note 53986 added to function.imagettfbbox
| From: | anthonyatarkiadotenel at osu1 dot php dot net | Date: | Mon, 20 Jun 2005 09:51:18 +0000 |
| Subject: | note 53986 added to function.imagettfbbox | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90670@lists.php.net to get a copy of this message | ||
l.s.
I changed the function printWordWrapped a little.
Here is my variation... this works better for me.
If you want to see an implementation have a look one of these days at www.kaartjeposten.nl or
www.mijnborrel.nl.
Many thanks to the suplier of the earlier function!
function printWordWrapped(&$image, $top, $left, $maxWidth, $font, $color, $text, $textSize) {
$words = explode(' ', strip_tags($text)); // split the text into an array of single
words
$line = '';
while (count($words) > 0) {
$newline = false;
$dimensions = imagettfbbox($textSize, 0, $font, $line.' '.$words[0]);
$lineWidth = $dimensions[2] - $dimensions[0]; // get the length of this line, if the word is to
be included
if ($lineWidth > $maxWidth) { // if this makes the text wider that anticipated
//add a new line character
$line .= "\n";
$newline = true;
}
if ($line != "" && !$newline) {
// add the word to the current sentence
//if it isn't the first word in a sentence add a space
$line .= ' '.$words[0];
} else {
$line .= $words[0]; // add the word to the sentence
}
$words = array_slice($words, 1); // remove the word from the array
}
$dimensions = imagettfbbox($textSize, 0, $font, $line.$line);
$lineHeight = $dimensions[1] - $dimensions[7]; // the height of a single line
imagettftext($image, $textSize, 0, $left, $top + $lineHeight * $i, $color, $font, $line);
return $lineHeight;
}
----
Manual Page -- http://www.php.net/manual/en/function.imagettfbbox.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+53986
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53986&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53986&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53986&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53986&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+53986&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53986&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+53986&report=yes
Search -- http://master.php.net/manage/user-notes.php