Page 1 of 1

Please help me with some GD code

Posted: Thu Dec 18, 2008 10:31 am
by anjan011
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! :banghead:

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();
    }
 
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!

Re: Please help me with some GD code

Posted: Thu Dec 18, 2008 4:02 pm
by requinix
Comment out the header() and look for error messages.

Re: Please help me with some GD code

Posted: Fri Dec 19, 2008 12:36 am
by anjan011
tasairis wrote:Comment out the header() and look for error messages.
I did but it shows an empty browser screen :( is it a bug in PHP or what? :roll: