Php Gd2
Hi!
I am trying to make some graphs on the fly through php, but it is not working. Originally I didn't have the gd2 extension, so I downloaded php again, took the gd2.dll file out, put it into the ext folder, made sure that in the ini file the extensions were pointing to the ext folder and uncommented the gd2 extension.
I wrote a test code:
<?php
header("content-type:image/png");
$height=10;
$width=10;
$im=imagecreatetruecolor($width, $height);
$blue=imagecolorallocate($im,0,0,64);
imagefill($im,0,0,$blue);
imagepng($im);
imagedestroy($im);
?>
and I get this error:
"the image at example.com cannot be displayed because it contains errors"
When I take out
header("content-type:image/png");
I get a bunch of mumbo jumbo, but not the warning.
does anyone know what is going on?
Thanks!
L
pr0gr4mm3r posted this at 02:11 — 13th July 2007.
He has: 1,502 posts
Joined: Sep 2006
The first thing you should do is create a new php file, and then put in the following code:
<?php
phpinfo();
?>
That will be able to tell you if PHP is using the GD extensions and working. Since your script works on my server, it looks to be a problem with your GD extension.
Dynamic images can be a tricky thing to debug because of the fact that the errors cannot be displayed easily, but the phpinfo() will be able to tell you if your extensions are loading properly.
L3ZL1E posted this at 17:44 — 13th July 2007.
They have: 32 posts
Joined: Feb 2007
Thanks so much for testing my code!
Unfortunately, I've even tried reinstalling php on this server with the extension and it still does not work.
phpinfo says that it's enabled.
I really don't know what to do next.
L
L3ZL1E posted this at 17:45 — 13th July 2007.
They have: 32 posts
Joined: Feb 2007
What kind of server do you use? I am thinking about switching anyways.
pr0gr4mm3r posted this at 17:53 — 13th July 2007.
He has: 1,502 posts
Joined: Sep 2006
So...just to make sure, when you say phpInfo shows it, do you mean that there is an entire section for the gd options? (see attached picture for sample). Just seeing '--with-gd' at the top in the configure options does not mean that it's enabled. I set up a php & MySQL environment on my Windows laptop and had a heck of a time getting it to function properly.
This server runs Ubuntu 7.04, Apache, MySQL, PHP, etc (or LAMP as it's referred to).
L3ZL1E posted this at 18:30 — 13th July 2007.
They have: 32 posts
Joined: Feb 2007
When I run phpinfo() that's exactly what I see. This has been nothing but a nightmare (running php on IIS!).
I'm trying to work with the IT manager to figure this out. Usually, what will happen is I will leave on a Friday, with an issue like this, and then "magically" on Monday it will work!
Thanks so much for your help! Any other insights?
L
pr0gr4mm3r posted this at 18:32 — 13th July 2007.
He has: 1,502 posts
Joined: Sep 2006
Is there any way you could use Apache instead?
L3ZL1E posted this at 18:43 — 13th July 2007.
They have: 32 posts
Joined: Feb 2007
I might just switch to Apache...we've been talking about it anyways. These issues keep coming up with IIS, and it is so frustrating! I never know if it's my code or the server!
pr0gr4mm3r posted this at 18:45 — 13th July 2007.
He has: 1,502 posts
Joined: Sep 2006
Well, this time you know it's your server, I copied that verbatim, and it worked fine.
When I set up PHP on my Windows machine, I had to copy the MySQL dll file into my Windows/system32 directory for it to work. I doubt that would help you because it's already loading (as shown in the phpinfo()), but it may be worth a try.
L3ZL1E posted this at 18:07 — 19th July 2007.
They have: 32 posts
Joined: Feb 2007
There has got to be something php is doing wrong on the server. Does anyone else have any ideas about how to fix this problem? Does my server just not support GD2 or something?
pr0gr4mm3r posted this at 18:13 — 19th July 2007.
He has: 1,502 posts
Joined: Sep 2006
We've already established the fact that GD2 is supported on your server because it shows up in phpinfo().
Run the following code, and see what error comes up:
<?php
header (\"Content-type: text/plain\");
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, \"A Simple Text String\", $text_color);
imagepng($im);
imagedestroy($im);
?>
L3ZL1E posted this at 19:27 — 19th July 2007.
They have: 32 posts
Joined: Feb 2007
It just opens a popup to save to disk or open in dreamweaver...when I open it in dw it says something like:
‰PNG
pr0gr4mm3r posted this at 19:49 — 19th July 2007.
He has: 1,502 posts
Joined: Sep 2006
Well...in theory, that code was going to show you the error that was happening. Somehow, you are going to have to read that debugging/error information from PHP on what error is happening. Your IIS error logs may/may not have that info - that may be worth looking into.
It seems that this is an issue with IIS, and that's where my experience stops. Hopefully, somebody with some IIS experience will stop in.
L3ZL1E posted this at 19:54 — 19th July 2007.
They have: 32 posts
Joined: Feb 2007
Thanks so much for your help! I'm going to try to keep this thread going. There has to be someone out there that knows what to do!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.