gd library

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

JasonTC
Forum Commoner
Posts: 92
Joined: Wed Nov 02, 2005 11:05 am
Location: Grand Rapids, MI

gd library

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

http://ca.php.net/gd read the installation section
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post 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
JasonTC
Forum Commoner
Posts: 92
Joined: Wed Nov 02, 2005 11:05 am
Location: Grand Rapids, MI

Post 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?
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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.
JasonTC
Forum Commoner
Posts: 92
Joined: Wed Nov 02, 2005 11:05 am
Location: Grand Rapids, MI

Post 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
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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.
JasonTC
Forum Commoner
Posts: 92
Joined: Wed Nov 02, 2005 11:05 am
Location: Grand Rapids, MI

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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)?
JasonTC
Forum Commoner
Posts: 92
Joined: Wed Nov 02, 2005 11:05 am
Location: Grand Rapids, MI

Post by JasonTC »

Same on mine.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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?
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post 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
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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 :)
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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:
Post Reply