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
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.