As my web applications for artists became more sophisticated, I realized the value in having the ability for the app to dynamically resize images, say, to create thumbnails when an image is uploaded. Under PHP, the obvious choice is the GD libraries. While GD was available on my production server, I had to install it on my Mac OS X development platform. I found the procedure which I've included below. NOTE: This procedure has become obsolete with the use of PHP5 and Marc Liyanage's Entropy package. Entropy is basically a bundled version of PHP for Mac OS X (both Apache 1.3 and 2) with all the goodies. Here is the original procedure for what it's worth.
How to Build GD on Mac OS X ? I have been trying to get the Smart Image Processor extension to work. Does anyone know where the GD library is supposed to go? I keep getting an error (GD Library not installed correctly).
GD is a set of utilities for creating and manipulating JPEG and PNG images, as well as libraries for adding graphics support in particular PHP. Smart Image Proccessor supports these libraries. The compile requires a couple of additional libraries to be installed first.
Setup
Create a temporary directory to build the libraries that GD requires, as well as GD itself. Also create the install directories since they may not yet exist.
$ mkdir build-gd
$ cd build-gd
$ sudo mkdir -p /usr/local/share/man /usr/local/include /usr/local/bin /usr/local/lib
For JPEG images support, the jpeg-6b libraries need to be installed. Smart Image Proccessor can not function without them. Aside from relocating the man pages to the place where we expect them on Mac OS X, no changes are required.
Download and build the latest jpeg libraries:
$ curl -O ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
$ gnutar -xzf jpegsrc.v6b.tar.gz
$ pushd jpeg-6b/
$ ./configure
$ make
$ sudo make install mandir="/usr/local/share/man"
$ sudo make install-lib
$ sudo ranlib /usr/local/lib/libjpeg.a
$ popd
For manipulating PNG files, the libpng code needs to be compiled. For the Smart Image Proccessor this part is not required, only if you want to support PNG files for resize. After resize the image gets always converted to a JPEG
Download and build the latest png libraries:
$ curl -O http://download.sourceforge.net/libpng/libpng-1.2.25.tar.gz
$ tar -xvzf libpng-1.2.5.tar.gz
$ pushd libpng-1.2.5/
$ ./configure
$ make
$ sudo make install
$ sudo ranlib /usr/local/lib/libpng.a
$ popd
GD also requires the zlib library, but this is supplied with Mac OS X.
After completing the above steps, the actual GD source can be compiled. Because we don't want to change the Makefile, the correct value for the COMPILER variable is passed. This will cause a couple of errors at the end of this compile, complaining about missing X-Windows directories. They aren't required, and it's nothing to worry about.
This will install the GD applications (webpng, pngtogd and a bunch of others) as well as the libraries that allow other applications to use GD functionality.
Download and build the latest GD:
$ curl -O http://www.libgd.org/releases/gd-2.0.35.tar.gz
$ tar xvzf gd-2.0.35.tar.gz
$ pushd gd-2.0.35
$ ./configure
$ sudo make install
$ sudo ranlib /usr/local/lib/libgd.a
$ popd
There may be a warning about no symbols in the library, but that's something that can be safely ignored.
You are now ready to add GD support to PHP!
$ curl -O http://www.php.net/get/php-4.4.8.tar.gz
$ sudo make install