怎样编译安装GD库

2015年12月15日 | 分类: 【技术】

【介绍】

LibGD 是一个开源的图像处理库,支持 PNG/JPEG/GIF以及其他格式的图像。GD一般被用来创建图表、图形、缩略图以及其他图像相关的处理操作。

官网:https://www.libgd.org/
源码:https://github.com/libgd/libgd/

【rpm安装最新版本gd(推荐)】

依赖:

yum install libwebp libwebp-devel libxml2 libxml2-devel zlib zlib-devel libpng libpng-devel freetype libjpeg libjpeg-devel libXpm libXpm-devel

下载:https://centos.pkgs.org/7/remi-x86_64/gd-last-2.2.5-8.el7.remi.x86_64.rpm.html
下载:https://centos.pkgs.org/7/remi-x86_64/gd-last-devel-2.2.5-8.el7.remi.x86_64.rpm.html

yum install http://rpms.remirepo.net/enterprise/7/remi/x86_64//gd-last-2.2.5-8.el7.remi.x86_64.rpm
yum install http://rpms.remirepo.net/enterprise/7/remi/x86_64//gd-last-devel-2.2.5-8.el7.remi.x86_64.rpm

如果报错:

Error: Package: gd-last-2.2.5-8.el7.remi.x86_64 (/gd-last-2.2.5-8.el7.remi.x86_64)
           Requires: libwebp.so.7()(64bit)

那么安装它:

下载:https://centos.pkgs.org/7/remi-x86_64/libwebp7-1.0.2-1.el7.remi.x86_64.rpm.html

yum install http://rpms.remirepo.net/enterprise/7/remi/x86_64//libwebp7-1.0.2-1.el7.remi.x86_64.rpm

如果报错:

Error: gd-last-devel conflicts with gd-devel-2.0.35-26.el7.x86_64

那么卸载它:

yum remove gd-devel

【yum安装】

问题:版本较低。

yum install libwebp libwebp-devel libxml2 libxml2-devel zlib zlib-devel libpng libpng-devel freetype libjpeg libjpeg-devel libXpm libXpm-devel gd gd-devel

【从源码编译安装】

问题:可能出现奇怪的环境问题。

安装次序:1. zlib > 2. libpng > 3. freetype > 4. jpeg > 5. libxpm > 6. libgd

编译安装zlib:

参考:https://amon.org/zlib

编译安装libpng:

参考:https://amon.org/libpng

编译安装freetype:

参考:https://amon.org/freetype

编译安装jpeg:

参考:https://amon.org/jpeg

编译安装libtiff:

参考:https://amon.org/libtiff

yum安装libxpm:

yum install libXpm libXpm-devel

编译安装libgd:

下载:https://github.com/libgd/libgd/releases

最新版本:libgd-2.3.0

wget https://github.com/libgd/libgd/releases/download/gd-2.3.0/libgd-2.3.0.tar.gz && tar -zxvf libgd-2.3.0.tar.gz && cd libgd-2.3.0
./configure --prefix=/usr/local/gd --enable-shared --with-jpeg=/usr/local/jpeg --with-freetype=/usr/local/freetype --with-png=/usr/local/png LDFLAGS="-L/usr/lib -lz"
make && make install

较早版本:libgd-2.2.5

wget https://github.com/libgd/libgd/releases/download/gd-2.2.5/libgd-2.2.5.tar.gz && tar -zxvf libgd-2.2.5.tar.gz && cd libgd-2.2.5
./configure --prefix=/usr/local/gd --enable-shared --with-jpeg=/usr/local/jpeg --with-freetype=/usr/local/freetype --with-png=/usr/local/png LDFLAGS="-L/usr/lib -lz"
make && make install

输出:

...
Libraries have been installed in:
   /usr/local/gd/lib
...

编译安装完成。

export GDLIB_CFLAGS="-I/usr/local/gd/include" GDLIB_LIBS="-L/usr/local/gd -lgd"

【参考】

参考:http://www.linuxforums.org/forum/red-hat-fedora-linux/136596-installing-gd-php.html
参考:https://www.linuxquestions.org/questions/mandriva-30/mediawiki-thumbnail-error-incomplete-gd-library-configuration-missing-function-image-529292/page2.html
参考:https://blog.csdn.net/angelz/article/details/331257