Why doesn't this PHP code create a valid PNG image?
$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();
}
+1
source to share
3 answers
I tried it and it works. This produced a chunk of red text saying "Poll canceled!"
Maybe you should check if $ c and $ i are really 0?
I assume you have <? php and? > tags at the beginning and end of the file?
Edit: also is the ttf font file in the right place?
It might help if you can give a little more information: is this the browser giving the error? Or just show nothing?
Ben
+1
source to share
As already stated, the question is a bit fragmented in detail.
Is the GDFONTPATH ββenvironment variable set correctly?
<?php
// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));
(from uk.php.net/imagefttext )
+1
source to share