Can't get GD functions to work

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
Mophoc
Forum Newbie
Posts: 2
Joined: Fri Dec 28, 2007 3:59 am

Can't get GD functions to work

Post 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!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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);
Mophoc
Forum Newbie
Posts: 2
Joined: Fri Dec 28, 2007 3:59 am

Post 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.
Stazh
Forum Newbie
Posts: 1
Joined: Sat Dec 13, 2008 5:16 am

Re: Can't get GD functions to work

Post 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 :)
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: Can't get GD functions to work

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Can't get GD functions to work

Post by pickle »

This thread is a year old. ~Mophoc has moved on by now - so should everyone else.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply