Installing GD
The Perl Journal, Summer 2000
 

To install GD on your system, you'll need to install some system libraries first. Here is a step-by-step guide to retrieving and installing them. Again, none of this is necessary if you're using Perl on Windows or a Mac.

zlib

The zlib compression library can be obtained from ftp://ftp.freesoftware.com/pub/infozip/zlib/zlib.tar.gz. Download and extract the archive. On most systems (Solaris is an exception) you will not have to build the zlib library, because when you build libpng later, it incorporates the source files rather than the actual library. If you choose to build and install zlib, use the standard install procedure:
  % ./configure
  % make
  # make install (as root)

libpng

Installing libpng is a little more complicated. You can get the latest version from ftp://ftp.cdrom.com/pub/png/src/. Look for something like "libpng-x.y.z.tar.gz", where x.y.z is the highest version number. Download and extract the archive. You'll need zlib on the same level as the libpng directory, and they should both be named without their versions. In other words, your directory structure should look like this:

           |
           +- zlib
           |
           +- libpng

Something like the following should do it. The actual commands may differ from system to system. You'll have to remove the archive before doing this (rm *.tar or rm *.tar.gz).

  % mv zlib* zlib
  % mv libpng* libpng
  % cd libpng
  % cp scripts/makefile.stf Makefile
  % make
  # make install (as root)

You should choose one of the makefiles in the libpng/scripts directory according to your system (such as scripts/makefile.linux for Linux or scripts/makefile.sunos for Solaris).

lttf (optional)

If you want support for TrueType fonts in your graphs (say, because you want your axis labels in Japanese), you can install the lttf library. You cannot build this if you don't have X Windows installed. You can download lttf from http://freetype.sourceforge.net/download.html and then build it as usual:

  % ./configure
  % make
  # make install (as root)

jpeg-6b

You will need the jpeg-6a (or later) library on your system for GD.pm to compile. It is often already installed, so check /usr/lib or /usr/local/lib for libjpeg. If it's not installed, you can download it from ftp://ftp.uu.net/graphics/jpeg/ and build it with the steps shown above. Alternately, there may be a precompiled packaged version (RPM, DEB, etc.) available from your local package site.

libgd

Installing libgd should now be straightforward. Download the latest version from ftp://ftp.boutell.com/pub/boutell/gd/. After extracting the archive, edit the Makefile so that it includes support for jpeg and ttf if you installed those packages. You may also have to add -I/usr/local/include/freetype to the INCLUDEDIRS= line to make it work with freetype-1.3.1. You can then build the library as follows:

  % make
  # make install (as root)

You will now be able to install GD and the rest of the Perl modules mentioned in this article.