Page 1 of 2

gd library

Posted: Thu Nov 17, 2005 7:02 pm
by JasonTC
Is anyone using the gd library with PHP? If so, how do I install it? I've read the documentation, but it's not very clear to me what I'm supposed to do. Do I really have to compile C code? Sorry if this is a dumb question, but I'm finding this more difficult than it seems like it should be.

Thanks,
Jason

Posted: Thu Nov 17, 2005 7:06 pm
by John Cartwright
http://ca.php.net/gd read the installation section

Posted: Thu Nov 17, 2005 7:07 pm
by Deemo
when PHP installed, you have the option of installing the GD libraries. i believe the configuration tag is --with-gd (assuming you have php 4.3+)

bah beat me to it :P

Posted: Thu Nov 17, 2005 7:22 pm
by JasonTC
Well, turns out we have PHP 4.3.9 here, but I wasn't the one who installed it. Apparently, the gd library has been installed, but there was only one script that used it and it gave me some errors when I tried to test it. However, these errors came from an include file and were not gd-related.

Just now, I grabbed a little test thing from php.net:

Code: Select all

<?php

header("Content-type: image/png");
$string = $_GET['text'];
$im    = imagecreatefrompng("images/button1.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px    = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);

?>
I called it button.php and made another file like this:

Code: Select all

<img src="button.php?text=text">
Just like it said to. I changed the "images/button1.jpg" to point to an image that actually exists, too. I didn't get any errors, which implies the gd library is working, but this script just resulted in a broken image. Any ideas?

Posted: Thu Nov 17, 2005 8:11 pm
by AKA Panama Jack
Well, you won't get any errors calling a php program through an image tag. You could have all kinds of errors in the button.php program and they will never show.

You need to enter the url http://<your_web_site>/button.php?text=text to see if any errors show up or if the image is created.

Posted: Sun Nov 20, 2005 2:05 pm
by JasonTC
Well, I went to button.php directly with the header information commented out and it told me:

Code: Select all

Fatal error: Call to undefined function: imagecreatefrompng() in c:\wwwroot\button.php on line 5
What do I need to do to fix this?

Thanks,
Jason

Posted: Sun Nov 20, 2005 2:15 pm
by AKA Panama Jack
Well, it looks like you don't have the gd library installed in PHP.

Execute one of these small scripts.

Code: Select all

<?php
if(function_exists("gd_info"))
	var_dump(gd_info());
else
	echo "GD Library not installed";
?>
or

Code: Select all

<?php
if(function_exists("gd_info"))
	print_r (gd_info());
else
	echo "GD Library not installed";
?>
This will give you a list of the installed GD modules.

["PNG Support"] => bool(true)

Will be shown if the PNG module is installed. If the GD library isn't installed in PHP then you will get the "GD Library not installed" message.

Posted: Sun Nov 20, 2005 3:05 pm
by JasonTC
That resulted in "GD Library not installed", which reverts us back to my original post. Someone posted a link to the php.net installation instructions, but I don't fully understand them. For example, it says:
To enable GD-support configure PHP --with-gd[=DIR], where DIR is the GD base install directory. To use the recommended bundled version of the GD library (which was first bundled in PHP 4.3.0), use the configure option --with-gd. GD library requires libpng and libjpeg to compile.

In Windows, you'll include the GD2 DLL php_gd2.dll as an extension in php.ini. The GD1 DLL php_gd.dll was removed in PHP 4.3.2. Also note that the preferred truecolor image functions, such as imagecreatetruecolor(), require GD2.
I don't know what "configure PHP --with-gd[=DIR]" means. One thought is that it a step that is taken in the PHP installation process, in which I did not participate. I un-commented the line in php.ini that reads "extension=php_gd2.dll" but it made no difference. I wasn't all that surprised by this since I don't really know what I'm doing, anyway. Can someone possibly put the installation process in simple terms for me?

Thanks,
Jason

Posted: Sun Nov 20, 2005 3:27 pm
by onion2k
If you install PHP from the binary version then uncommenting the extension line in your PHP.ini file should definitely work. Is php_gd2.dll in your php/extensions directory (thats c:/php/extensions/ on my pc here, but may be different on your computer)?

Posted: Sun Nov 20, 2005 3:29 pm
by JasonTC
Same on mine.

Posted: Sun Nov 20, 2005 3:38 pm
by AKA Panama Jack
JasonTC wrote:I un-commented the line in php.ini that reads "extension=php_gd2.dll" but it made no difference.
Did you stop Apache and restart it after you made those changes to the php.ini?

Posted: Sun Nov 20, 2005 7:40 pm
by yum-jelly
Also....

Follow me....

My Computer >> Right Click >> scroll down to >> Properties >> Left Click

Top of... >> System Properties >> Left Click >> Advanced >> Go Down To >> Environment Variables >> Left Click

Lower Window >> Highlight Variable * Path * >> Left Click the * Edit Button * below that window! Go to the beginning of * Variable Value * place your cursor there, then type!

c:\php\dlls;

If that is the path to your PHP * dlls folder * remember type exactly what is above including the semicolon (the path must not end with * \ * it must be the directory name, in this cae * dlls *)

Left Click * OK * 3 times, restart Apache, IIS or what ever you are using...

yj

Posted: Mon Nov 21, 2005 12:53 am
by n00b Saibot
There have been posts above which indicate that restarting Apache is necessary but I don't think it to be necessary... all it needs is uncommenting the particular line, saving the ini and a F5(refresh) :| and yes, I have pretty much personal exp. to back that statement :)

Posted: Mon Nov 21, 2005 1:00 am
by AKA Panama Jack
n00b Saibot wrote:There have been posts above which indicate that restarting Apache is necessary but I don't think it to be necessary... all it needs is uncommenting the particular line, saving the ini and a F5(refresh) :| and yes, I have pretty much personal exp. to back that statement :)
If you make any changes to the php.ini you have to restart apache for the changes to take effect. Apache will reload PHP when it is restarted.

Posted: Mon Nov 21, 2005 1:39 am
by n00b Saibot
I've installed Apache+PHP several times with default conf. i.e. include_dir="", php_gd2.dll commented out. And when the need is there for gd functions or for that matter any lib, I simply uncomment the particular line, refresh my page and wham! its working AND NO RESTARTING APACHE :twisted: