Page 1 of 1

Can't get GD functions to work

Posted: Fri Dec 28, 2007 4:36 am
by Mophoc
I have read through many threads dealing with GD installation problems, but I still couldn't find any solution to my specific problem.

I have installed GD, and gd_info() confirms that it is installed and enabled, but I can't get any of the image related functions to work! And I'm talking basic scripts copied from examples at php.net and GD tutorials, so there is nothing wrong with the code itself.

I feel like I must have missed some embarrasingly obvious vital detail, but I can't figure out what!

gd_info() produces this:
[GD Version] => bundled (2.0.34 compatible)
[FreeType Support] => 1
[FreeType Linkage] => with freetype
[T1Lib Support] => 1
[GIF Read Support] => 1
[GIF Create Support] => 1
[JPG Support] => 1
[PNG Support] => 1
[WBMP Support] => 1
[XPM Support] =>
[XBM Support] => 1
[JIS-mapped Japanese Font Support] =>
And phpinfo() produces:
Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared"

[...]

gd
GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.1.9
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled

[...]
Any help would be appreciated!

Posted: Fri Dec 28, 2007 9:58 am
by John Cartwright
Can you explain what "does not work" means. Are you getting errors? Post the code?

try adding

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', true);

Posted: Fri Dec 28, 2007 7:04 pm
by Mophoc
Thank you for the quick reply!

I seem to get the same error message with or without adding your code.

The following code (copied from php.net)...

Code: Select all

<?php
header("Content-type: image/png");
$im = @imagecreate(110, 20)
    or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>
...produces this error message (translated from my language version):
The image at “[...]/pic2.php” cannot be displayed, since it contains errors.
But there are no errors in the code, right?

I have tried it with gif and other image formats as well, but the result is always the same.

Re: Can't get GD functions to work

Posted: Sat Dec 13, 2008 5:29 am
by Stazh
Yes, I have the same problem. I've tried using not just PNG creation function, but also the JPG and GIF functions. The output is always the same. Corrupt image output to the browser when I try to stream it directly, but an OK image when I try to save it to the file.

I've checked the PHP file to see is there any rouge bytes in front and after the PHP block but there are none. I'm going mad here, please help, I have cookies :)

Re: Can't get GD functions to work

Posted: Sat Dec 13, 2008 11:40 am
by greyhoundcode
Hey Mophoc, it must be something to do with your setup - I copied and pasted your code and it worked just fine, got a little black rectangle with pink text saying 'A Simple Text String' (as you'd expect!).

Do you have extension=php_gd2.dll included and uncommented in your .ini?

Re: Can't get GD functions to work

Posted: Mon Dec 15, 2008 10:55 am
by pickle
This thread is a year old. ~Mophoc has moved on by now - so should everyone else.