Installing GD Graphics Library on Mac OS X

Recently, I needed to install the GD Graphics Library locally on my Mac. GD is an open source code library for the dynamic creation of images by programmers. GD creates PNG, JPEG and GIF images, among other formats. GD is commonly used to generate charts, graphics, thumbnails, and most anything else, on the fly. While not restricted to use on the web, the most common applications of GD involve web site development.

I searched through a lot of tutorials, and found that most of them are out of date and/or incomplete. In spite of this, I finally managed to figure it out. However, I took notes on everything I did so that someone else needing to do this will find this helpful and won’t have to struggle with it as much as I did.

I have to admit I am pretty green when it comes to using command line and installing open source code on my computer. I have learned a lot though and I really enjoy it. I have found that the Mac is a great open source programming environment. Many programmers are figuring this out, and I believe you will continue to see more programmers coming to the Mac platform.

Anyway, these instructions, as straightforward as they are, still assume you know the basics of how to install and run open source code on your computer. If you don’t, you need to go read more and then come back here. Now, let’s begin.

The first thing you need to do is download the packages you will need. Here is the commands you will use for the most current versions of these packages as of this posting.

curl -O http://www.zlib.net/zlib-1.2.3.tar.gz
curl -O http://superb-east.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.20.tar.gz
curl -O ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
curl -O http://download.savannah.gnu.org/releases/freetype/freetype-2.3.5.tar.gz
curl -O http://www.libgd.org/releases/gd-2.0.35.tar.gz

Download these packages to a directory on your hard drive. The next thing you need to do is unpack these directories. Running this command will unpack all the directories you just downloaded.

ls *gz | xargs -n 1 tar zxvf

First, we will install zlib by running the commands below.

cd zlib-1.2.3
./configure --shared
make
sudo make install

Next, install libpng by running the commands below.

cd ../libpng-1.2.20
cp scripts/makefile.darwin Makefile

Open up Makefile in your favorite text editor and edit the file to read as follows.

# Where the zlib library and include files are located
ZLIBLIB=/usr/local/lib
ZLIBINC=/usr/local/include
#ZLIBLIB=../zlib
#ZLIBINC=../zlib

Then finish the install.

make
sudo make install

Test this by running the following code.

export srcdir=.
./test-pngtest.sh

Next install libjpeg.

cd ../jpeg-6b/
ln -s `which glibtool` ./libtool
export MACOSX_DEPLOYMENT_TARGET=10.4
./configure --enable-shared
make
sudo make install

Now install freetype2.

cd ../freetype-2.3.5

Open include/freetype/config/ftoption.h in your favorite editor and uncomment line 461 to read as follows.

#define TT_CONFIG_OPTION_BYTECODE_INTERPRETER

Then complete the install.

./configure
make
sudo make install

Finally install GD.

cd ../gd-2.0.35
ln -s `which glibtool` ./libtool
./configure

The report looked like this when I did it.

Support for PNG library: yes
Support for JPEG library: yes
Support for Freetype 2.x library: yes
Support for Fontconfig library: no
Support for Xpm library: no
Support for pthreads: yes

Then finish the install.

make
sudo make install

You can test it with the following code.

./gdtest test/gdtest.png
open test/*.jpg

To add support for Fontconfig, run this command.

export GDFONTPATH=$HOME/Library/Fonts:/Library/Fonts:/System/Library/Fonts

To complete the installation, you need to recomple PHP with all the libraries you just installed. Here is how I did it.

./configure \
--with-zlib-dir=/usr/local/lib \
--with-jpeg-dir=/usr/local/lib \
--with-png-dir=/usr/local/lib \
--with-gd \
--with-mysql=/usr/local/mysql \
--with-apxs

make
sudo make install

Now you should have PHP with GDLIB installed. That’s it. You’re done! Now, on to your next project!

Related Posts:

del.icio.us Digg Furl Reddit Google StumbleUpon Technorati Yahoo!

2 Responses to “Installing GD Graphics Library on Mac OS X”

  1. davermont Says:

    Great writeup, you’ve made my day!

    One thing I dread when upgrading to a new OS is getting the GD library installed and working again. Thanks for braving this install, and for taking the time to help out the rest of us.

    The only snag I ran into was in compiling libpng; I got the following error:
    ld: malformed version number: 0.1.2.20
    The solution was to edit the Makefile changing line 23 to:
    PNGVER = $(PNGMIN)

    Other than that it was a snap, thanks again!

  2. wallace Says:

    Found your blog via google after searching for the

    dyld: Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib

    error. Tried your fix of copying across the file and I now have the latest php5 up and running (was upgrading from a previous php5 version).

    So thanks!

Leave a Reply

Most Popular Posts

Pages

Twitter Updates

  • And yes it is true for those of you that don't know, the bird is the word. Indeed. 1 day ago
  • Excellent Office Space reference in Family Guy this week. Slow motion too. 1 day ago
  • Feeling like Michael Scott is going to walk by my desk at any moment. 1 day ago
  • More updates...

Profiles