note 53986 deleted from function.imagettfbbox by nlopess
| From: | nlopess@php.net | Date: | Mon, 20 Jun 2005 09:57:58 +0000 |
| Subject: | note 53986 deleted from function.imagettfbbox by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-90676@lists.php.net to get a copy of this message | ||
Note Submitter: anthony at arkia dot en el
----
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;
}