smarty Posted July 10, 2008 Share Posted July 10, 2008 HI! I am using the following code for drawing a rectangle: <html><body> <?php $myImage = @ImageCreate(150, 150); $black = ImageColorAllocate($myImage, 0, 0, 0); $white = ImageColorAllocate($myImage, 255, 255, 255); $red = ImageColorAllocate($myImage, 255, 0, 0); $gren = ImageColorAllocate($myImage, 0, 255, 0); $blue = ImageColorAllocate($myImage, 0, 0, 255); //draw some rectangles ImageRectangle($myImage, 15, 15, 40, 55, $red); ImageRectangle($myImage, 40, 55, 65, 95, $white); //output the image to the browser header ("Content-type: image/jpeg"); ImageJpeg($myImage); //clean up after yourself ImageDestroy($myImage); ?> </body> </html> and I am getting the following weird output in the browser: ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ÿÛC $.' ",#(7),01444'9=82<.342ÿÛC 2!!22222222222222222222222222222222222222222222222222ÿÀ––. I am using Apache 2.2.8, PHP 5.2.6 & in my php.ini file, there is the following line: extension=php_gd2.dll. But I don't know what is the problem. Anyone who knows how to correct it, please help. Link to comment https://forums.phpfreaks.com/topic/114078-help-images-not-opening-in-php/ Share on other sites More sharing options...
slushpuppie Posted July 10, 2008 Share Posted July 10, 2008 your code works for me: http://greg.transitid.com/test/ do you have the proper image libraries installed on your server? Link to comment https://forums.phpfreaks.com/topic/114078-help-images-not-opening-in-php/#findComment-586341 Share on other sites More sharing options...
PFMaBiSmAd Posted July 10, 2008 Share Posted July 10, 2008 Start by removing all the HTML tags. Code that outputs an image, just consists of the header and the image data. Link to comment https://forums.phpfreaks.com/topic/114078-help-images-not-opening-in-php/#findComment-586343 Share on other sites More sharing options...
slushpuppie Posted July 10, 2008 Share Posted July 10, 2008 oh yeah, what the above poster said... it must be early, i didn't even notice that, i just naturally copied and pasted the php code into a blank .php page and it worked. yeah, it's going to try and display your html tags as a jpeg! remove all that. then what you can do is in your html code call <img src="image.php" /> and put your image code into image.php... you call image.php like an image since php tells it to output as a jpeg. Link to comment https://forums.phpfreaks.com/topic/114078-help-images-not-opening-in-php/#findComment-586347 Share on other sites More sharing options...
smarty Posted July 14, 2008 Author Share Posted July 14, 2008 I am now getting a small box with a red cross inside as in the attached file... I think I am missing out on some libraries.. but when I use phpinfo(), I get: 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 .. Can u plz tell wat's the prob.. Also, what libraries etc. are req..... thanx [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/114078-help-images-not-opening-in-php/#findComment-589446 Share on other sites More sharing options...
vikramjeet.singla Posted July 14, 2008 Share Posted July 14, 2008 remove all html tags and place exit after destorying image.... <?php $myImage = @ImageCreate(150, 150); $black = ImageColorAllocate($myImage, 0, 0, 0); $white = ImageColorAllocate($myImage, 255, 255, 255); $red = ImageColorAllocate($myImage, 255, 0, 0); $gren = ImageColorAllocate($myImage, 0, 255, 0); $blue = ImageColorAllocate($myImage, 0, 0, 255); //draw some rectangles ImageRectangle($myImage, 15, 15, 40, 55, $red); ImageRectangle($myImage, 40, 55, 65, 95, $white); //output the image to the browser header ("Content-type: image/jpeg"); ImageJpeg($myImage); //clean up after yourself ImageDestroy($myImage); exit; ?> Link to comment https://forums.phpfreaks.com/topic/114078-help-images-not-opening-in-php/#findComment-589455 Share on other sites More sharing options...
PFMaBiSmAd Posted July 14, 2008 Share Posted July 14, 2008 The script ends execution when the closing ?> tag is reached. There is no point in putting an exit; statement there. smarty, you must post your current code (both showing how you are putting the image onto a web page and how you are producing and outputting the image) to get any help with what it is doing. The box/red-x you are getting means the browser could not fetch and display the image. There could be a dozen different reasons. Also, don't put any @ in code as that will prevent logging of errors that would help point out problems that might be occurring. Remove the @ from in front of the ImageCreate() function call. Add the following line after your first opening <?php tag and then check your web server log file for errors - error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/114078-help-images-not-opening-in-php/#findComment-589534 Share on other sites More sharing options...
vikramjeet.singla Posted July 14, 2008 Share Posted July 14, 2008 i have tried this and it is working fine for me.... test.php <?php $myImage = @ImageCreate(150, 150); $black = ImageColorAllocate($myImage, 0, 0, 0); $white = ImageColorAllocate($myImage, 255, 255, 255); $red = ImageColorAllocate($myImage, 255, 0, 0); $gren = ImageColorAllocate($myImage, 0, 255, 0); $blue = ImageColorAllocate($myImage, 0, 0, 255); //draw some rectangles ImageRectangle($myImage, 15, 15, 40, 55, $red); ImageRectangle($myImage, 40, 55, 65, 95, $white); //output the image to the browser header ("Content-type: image/jpeg"); ImageJpeg($myImage); //clean up after yourself ImageDestroy($myImage); exit; ?> and usage: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> </HEAD> <BODY> <img src="test.php" border="0" /> </BODY> </HTML> Link to comment https://forums.phpfreaks.com/topic/114078-help-images-not-opening-in-php/#findComment-589540 Share on other sites More sharing options...
PFMaBiSmAd Posted July 14, 2008 Share Posted July 14, 2008 Four days ago, slushpuppie pointed out that the php code itself worked and the raw image data that smarty showed in the first post (with extraneous html tags around it that prevented the browser from rendering it) indicates that GD is working. It is what smarty is specifically doing with that code that is causing the problem. Until smarty provides specific information as to what he is doing, there is no point in reconfirming that the code works. Link to comment https://forums.phpfreaks.com/topic/114078-help-images-not-opening-in-php/#findComment-589585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.