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.
Comments on this entry are closed.
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!
Hi,
In your phpinfo() screenshoot, it shows libJPEG Version: Unknown. Is that ok? Did you check if the library is working properly?
Thanks!
LibFreeType and LibJPEG, that’s what I needed, thanks! 😀 Actually running it on PHP 5.6.1