Please help me with some GD code
Posted: Thu Dec 18, 2008 10:31 am
Hi! I am trying to test GD to generate simple pie chart to display the percentage of correct & incorrect answers for a quiz. But the GD code i am coding is getting me mad!
Just tell me what i did wrong here to get a message in firefox "The image ... can not be displayed, because it contain errors.", plz help! I get this error even if i just copy and paste sample code from GD functions in php manual!
Code: Select all
$c = $record['corrects'];
$i = $record['incorrects'];
if($c == 0 && $i == 0)
{
$image = imagecreatetruecolor(200,80);
$white = imagecolorallocate($image,255,255,255);
$red = imagecolorallocate($image,255,0,0);
imagefilledrectangle($image,0,0,199,79,$white);
$text = 'Quiz cancelled!';
$box = imageftbbox(10,0,'verdana.ttf',$text);
$x = imagesx($image)/2 - abs($box[2] - $box[0])/2 - 5;
$y = imagesy($image)/2 - abs($box[5] - $box[3])/2 - 5;
imagefttext($image,10,0,$x,$y,$red,'verdana.ttf',$text);
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
exit();
}