虚拟化容器,大数据,DBA,中间件,监控。

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

14 10月
作者:admin|分类:系统运维

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/savewget 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.


浏览25.2k 评论0
返回
目录
返回
首页
/usr/include/libpng12/pngconf.h:337: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'include' make: *** Top 25 Best Linux Performance Monitoring and Debugging Tools