不重新编译php, 扩展gd库

1.准备
$ wget https://bitbucket.org/pierrejoye/gd-libgd/get/GD_2_0_33.zip
$ wget http://prdownloads.sourceforge.net/libpng/libpng-1.5.12.tar.gz?download
$ wget http://www.ijg.org/files/jpegsrc.v8d.tar.gz
$ wget http://sourceforge.net/projects/freetype/files/latest/download?source=files
$ mv download?source=files freetype.tar.bz2


2.安装 freetype
$ tar jxvf freetype.tar.bz2
$ cd freetype-2.4.10/
$ ./configure --prefix=/usr/local/freetype
$ make && make install


3.安装 jpeg
$ tar zxvf jpegsrc.v8d.tar.gz
$ cd jpeg-8d/
$ ./configure --prefix=/usr/local/jpeg8d --enable-static --enable-shared
$ make && make install


3.安装libpng
  在以前安装apache 的时候安装了zlib, 但是在在装zlib的时候,可能还是找不到zlib, 只需在进到zlib 文件夹, 运行make clean, 然后不带参数再编译安装一次
a.重新安装zlib
$ cd <zlib源文件>/
$ make clean
$ ./configure
$ make && make install

b.安装libpng
$ tar zxvf libpng-1.5.12.tar.gz
$ cd libpng-1.5.12/
$ ./configure --prefix=/usr/local/libpng && make && make install


4.安装 GD
  安装的时候提示找不到png.h, 先修改gd_png.c
$ unzip GD_2_0_33.zip
$ cd pierrejoye-gd-libgd-5551f61978e3/src
$ vi gd_png.c
/*
 #include "png.h" ==> #include "/usr/local/libpng/include/png.h"
*/
$ sudo ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg8d --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype


5.整合php & gd
  对于php5.4有个bug,在 "gdIOCtx"结构体中没有 "data" 这个成员,解决办法
$vi <gd_dir>/include/gd_io.h
/*
typedef struct gdIOCtx

{
  int (*getC) (struct gdIOCtx *);
  int (*getBuf) (struct gdIOCtx *, void *, int);
  void (*putC) (struct gdIOCtx *, int);
  int (*putBuf) (struct gdIOCtx *, const void *, int);
  int (*seek) (struct gdIOCtx *, const int);
  long (*tell) (struct gdIOCtx *);
  void (*gd_free) (struct gdIOCtx *);
  void (*data);// 新添加这一行
}
*/

  整合php & gd
$ cd <php源文件>/ext/gd
$ /usr/local/php5/bin/phpize //生成configure
$ ./configure --with-gd=/usr/local/gd --with-jpeg-dir=/usr/local/jpeg8d --with-png-dir=/usr/local/libpng --with-freetype-dir=/usr/local/freetype --with-zlib-dir=/usr/local/zlib --with-php-config=/usr/local/php5/bin/php-config
$ make && make install
$ vi /usr/local/php5/apache/php.ini
/*
extension=gd.so //添加这一行
*/
$ apache restart

注:不知道是不是动态扩展gd的原因, 这个时候访问服务器并不能打开网页, 查找apache error_log, 上面写着:
/usr/local/apache//bin/httpd: symbol lookup error: /usr/local/php5/lib/php/extensions/no-debug-zts-20100525/gd.so: undefined symbol: gdJpegGetVersionString

/usr/local/apache//bin/httpd: symbol lookup error: /usr/local/php5/lib/php/extensions/no-debug-zts-20100525/gd.so: undefined symbol: gdPngGetVersionString

在网上找了好长时间, 找不到解决这个问题的办法, 或者这个问题引起的原因, 我想到了一个办法作为临时的解决办法:修改gd.c
$ vi $ cd <php源文件>/ext/gd/gd.c
/*
在这个文件的下面添加
# include <png.h>
# include <jpeglib.h>
const char * gdJpegGetVersionString()
{
          switch(JPEG_LIB_VERSION) {
                  case 62:
                          return "6b";
                          break;
                  default:
                          return "unknown";
          }
}

const char * gdPngGetVersionString()
{
         return PNG_LIBPNG_VER_STRING;
}

*/

然后重新整合php & gd, 问题解决,可以生成验证码.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值