编译安装GD库对gif jpg(jpeg) png wbmp xml 和 ttf字

可以说如果要配置一台LAMP服务器,都离不开安装gd库,就算自己php开发不涉及到图形方面,
但是如果使用其他一些php开发的工具也会涉及到。

简单介绍一下gd库:
gd库提供了一系列用来处理图片的API,使用GD库可以处理图片,或者生成图片。
在网站上GD库通常用来生成缩略图或者用来对图片加水印或者对网站数据生成报表。
也就是有了gd库,我们用php对图片的处理将会得心应手。

一、安装ncurses

安装gd库会用到的

#tar zxvf ncurses-5\[1\].6.tar.gz -C /usr/local/src

# cd /usr/local/src/ncurses-5.6/

#./configure --prefix=/usr --with-shared --without-debug

# make ; make install

二、安装GD

1. zlib

# tar zxvf zlib-1.2.3.tar.gz -C /usr/local/src/

# cd /usr/local/src/zlib-1.2.3/

# ./configure --prefix=/usr/local/zlib

# make ; make install

2.libpng

# tar zxvf libpng-1.2.26.tar.gz -C /usr/local/src/

# cd /usr/local/src/libpng-1.2.26/

# cp scripts/makefile.linux ./makefile //注意,这里的makefile不是用./configure生成,而是直接从scripts/里拷一个

# ./configure --prefix=/usr/local/libpng

# make ; make install

3.freetype(ttf)

# tar zxvf freetype-2.3.5.tar.gz -C /usr/local/src

# cd /usr/local/src/freetype-2.3.5/

# ./configure --prefix=/usr/local/freetype

# make ; make install

4.jpegsrc

# tar zxvf jpegsrc.v6b.tar.gz -C /usr/local/src/

# cd /usr/local/src/jpeg-6b/

# mkdir -pv /usr/local/libjpeg/{,bin,lib,include,man/man1,man1}

上面的命令是要手动创建一些目录,否则configure时候会说找不到目录

# ./configure --prefix=/usr/local/libjpeg --enable-shared --enable-static

注意,这里configure一定要带--enable-shared参数,不然,不会生成共享库

# make ; make install

5.libxml2

# tar zxvf libxml2-2.6.31.tar.gz -C /usr/local/src/

# cd /usr/local/src/libxml2-2.6.31/

# ./configure --prefix=/usr/local/libxml2

# make ; make install

# cp xml2-config /usr/bin/

6.libmcrypt

# tar zxvf libmcrypt-2.5.7.tar.gz -C /usr/local/src/

# cd /usr/local/src/libmcrypt-2.5.7/

# ./configure

# make ; make install

7.Fontconfig

# tar zxvf fontconfig-2.4.2.tar.gz -C /usr/local/src/

# cd /usr/local/src/fontconfig-2.4.2/

# ./configure --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config

如果报错:

checking for LIBXML2... configure: error: Package requirements (libxml-2.0 >= 2.6) were not met:

No package 'libxml-2.0' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBXML2_CFLAGS
and LIBXML2_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.


但是我们在上面其实已经安装上 libxml2 了的,这里只是一个环境变量没有设置好而已。

解决办法: 确定 /usr/local/libxml2/lib/pkgconfig 目录下有 libxml-2.0.pc

export PKG_CONFIG_PATH=/usr/local/libxml2/lib/pkgconfig:$PKG_CONFIG_PATH

再次生成 makefile , 这样就成功了。

# make ; make install

8.安装GD库

# tar zxvf gd-2.0.35.tar.gz -C /usr/local/src/

# cd /usr/local/src/gd-2.0.35/

# ./configure --prefix=/usr/local/libgd --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-jpeg=/usr/local/libjpeg --with-fontconfig=/usr/local/fontconfig

下面出现:表示都支持了

** Configuration summary for gd 2.0.34:

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

# make ; make install

编辑/etc/ld.so.conf,添加以下几行到此文件中。

/usr/local/zlib/lib

/usr/local/freetype/lib

/usr/local/libjpeg/lib

/usr/local/libgd/lib

并执行ldconfig命令,使用动态装入器装载找到共享库


你可能感兴趣的:(编译安装GD库对gif jpg(jpeg) png wbmp xml 和 ttf字)