PDA

View Full Version : Cant get GD working


missing-score
03-17-2004, 12:46 PM
Well after reading a recent thread by ConfusedOfLife I decided to set up GD on my local server. I did everything i thought i had to do, and I cant get it to work. I copied a script from php.net to test:

<?php
header("Content-type: image/png");
$string = 'hello';
$im = imagecreatefrompng("images/button1.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
?>

and I get this error:

The image “http://localhost/testGD.php” cannot be displayed, because it contains errors.

I removed the header, and I get:

Fatal error: Call to undefined function: imagecreatefrompng() in c:\apache\htdocs\testgd.php on line 3

I went to www.php.net and it said that there is a bundled version of GD that comes with PHP. I enabled the extension in php.ini, and I have tried setting a full path (c:/php/extensions/php_gd2.dll) as well as just php_gd2.dll.

Does anyone have any ideas how I could get this working? Im running apache (latest version), php 4.3.4 on windows XP home.

Thanks

firepages
03-17-2004, 01:55 PM
did you restart apache after changing the php.ini ?

missing-score
03-17-2004, 05:55 PM
Yes.

Is there anything else I would need apart from what came with the PHP 4.3.4 download?

ConfusedOfLife
03-17-2004, 06:15 PM
huh! So you're having the same problem! I know that it might look so clear, but I just wanted to say that you shouldn't put the full path for an extension, I mean you only write extension=php_gd2.dll, or better to say you uncomment it, and that's all. You should set the extension_dir value to make the path.

PS: I found some very new problmes regarding these dll files that I'm going to make a new thread for them! Don't forget to pay a visit if you have time for some new problems!

Edit: This is the address (http://codingforums.com/showthread.php?s=&threadid=35235)

SDP2006
03-17-2004, 10:27 PM
Try sending the header before creating the image
<?php
$string = 'hello';
$im = imagecreatefrompng("images/button1.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>

[edit]
Whipped this code up and it worked fine -
<?php
$img_handle = ImageCreate (300, 40) or die ("Cannot Create image");
$back_color = ImageColorAllocate ($img_handle, 0, 255, 0); /* GREEN */
$txt_color = ImageColorAllocate ($img_handle, 0, 0, 0); /* BLACK */
ImageString ($img_handle, 30, 5, 5, " Testing one, two, three!!", $txt_color);
ImageString ($img_handle, 30, 5, 20, " Happy St. Patricks day!", $txt_color);
header ("Content-type: image/png");
ImagePng ($img_handle);
?>

missing-score
03-17-2004, 10:33 PM
I think it is a problem with apache... or how i have configured PHP with apache...

I think this becuase I used my original script, went to command prompt, and typed:

cd C:\php
php.exe C:\Apache\htdocs\testGD.php

and it output raw image data... it was unreadable of course, but it was definately an image.

However without modifying anything, I went to http://localhost/testGD.php and it said there was an error. The only other thing I can think is that there was an error in the image outputted to the command prompt. Just had a thought... it might be the way mozilla tells you if there is an error in the image, Im going to test it in IE.

missing-score
03-17-2004, 10:38 PM
ok, the error message all along was:

Fatal error: Call to undefined function imagecreatefrompng() in c:\Apache\htdocs\testGD.php on line 4

but mozilla outputted "The image “http://localhost/testGD.php” cannot be displayed, because it contains errors."

as the fatal error message is clearly not valid image data.