FAQ PHP
From LibGD
Contents |
How do I get gd to work with PHP?
If you compile PHP yourself, it is recommended to use the bundled version of the GD library. It is possible using the following configure line (all features and works with all php versions):
./configure --with-gd -with-png-dir=/usr --with-jpeg-dir=/usr --with-freetype-dir=/usr'
Update: please note that PHP has not yet been updated to include support for the animated GIF features that have been added to gd. It will be added in php 5.3 and 6.x
From 4.3.x, PHP includes its own version of gd, bundled in each PHP release.
The PHP version of gd offers features similar to and sometimes in addition to those included in the latest version of gd found here as well as many bug fixes not present in the latest GD release. If you are working with PHP, using the built-in gd of PHP 4.3.0 or better is recommended.
We are working to merge the changes done in the PHP GD in the normal GD library.
if you wish to continue using php 4.2.3 but need gd support for it, see the patching PHP for gd 2.0.8 and up page for important information. Please understand that patching PHP is probably not easier than upgrading PHP unless you have a very good reason to believe upgrading will not work for you.
Windows
The php_gd2.dll is included in a standard PHP installation for Windows, it's not enabled by default. You have to turn it on, the user may simply uncomment the line "extension=php_gd2.dll" in php.ini and restart the PHP extension.
Change:
#extension=php_gd2.dll
To:
extension=php_gd2.dll
You may also have to correct the extension directory setting from:
extension_dir = "./" Or: extension_dir = "./extensions"
NOTE: SUBSTITUTE THE ACTUAL PHP INSTALLATION DIRECTORY ON *YOUR* COMPUTER.
To (FOR WINDOWS):
extension_dir = "c:/php/extensions"
Thanks to Benoit Blais for this last point. Thanks also to Alan MacDougall and Perculator.
Unices/Linux
If you compile php yourself from CVS or the sources releases, you have to use the following configure options:
./configure '--with-gd' '--with-png-dir=/usr' '--with-jpeg-dir=/usr' '--with-freetype-dir=/usr' '--with-zlib-dir=/usr'
Change the path if you have not installed libpng, libjpeg or zlib in /usr.
A detailed version is availaible here.
Where can I find an example of PHP programming with gd?
There is many high quality documentations and tutorials available. Here is the most complete:
- The PHP Manual, the manual notes can be a gold mine
- PHP In a Nutshell, [Multimedia chapter http://hudzilla.org/phpwiki/index.php?title=Main_Page]
- Amazing presentation by Jeff Knight of New York PHP
- the www.phpgd.com is site dedicated to PHP and GD with a forum and a tutorials section
Why does gd cause my PHP script to run out of memory?
Most often, the problem is that the memory_limit parameter in php.ini is set to something very conservative, like 8M (eight megabytes). Increase that setting and restart the web server.
Of course, opening truly huge images can cause real memory problems, if several are open at once. 8,000 pixels times 8,000 pixels times four bytes for truecolor equals a walloping 256 megabytes.
See the PHP manual memory limit
How do I know which GD Version is used?
See phpinfo:
<?php phpinfo(); ?>
If you use the bundled PHP version, you will see something like in the result page:
| gd | |
| GD Support | enabled |
| GD Version | bundled (2.0.28 compatible) |
| FreeType Support | enabled |
| GIF Read Support | enabled |
| GIF Create Support | enabled |
| JPG Support | enabled |
| PNG Support | enabled |
| WBMP Support | enabled |
| XBM Support | enabled |
