Jump to content

Please help gd generated images are not displayed on screen


matrixrp

Recommended Posts

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" />

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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 . 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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;");

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.