Jump to content


GD PHP Problem

  • Please log in to reply
3 replies to this topic

#1 alberto_zurita

  • Members
  • PipPip
  • Member
  • 13 posts

Posted 28 April 2006 - 08:58 PM


I am having a problem related to GD and PHP. I am trying to create an image with GD library and PHP, but...

here is what happens:

If I run the code on my localhost

header ("Content-type: image/png");
$img_handle = ImageCreate (230, 20) or die ("Cannot Create image");
$back_color = ImageColorAllocate ($img_handle, 0, 10, 10);
$txt_color = ImageColorAllocate ($img_handle, 233, 114, 191);
ImageString ($img_handle, 31, 5, 5, "My first Program with GD", $txt_color);
ImagePng ($img_handle);

Instead of showing a png file it prints wierd characters on the browser:

‰PNG  IHDRæ£þÓêPLTE ér¿`ŽLÚIDATxœåбAàŸMhF®!ža’+(„WÙË&ª;‘x?ë”Z…‡Ði'J­D£RÑ+®0wÁ¯`«ÙýòÏfø³Sc



Yes, it prints all this weird characters just as it is above. I know I have installed GD, because I checked it with the info() function:


echo "<xmp> ";


echo "</xmp> ";


This prints:

[GD Version] => bundled (2.0.28 compatible)
[FreeType Support] => 1
[FreeType Linkage] => with freetype
[T1Lib Support] =>
[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] =>

This shows GD is enabled.

But, I don't know why it doesn't show the image but a string of weird characters.
If I run the following code, and image is created in the specified local directory below, but only an orange square is created(png file), but with NO STRING attached to it:

header("Content-type: image/png");

$string = "hey dude.......";
$im = imagecreate(600,900);
$orange = imagecolorallocate($im, 220, 210, 60);

//saves image to "myimage.png"


Is there something I am missing? It seems I have all the files in place. I put bgd.dll, and php_gd2.dll in the Systems directory in Windows.
I also uncommented the line required on php.ini for extensions, so it seems it is loading that module.

Please help me. All your help is very much appreciated.



ps: I am running PHP version 5.0.4

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

#2 alberto_zurita

  • Members
  • PipPip
  • Member
  • 13 posts

Posted 28 April 2006 - 09:42 PM

I fixed the weird character printing, but the image still doesn't show up, only the deafult box with the sad X in the middle.

Any ideas?



#3 Sakrag

  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 29 April 2006 - 01:26 AM

The image is some how gettign corrupted when it reaches your browser probably. Make sure you do not output any content before the image (no other headers, no prints, no echos) and also make sure you have now extra empty liens or spaces at the end or beginning of the file (before and after the <? and ?> tags) this will cause those spaces to actually be output to the browser as text and corrupt the image.

#4 alberto_zurita

  • Members
  • PipPip
  • Member
  • 13 posts

Posted 29 April 2006 - 06:25 AM

Yes, I figured out that problem. :)

Thanks for your feedback!!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users