≡ Menu

How to Enable GD Library in PHP with LibJPEG, FreeType and LibPNG

In PHP you can manipulate image files using GD library.

It support several formats including GIF, PNG, JPEG, etc. You can use LibGD library to stream images directly from your application to the browser.

This tutorial explains how to enable GD functionality in PHP.

Download LibJPEG Library

First, download the LibJPG files from here. Or, you can use the wget below to download it directly.

cd /usr/save
wget http://www.ijg.org/files/jpegsrc.v9.tar.gz

Install LibJPEG Library

Once you’ve downloaded it, extract the archive and install it as shown below.

tar xvfz jpegsrc.v9.tar.gz
cd jpeg-9
./configure
make
make install

This will install the jpeg libraries in the default /usr/local/lib/ location as shown below.

# ls /usr/local/lib/*jpeg*
/usr/local/lib/libjpeg.a
/usr/local/lib/libjpeg.la*
/usr/local/lib/libjpeg.so -> libjpeg.so.9.0.0*
/usr/local/lib/libjpeg.so.9 -> libjpeg.so.9.0.0*
/usr/local/lib/libjpeg.so.9.0.0*

Download FreeType Library

Download the freetype library from here. Or, you can use the wget below to download it directly.

cd /usr/save
wget http://iweb.dl.sourceforge.net/project/freetype/freetype2/2.5.0/freetype-2.5.0.1.tar.bz2

Install FreeType Library

Once you’ve downloaded it, extract the archive and install it as shown below.

tar xvfj freetype-2.5.0.1.tar.bz2
cd freetype-2.5.0.1/
./configure --without-png
make
make install

While installing freetype, if you don’t specify without-png flag to the ./configure as shown above, you might get the following error during ./configure

/usr/include/libpng12/pngconf.h:336: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
/usr/include/libpng12/pngconf.h:337: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'include'
make: *** [/usr/src/freetype-2.5.0.1/objs/sfnt.lo] Error 1

Install LibPNG

For most part, your system might already have LibPNG libraries installed as shown below.

# rpm -qa | egrep 'jpg|png'
libpng-devel-1.2.10-7.1.el5_0.1
libpng-1.2.10-7.1.el5_0.1

But, if you don’t have it, download and install LibPNG from here.

Compile PHP

Now, download and install PHP from source as we explained earlier. But, this time, make sure to pass the following parameters to the ./configure in your PHP installation.

./configure \ 
     --with-apxs2=/usr/local/apache2/bin/apxs  \
     --with-mysql \
     --with-gd \
     --with-jpeg-dir \
     --enable-gd-native-ttf \
     --with-freetype-dir \
make
make install

Verify GD is enabled in PHP

Now, create a test php page with the phpinfo(),and view it from the browser. As you see below, you’ll notice that it has the LibGD and related libraries enabled.

Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • memo November 13, 2013, 8:56 am

    Hi,
    I’m on a Amazon Linux Ami with php and apache installed. Needed GD extension.
    Started to proceed with your instructions. On ./configure it returned an error stating configure: error: in `/tmp/jpeg-9′:
    configure: error: no acceptable C compiler found in $PATH

    Pls. help!

  • Fernando January 6, 2014, 3:05 am

    Hi,

    In your phpinfo() screenshoot, it shows libJPEG Version: Unknown. Is that ok? Did you check if the library is working properly?

    Thanks!

  • Katsuro October 16, 2014, 11:28 am

    LibFreeType and LibJPEG, that’s what I needed, thanks! 😀 Actually running it on PHP 5.6.1