A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearWhy this PHP code not generating a valid PNG image? - page 1
User InfoPosts
Why this PHP code not generating a valid PNG image?#1
$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();
}

posted date: 2008-12-18 08:36:00


Re: Why this PHP code not generating a valid PNG image?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-18 08:36:01


Re: Why this PHP code not generating a valid PNG image?#3
I tried it, and it works. It produced a piece of red text, saying "Quiz canceled!".Maybe you should check whether $c and $i are both indeed 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 location?It might help also if you could give a bit more information: is the browser giving an error? Or just not showing anything?Ben

posted date: 2008-12-18 08:41:00


Re: Why this PHP code not generating a valid PNG image?#4
As has been said, the question's a bit sketchy on details.Is the GDFONTPATH environment variable set correctly?<?php// Set the enviroment variable for GDputenv('GDFONTPATH=' . realpath('.'));(from uk.php.net/imagefttext)

posted date: 2008-12-18 08:46:00


Re: Why this PHP code not generating a valid PNG image?#5
no avail! :( nothing shows

posted date: 2008-12-27 23:07:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.