note 86134 added to function.imagettfbbox
| From: | decimealgo at gmail dot com | Date: | Sat, 04 Oct 2008 17:11:41 +0000 |
| Subject: | note 86134 added to function.imagettfbbox | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-145057@lists.php.net to get a copy of this message | ||
This is a function which reformats a text string into a text block of a given width.
Usefull when you have a long single line string and want to fit it into a fixed width but don't
care about it's height
function makeTextBlock($text, $fontfile, $fontsize, $width)
{
$words = explode(' ', $text);
$lines = array($words[0]);
$currentLine = 0;
for($i = 1; $i < count($words); $i++)
{
$lineSize = imagettfbbox($fontsize, 0, $fontfile, $lines[$currentLine] . ' ' .
$words[$i]);
if($lineSize[2] - $lineSize[0] < $width)
{
$lines[$currentLine] .= ' ' . $words[$i];
}
else
{
$currentLine++;
$lines[$currentLine] = $words[$i];
}
}
return implode("\n", $lines);
}
----
Server IP: 190.2.55.3
Probable Submitter: 190.245.178.79
----
Manual Page -- http://www.php.net/manual/en/function.imagettfbbox.php
Edit -- https://master.php.net/note/edit/86134
Del: integrated -- https://master.php.net/note/delete/86134/integrated
Del: useless -- https://master.php.net/note/delete/86134/useless
Del: bad code -- https://master.php.net/note/delete/86134/bad+code
Del: spam -- https://master.php.net/note/delete/86134/spam
Del: non-english -- https://master.php.net/note/delete/86134/non-english
Del: in docs -- https://master.php.net/note/delete/86134/in+docs
Del: other reasons-- https://master.php.net/note/delete/86134
Reject -- https://master.php.net/note/reject/86134
Search -- https://master.php.net/manage/user-notes.php