note 42928 added to function.imagettftext
| From: | erik at bigcookie dot com | Date: | Fri, 04 Jun 2004 01:34:52 +0000 |
| Subject: | note 42928 added to function.imagettftext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70785@lists.php.net to get a copy of this message | ||
I was having trouble getting words to wrap correctly, and worked through it with this solution. It
may not be the prettiest but it works for me.
<?php
//Create an empty array
$length_array = array();
//Dissect $text
$fragments = explode("\n",$text);
$fragments_count = count($fragments);
for ($i = 0; $i <=$fragments_count; $i++)
{
array_push($length_array, strlen($fragments[$i]));
}
//Sort the array so the highest value is first
rsort($length_array);
//find out how many lines there are in the string.
$line_count = count($length_array);
//Image Parameters
$w = $length_array[0] * 10;
$h = $line_count * 25;
$size = 10;
$xpos = 5;
$ypos = 20;
$im = imagecreate($w, $h);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagettftext($im, $size, 0, $xpos, $ypos, $black,
"/usr/lib/X11/fonts/TrueType/Courier_New.ttf", $text);
header("Cache-control: private");
header("Content-Type: image/jpeg");
imagejpeg($im);
imagedestroy($im);
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagettftext.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42928
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42928&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42928&report=yes
Search -- http://master.php.net/manage/user-notes.php