alberto_zurita Posted April 28, 2006 Share Posted April 28, 2006 Hi,I am having some problems 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 <?php 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'JD£RÑ+®0wÁ¯`«ÙýòÏfø³Sc CYeŸG?Eý˜õà«*T,(´ªšðñ£Peí|&H»;?&¦±éÖ³½54IÇ%¥öÉé¿×‘[¢•!‘i¡)1kg$;ÇP E‚˜o™¶²,{»—z÷·†…Âå:`Ž¾´¹Ì”?¨Ž,³fSñƒ8Ÿ¨Æ7È?½íEµ¯E´ª,ÒNçÛ@µ4&‚øg••Gé2ü¶'€£D?ijžIEND®B`‚ 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:<?phpecho "<xmp> ";print_r(gd_info());echo "</xmp> ";?>This prints: Array( [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); imagestring($im,5,3,1,$string,$orange); //saves image to "myimage.png" imagepng($im,"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.Thanks!!Albertops: I am running PHP version 5.0.4gdGD 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 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 28, 2006 Share Posted April 28, 2006 Make sure you have no characters before the opening "<?php". If you do, those characters will cause the symptoms you're seeing.Ken Quote Link to comment Share on other sites More sharing options...
alberto_zurita Posted April 28, 2006 Author Share Posted April 28, 2006 Thanks Ken,I already fixed the weird charcters printing, but still the image doesn't show up. Only the sad square box with the X in the middle.Do you have any ideas what the problem might be? Thanks.Alberto Quote Link to comment Share on other sites More sharing options...
Orio Posted April 29, 2006 Share Posted April 29, 2006 Maybe this will work... With two diffrent files.Put this part of code in makepic.php:[code]<?php 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); ?>[/code]Then on the page calling the pic do the following:[code]<img src="makepic.php" border="0" />[/code]Orio. Quote Link to comment Share on other sites More sharing options...
alberto_zurita Posted April 30, 2006 Author Share Posted April 30, 2006 thanks orio,I already fixed it, and yes...I tried what you said, but that was not the problem. I was leaving a space at the beggining of the file.:(Regards,Beto Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.