Showing posts with label enable GD. Show all posts
Showing posts with label enable GD. Show all posts

Wednesday, January 28, 2009

How to Enable Image Support for PHP

How to Enable Image Support for PHP

Enabling support for images such as JPEG and PNG images on PHP should be relatively easy, unfortunately online documentation on how to do this is unclear. The following is a list of steps that you can take to enable PHP support for your site. You might want to do this if you're trying to enable thumbnail generation on MediaWiki and you encounter an error like Fatal error: Call to undefined function: imagecreatefromjpeg() .
For SLES 9 simply install the following rpms:

t1lib-1.3.1-569.1.i586.rpm
php4-gd-4.3.4-43.8.i586.rpm

These steps were performed on a Red Hat Enterprise Linux ES release 3 machine, running PHP 4.3.10 and Apache 2.0.52.


Shared Tape Library
Download White Paper on NetApp VTL Integration for Your Network.
www.NetApp.com Music Library
2GB, Absolutely Free - Not A Trial Fast, Secure, And Free! Get Mozy.
Mozy.com PowerEdge™ Tower Servers
High performance Servers from Dell™ with Intel® Xeon® Processor E3110
dell.com/towerservers
Ads by Google
Hide these ads

Show Ads
[edit] Steps

1. Download and install the JPEG library from here. The file you want to download is jpegsrc.v6b.tar.gz. Unzip, extract, configure, make and install by executing these steps:

tar xvfz jpegsrc.v6b.tar.gz
cd jpeg-6b
./configure
make
make install

2. This will install the library in your /usr/local directory. Unfortunately if you plan on compiling GD (GD is the graphics library that PHP uses) from scratch you will also have to copy over the header files manually by doing this:

cp ./include/j*.h /usr/local/include

3. Only do this if you want to compile GD yourself.

4. Download and install the LIBPNG library. Even though you might not configure PHP using PNG support, you can't for some reason configure GD without it. Go here, scroll down to where you see "Source Code" and download a version, this example will use the .tar.gz version.

tar xvfz libpng-1.2.8-config.tar.gz
cd libpng-1.2.8-config
./configure
make
make install

5. Now that these 2 libraries are installed, it's time to compile PHP. If you already have PHP installed on your machine you may have to download the source all over again and recompile it. Go to PHP's home page and download the most recent versin of the 4.x source code. Extract it and configure. The following configure options enable MySQL and Apache libraries as well as the image libraries, if you have any other libraries that you wish to use, make sure to include them.

./configure --with-mysql --with-apxs2=/usr/sbin/apxs \
--with-gd --with-jpeg --with-jpeg-dir=/usr/local \
--with-png --with-png-dir=/usr/local --with-zlib-dir=/usr
(the backslahes denote a new line)
make
make install

6. After this, it's time to restart Apache:

httpd -k restart

7. If you get a warning about the PHP module already being loaded, remove either the LoadModule in httpd.conf or remove the php.conf file in /etc/httpd/conf.d.

8. Now you should have images support for PHP!


[edit] Tips

* If any compilation fails and you have to reconfigure, make sure you do "make clean" before doing a make.
* Listen to some relaxing music while doing this, because wading through unclear documentation for your desired setup could be very frustrating. I suggest Nick Drake's Pink Moon album to help things along.
* Visit PHP.net's Image Functions for the most recent URLs for the libraries and instructions for configuring images and more information.