但是如果使用其他一些php开发的工具也会涉及到。
一、简单介绍一下gd库:
gd库提供了一系列用来处理图片的API,使用GD库可以处理图片,或者生成图片。
在网站上GD库通常用来生成缩略图或者用来对图片加水印或者对网站数据生成报表。
也就是有了gd库,我们用php对图片的处理将会得心应手。
二、安装GD的过程
1.
# 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
# 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
将拷贝出来的makefile放在上级目前下面之后。修改makefile文件中的如下处
# Where the zlib library and include files are located
ZLIBLIB=/usr/local/zlib/lib
ZLIBINC=/usr/local/zlib/include
然后进行编译就可以成功了
# make ; make install
备注:
安装libpng的时候,报下面的错误的话,如果是已经装了zlib还报这个错的话,哪么就要重新换一种方式装zlib
configure: error: ZLib not installed
最后的解决方案是:
1.进入zlib的源文件目录,执行命令 make clean,清除zlib;
2.重新配置
./configure,后面不要接--prefix参数;(我第一次装的时候是加了prefix来进行编译的。所以这一次不要)
3.编辑 && 安装;
4.进入libpng目录,执行命令 ./configure --prefix=/usr/local/libpng;
5.编译 && 安装;
6.安装成功;
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
如果报错:
No package 'libxml-2.0' found Consider adjusting the PKG_CONFIG_PATH
environment variable if you Alternatively, you may set the environment
variables LIBXML2_CFLAGS |
但是我们在上面其实已经安装上 libxml2 了的,这里只是一个环境变量没有设置好而已。
解决办法: 确定 /usr/local/libxml2/lib/pkgconfig 目录下有 libxml-2.0.pc
export PKG_CONFIG_PATH=/usr/local/libxml2/lib/pkgconfig:$PKG_CONFIG_PATH
记住在export前面无需要有sudo,这样子就会通过了。
然后在进行下面的操作的时候,也不要加sudo执行
./configure --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config
再次生成 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
下面出现:表示都支持了
|
编辑/etc/ld.so.conf,
在
libc.conf文件中加入下面的库,如果没有调用这些库的话,验证码的图片,就会显示成黑白色。无法正常显示。
添加以下几行到此文件中。
三. 重新编译安装php(需要以下这些东东,如果想知道详情,请参见我的另外一篇博文)
./configure --prefix=/opt/php --with-gd=/usr/local/libgd
--with-jpeg-
dir=/usr/local/libjpeg
freetype-dir=/usr/local/freetype --enable-mbstring
--enable-mbstring --
with-apxs2=/opt/apache/bin/apxs --with-mysql=/opt/mysql
--with-config-
file-path=/opt/php/etc
http://blog.sina.com.cn/s/blog_517e2e1b0100ejyg.html(大部分的步骤来自这位好友的博客)
http://www.iced36.cn/log/?action=show&id=51