note 116501 added to function.imagestring
| From: | Booteille | Date: | Wed, 14 Jan 2015 00:56:51 +0000 |
| Subject: | note 116501 added to function.imagestring | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201422@lists.php.net to get a copy of this message | ||
Here is a function with similar declaration of imagestring() but who handles whitespaces (It creates
new lines and 4 spaces instead of \n and \t) and image's size limits
<?php
/**
* @author Booteille
*
* @param resource $image
* @param int $font
* @param int $x
* @param int $y
* @param string $string
* @param int $color
*/
function whitespaces_imagestring($image, $font, $x, $y, $string, $color) {
$font_height = imagefontheight($font);
$font_width = imagefontwidth($font);
$image_height = imagesy($image);
$image_width = imagesx($image);
$max_characters = (int) ($image_width - $x) / $font_width ;
$next_offset_y = $y;
for($i = 0, $exploded_string = explode("\n", $string), $i_count =
count($exploded_string); $i < $i_count; $i++) {
$exploded_wrapped_string = explode("\n", wordwrap(str_replace("\t",
" ", $exploded_string[$i]), $max_characters, "\n"));
$j_count = count($exploded_wrapped_string);
for($j = 0; $j < $j_count; $j++) {
imagestring($image, $font, $x, $next_offset_y, $exploded_wrapped_string[$j], $color);
$next_offset_y += $font_height;
if($next_offset_y >= $image_height - $y) {
return;
}
}
}
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 2a01:e34:ee72:9ec0:94a7:81bf:3d21:83cf
----
Manual Page -- http://php.net/manual/en/function.imagestring.php
Edit -- https://master.php.net/note/edit/116501
Del: integrated -- https://master.php.net/note/delete/116501/integrated
Del: useless -- https://master.php.net/note/delete/116501/useless
Del: bad code -- https://master.php.net/note/delete/116501/bad+code
Del: spam -- https://master.php.net/note/delete/116501/spam
Del: non-english -- https://master.php.net/note/delete/116501/non-english
Del: in docs -- https://master.php.net/note/delete/116501/in+docs
Del: other reasons-- https://master.php.net/note/delete/116501
Reject -- https://master.php.net/note/reject/116501
Search -- https://master.php.net/manage/user-notes.php