Please help me with some GD code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anjan011
Forum Newbie
Posts: 3
Joined: Thu Dec 18, 2008 10:24 am

Please help me with some GD code

Post 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!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Please help me with some GD code

Post by requinix »

Comment out the header() and look for error messages.
anjan011
Forum Newbie
Posts: 3
Joined: Thu Dec 18, 2008 10:24 am

Re: Please help me with some GD code

Post 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:
Post Reply