9ball Posted November 16, 2009 Share Posted November 16, 2009 I am just testing how image works with php and here is the code: <?php $myImage=ImageCreate(150,150); $black=ImageColorAllocate($myImage, 0, 0, 0); $white=ImageColorAllocate($myImage, 255, 255, 255); $red=ImageColorAllocate($myImage, 255, 0, 0); $green=ImageColorAllocate($myImage, 0, 255, 0); $blue=ImageColorAllocate($myImage, 0, 0, 255); ImageRectangle($myImage, 15, 15, 55, 85, $red); ImageRectangle($myImage, 55, 85, 125, 135, $white); header ("Content-type: image/jpeg"); ImageJpeg($myImage); ImageDestroy($myImage); ?> with any browsers, I only get back ÿØÿà some unreadable characters. Is it because content type didn't get change to image/jpeg? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/181741-getting-image-to-show-from-a-php-script/ Share on other sites More sharing options...
premiso Posted November 16, 2009 Share Posted November 16, 2009 You need to set the header in your php to be image/jpeg. Look at the PHP Manual page for details/instructions. Quote Link to comment https://forums.phpfreaks.com/topic/181741-getting-image-to-show-from-a-php-script/#findComment-958544 Share on other sites More sharing options...
9ball Posted November 16, 2009 Author Share Posted November 16, 2009 not sure what you meant. Moved the header statement to the top but got the same result. <?php header('Content-type: image/jpeg'); Quote Link to comment https://forums.phpfreaks.com/topic/181741-getting-image-to-show-from-a-php-script/#findComment-958781 Share on other sites More sharing options...
premiso Posted November 16, 2009 Share Posted November 16, 2009 Sorry, missed that part of the code It was fine where it was, as far as why it is outputting the binary and not the actual image....hmmm not sure, looking at imagejpeg what you are doing seems correct. Maybe try to output buffer the contents instead? <?php $myImage=ImageCreate(150,150); $black=ImageColorAllocate($myImage, 0, 0, 0); $white=ImageColorAllocate($myImage, 255, 255, 255); $red=ImageColorAllocate($myImage, 255, 0, 0); $green=ImageColorAllocate($myImage, 0, 255, 0); $blue=ImageColorAllocate($myImage, 0, 0, 255); ImageRectangle($myImage, 15, 15, 55, 85, $red); ImageRectangle($myImage, 55, 85, 125, 135, $white); header ("Content-type: image/jpeg"); ob_start(); ImageJpeg($myImage); $image = ob_get_contents(); ob_end_clean(); echo $image; ImageDestroy($myImage); ?> I highly doubt that it will work, but worth a shot... Quote Link to comment https://forums.phpfreaks.com/topic/181741-getting-image-to-show-from-a-php-script/#findComment-958785 Share on other sites More sharing options...
9ball Posted November 17, 2009 Author Share Posted November 17, 2009 still getting binary output. Is there something need to be set on the server side? Quote Link to comment https://forums.phpfreaks.com/topic/181741-getting-image-to-show-from-a-php-script/#findComment-958802 Share on other sites More sharing options...
9ball Posted November 20, 2009 Author Share Posted November 20, 2009 It could be the lousy godaddy ad that is causing the problem. It works on another site. Quote Link to comment https://forums.phpfreaks.com/topic/181741-getting-image-to-show-from-a-php-script/#findComment-962126 Share on other sites More sharing options...
PFMaBiSmAd Posted November 20, 2009 Share Posted November 20, 2009 You likely have a header error due to how the .php file is saved or something before the <?php tag. Add the following two lines of code immediately after the first opening <?php tag and temporarily comment out the header() statement - ini_set("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/181741-getting-image-to-show-from-a-php-script/#findComment-962134 Share on other sites More sharing options...
9ball Posted November 22, 2009 Author Share Posted November 22, 2009 No error return. I don't see any thing returned from the 2 lines added. got the same binary code. Quote Link to comment https://forums.phpfreaks.com/topic/181741-getting-image-to-show-from-a-php-script/#findComment-962887 Share on other sites More sharing options...
PFMaBiSmAd Posted November 22, 2009 Share Posted November 22, 2009 Try the same but with the header() statement uncommented (so that the code should attempt to output the header.) Quote Link to comment https://forums.phpfreaks.com/topic/181741-getting-image-to-show-from-a-php-script/#findComment-962890 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.