matrixrp Posted March 5, 2009 Share Posted March 5, 2009 I have problem with gd generated images when i try to run simple script from php manual to generate image only thing that i see on screen is placeholder for image but not the image self, and as i can see images are not shown in the php manual too where the example is i really have no idea what could be the problem if anyone has experienced the same problem please help. And here is the sample code from php manual: <?php // create a 200*200 image $img = imagecreatetruecolor(200, 200); // allocate some colors $white = imagecolorallocate($img, 255, 255, 255); $red = imagecolorallocate($img, 255, 0, 0); $green = imagecolorallocate($img, 0, 255, 0); $blue = imagecolorallocate($img, 0, 0, 255); // draw the head imagearc($img, 100, 100, 200, 200, 0, 360, $white); // mouth imagearc($img, 100, 100, 150, 150, 25, 155, $red); // left and then the right eye imagearc($img, 60, 75, 50, 50, 0, 360, $green); imagearc($img, 140, 75, 50, 50, 0, 360, $blue); // output image in the browser header("Content-type: image/png"); imagepng($img); // free memory imagedestroy($img); ?> and the sample page to call this image <img src="simpleImage.php" width="200" height="200" /> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 5, 2009 Share Posted March 5, 2009 couple steps in debugging this. first, load the image up directly in the URL. does it show? if it does, your img src is pointing to the wrong place. if it doesn't show right, move to the next step. next, comment out these lines: header("Content-type: image/png"); imagepng($img); refresh the page (we are still looking directly at the image) and see if a bunch of garbage looking stuff is shown. if so, that is good, if not, you have a PHP syntax problem somewhere. if error reporting is on, you will see the syntax error here. try that stuff out and report back what you find Quote Link to comment Share on other sites More sharing options...
matrixrp Posted March 5, 2009 Author Share Posted March 5, 2009 Well i did everything you said: Tryed to open directly in browser window but nothing showed up. I commented those two lines of code and still there is nothing in the browser and it doesn't show any errors. I have no idea what could be the problem A'm running this script on local apache 2.2 server on my computer . Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 5, 2009 Share Posted March 5, 2009 i copy/pasted the code you have and it worked fine for me. create a new php page, and put this in it: <?php phpinfo(); ?> load it up in a browser, scroll down to the GD section, and post what the info is there. mine for instance is: 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 Quote Link to comment Share on other sites More sharing options...
matrixrp Posted March 5, 2009 Author Share Posted March 5, 2009 I've allready checked that everything is ok: 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 The strange thing is that this same example is in the php manual and after the example there is little image placeholder which should be the image from this example but it isn't shown there either. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 6, 2009 Share Posted March 6, 2009 what OS/Browser are you using to view the image? Quote Link to comment Share on other sites More sharing options...
matrixrp Posted March 6, 2009 Author Share Posted March 6, 2009 I've tried on Mozilla, IE, Safari, Opera on the newest versions and all a get is empty page. Is there possibility the problem to be somewhere else, i mean problem with apache or some other system component. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 6, 2009 Share Posted March 6, 2009 it must be...the only other tip i have is to make sure there is absolutely NO extra characters (including whitespace) before or after the code. you may want to put an exit; after the imagedestroy() just to be safe. another way to test this is to write it to a file instead imagepng($img,'testfile.png'); then try opening that file (both on the file system and through the webserver p.s. - another thing i just noticed. i think the content type is supposed to have a semi-colon in it: header("Content-type: image/png;"); Quote Link to comment Share on other sites More sharing options...
matrixrp Posted March 6, 2009 Author Share Posted March 6, 2009 Well i did everything you said and now when i open the file directly it is showing: The image “http://localhost/gdtest.php” cannot be displayed, because it contains errors. I've got no clue what to do but thanks for you help. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 6, 2009 Share Posted March 6, 2009 ok...that means there are PHP syntax errors...comment out the header() line: header("Content-type: image/png"); and refresh Quote Link to comment Share on other sites More sharing options...
matrixrp Posted March 7, 2009 Author Share Posted March 7, 2009 Now after i comment out the header when i open the page directly it is full with bunch of garbage as you said and i believe this is finally something good, but when i try to open with image tag on other page like this: <img src="gdTest.php" width="200" height="200" /> Again the page is empty. Quote Link to comment Share on other sites More sharing options...
willpower Posted March 7, 2009 Share Posted March 7, 2009 The 'garbage' contains the key!!!! Take time to look thru the garbage as in there there could well be the error message. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 8, 2009 Share Posted March 8, 2009 there error message would either be before or after the garbage. do you have error reporting on? try putting this at the beginning of your script: ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
matrixrp Posted March 8, 2009 Author Share Posted March 8, 2009 Yes i have error reporting on set in the php ini. But there is no php error here two screenshots from this page: [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 8, 2009 Share Posted March 8, 2009 not sure what else to say. i can't replicate the problem. it seems like the it's generating the code fine. have you tried the script on any other webservers? Quote Link to comment Share on other sites More sharing options...
matrixrp Posted March 8, 2009 Author Share Posted March 8, 2009 Yes i've tried this example on public server and it runs fine, maybe the problem is somewhere else i'll continue to struggle with this problem but thanks again for your help. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 9, 2009 Share Posted March 9, 2009 i can't think of any other factors that would play in this. what is your webserver install? -OS -Install method (WAMP or individual components) -You can always try upgrading your Apache/PHP to the latest versions...there might be some weird conflict between your specific versions. Or, if it's just for your personal use, try out WAMP (assuming you are on windows) Quote Link to comment Share on other sites More sharing options...
matrixrp Posted March 9, 2009 Author Share Posted March 9, 2009 Well i already have the latest versions of php apache and mysql, and i'm using individual components, and my last chance is to use WAMP and see what will happen . Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 9, 2009 Share Posted March 9, 2009 one other thing you may want to try (if you haven't already) is to open a fresh file in a plain text editor like Notepad (don't use Wordpad), and retype the code in there. Don't copy/paste it...retype everything. There might be some random hidden character in there hanging around from copying/pasting. Quote Link to comment Share on other sites More sharing options...
matrixrp Posted March 10, 2009 Author Share Posted March 10, 2009 I've just installed copy of free php forum script and everything is ok all images are showing like captcha which means it is not problem with the server or php error, so now a'll try different examples and see what happens. 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.