Images from text
Posted: Mon Aug 16, 2004 2:10 pm
Hey all,
I'm trying to play around with making images using GD and libttf2.
I've got the following code but when I try to load the page I get:
The image “http://skorpion/gd.php” cannot be displayed, because it contains errors.
Has anyone got any ideas why this is happening?
I'm trying to play around with making images using GD and libttf2.
I've got the following code but when I try to load the page I get:
The image “http://skorpion/gd.php” cannot be displayed, because it contains errors.
Code: Select all
<?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, "quick4.ttf", $text);
header("Cache-control: private");
header("Content-Type: image/jpeg");
imagejpeg($im);
imagedestroy($im);
?>