note 31339 added to function.imagettfbbox
| From: | shamblrd at hotmail dot com | Date: | Thu, 17 Apr 2003 20:49:15 +0000 |
| Subject: | note 31339 added to function.imagettfbbox | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-46751@lists.php.net to get a copy of this message | ||
This handy function will split a string into an array of strings that fit a given line width for
imagettftext, splitting at spaces. The parameters are the text string itself, the font size, the
font file and the desired max width in pixels.
function text_to_lines($text, $size, $font, $width)
{
$ex = explode(" ", $text);
$ex_c = count($ex);
$p = 0;
for($i=0; $i<$ex_c; $i++)
{
if($i)
$test = $full[$p]." ";
$test .= $ex[$i];
$bbox = imagettfbbox($size, 0, $font, $test);
if(($bbox[4] - $bbox[6]) > $width)
{
$p++;
$full[$p] = $ex[$i];
}
else
$full[$p] = $test;
}
return $full;
}
--
http://www.php.net/manual/en/function.imagettfbbox.php
http://master.php.net/manage/user-notes.php?action=edit+31339
http://master.php.net/manage/user-notes.php?action=delete+31339
http://master.php.net/manage/user-notes.php?action=reject+31339