Image display problem
Posted by: jerem (190.183.111.---)
Date: February 12, 2009 05:50AM

Hi -- I've been breaking my head trying to display images with a content header on 3 browsers (firefox, opera, netscape). For example, the code below is straight out of the PHP manual but all I get (in Opera) is a text with the term image inside a small space; firefox informs that the page won't display because of an error , but it doesn't specify what (even though display errors works fine). I tried Firefox Live HTTP headers and noted that the image exists, etc. but the GET image is being skipped. I checked to see if the headers were being sent by writing a redirection header to be executed if the headers for the image had NOT been sent, and I was redirected successfully. I can display images with echo, but not with a content header. What is wrong? Something in the php.ini file? Please help.

<?php
header("Content-type: image/png"winking smiley;
$im = @imagecreate(110, 20)
or die("Cannot Initialize new GD image stream"winking smiley;
$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);
?>

Code copied from [www.php.net]
but similar code won't work either.

Re: Image display problem
Posted by: yfastud (Moderator)
Date: February 12, 2009 06:04AM

through wamp tray icon, enable php_gd2 ;-)

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides



Edited 1 time(s). Last edit at 02/12/2009 06:04AM by yfastud.

Re: Image display problem
Posted by: jerem (190.183.111.---)
Date: February 12, 2009 06:31AM

Thanks for the quick help. However I still don't see the image. I'm assuming I´ve enabled gd2 correctly:

it's now unchecked in the wamp tray php.ini file and also uncommented (no semi-colonwinking smiley in the gd2 dll in the apache php.ini.

Right? If so, what else might be the problem?

Re: Image display problem
Posted by: yfastud (Moderator)
Date: February 12, 2009 01:49PM


Re: Image display problem
Posted by: jerem (190.183.111.---)
Date: February 12, 2009 07:54PM

php_gd2 is checked. So is php_mbstring. Still the code doesn't work.

Does it work for you?

The file is in the www folder and called draw_image.php. I'm on windows XP and using wamp 2.0f.

Please remember I can display images using echo and img src, but not with content type header, like in the code above.

What now?

Re: Image display problem
Posted by: yfastud (Moderator)
Date: February 12, 2009 07:56PM


Re: Image display problem
Posted by: jerem (190.183.111.---)
Date: February 12, 2009 08:32PM

Hmm. So either some other change is needed in php.ini or ...Windows XP is blocking it somehow. Any further suggestions?

Re: Image display problem
Posted by: jerem (190.183.111.---)
Date: February 12, 2009 08:52PM

Even with windows xp firewall turned off and no anti-virus the code doesn't work on my Wamp..

Re: Image display problem
Posted by: jerem (190.183.111.---)
Date: February 13, 2009 03:07AM

Can anyone else confirm that the code above works on their wamp and their settings?

The code is safe, straight out of PHP manual. See link above.

Thank you in advance for your help.

Re: Image display problem
Posted by: jerem (190.183.111.---)
Date: February 13, 2009 08:59AM

OK the problem was being caused by the text editor. Notepad was inserting 3 characters before the opening of the php script, but they were not visible. I discovered it after reopening the file with open office.
Strangely, I had had the same problem with open office 3 months back.

So now you all know...text editors are not trustworthy!

Or perhaps both of these were hacked.

Re: Image display problem
Posted by: jerem (190.183.111.---)
Date: February 13, 2009 09:32AM

I've been informed that the problem is that PHP doesn't go well with UTF-8...that this is where the 3 characters were coming from.

Re: Image display problem
Posted by: yfastud (Moderator)
Date: February 13, 2009 01:50PM


Sorry, only registered users may post in this forum.