note 42928 deleted from function.imagettftext by aidan
| From: | aidan@php.net | Date: | Mon, 20 Sep 2004 08:47:18 +0000 |
| Subject: | note 42928 deleted from function.imagettftext by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77007@lists.php.net to get a copy of this message | ||
Note Submitter: erik at bigcookie dot com
----
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);
?>