©
This document uses PHP Chinese website manual Release
要激活 GD 支持,配置 PHP 时加上 --with-gd[=DIR] ,DIR 是 GD 的基本安装目录。要使用推荐的绑定的 GD 库版本(首次绑定于 PHP 4.3.0),使用 --with-gd 。要编译 GD 库,需要libpng 和 libjpeg。
在 Windows 中,需要将 GD2 的 DLL 文件 php_gd2.dll 作为一个扩展包含在 php.ini 中。GD1 的 DLL 文件 php_gd.dll 在 PHP 4.3.2 中被删除了。此外要注意首选的真彩色图像函数,例如 imagecreatetruecolor() ,需要 GD2。
Note:
要在 Windows 下启用 exif,在 php.ini 中 php_mbstring.dll 必须在 php_exif.dll 之前加载。
要在 PHP 3 中禁止 GD 支持,在配置时加上 --without-gd 。
要增强 GD 的能力以处理更多的图像格式,在配置 PHP 时指定 --with-XXXX 的配置开关。
图像格式 | 配置开关 |
---|---|
jpeg-6b | 要激活 jpeg-6b 的支持,加上 --with-jpeg-dir=DIR . |
png | 要激活 png 的支持,加上 --with-png-dir=DIR 。注意,libpng 需要 zlib library,因此配置中还要加上 --with-zlib-dir[=DIR] 。 |
xpm | 要激活 xpm 的支持,加上 --with-xpm-dir=DIR 。如果配置时提示找不到所需要的库,可以加上到 X11 库的路径。 |
Note: 当把 PHP 和 libpng 一起编译时,必须使用和 GD 库连接的同一个版本。
要增强 GD 的能力以处理更多的字体,在配置 PHP 时指定 --with-XXXX 的配置开关。
字库 | 配置开关 |
---|---|
FreeType 1.x | 要激活 FreeType 1.x 的支持,加上 --with-ttf[=DIR] 。 |
FreeType 2 | 要激活 FreeType 2 的支持,加上 --with-freetype-dir=DIR 。 |
T1lib | 要激活 T1lib(Type 1 字体),加上 --with-t1lib[=DIR] 。 |
本地 TrueType 字符串函数 | 要激活本地 TrueType 字符串函数的支持,加上 --enable-gd-native-ttf 。 |
[#1] amenadiel at gmail dot com [2015-07-23 21:13:56]
While it is true that you can install GD with apt, that version comes without some of the traits of the internal, compiled version.
I noticed that when I tried to call method `imageantialias`
http://php.net/manual/es/function.imageantialias.php
[#2] Patrick [2015-03-26 02:35:23]
I installes php5-gd by adding
deb http://ftp.de.debian.org/debian sid main
in /etc/apt/sources.list
then
apt-get install php5-gd
then i have troubles for starting apache2 but google find all troubles ...
cd /etc/apache2
mkdir conf.d
changes in apache2.conf :
replace
LockFile ${APACHE_LOCK_DIR}/accept.lock
by
Mutex file:${APACHE_LOCK_DIR} default
comment lines NameVirtualHost (with a #)
a2enmod suexec (correction Suexec....)
a2enmod rewrite (correction erreur dav)
a2enmod dav_fs (correction erreur filesystem)
service apache2 start
[#3] balazstx [2015-03-09 13:57:56]
$ sudo yum install php55-gd
PHP Version 5.5.21
ERVER_SOFTWARE Apache/2.4.10 (Amazon) PHP/5.5.21
Amazon Linux AMI 2014.09.2 (HVM) - ami-04003319
[#4] leyluj21 at gmail dot com [2014-10-23 09:58:06]
If you are using PHPBREW , the extension is called gd.
So you do.
```
phpbrew ext install gd
```
It will compile the extension to the core.
[#5] RB [2014-09-17 21:34:37]
Ubuntu 14.04
apt-get install php5-gd
service apache2 restart
Fixed my Joomla / Kunena install for my LAMP-server.
[#6] james dot a dot munsch at gmail dot com [2014-09-05 22:19:06]
sudo apt-get install php5-gd && sudo service apache2 restart
To install under Ubuntu 14.04.
[#7] PHP Compiler [2013-12-21 22:58:06]
To all smart-willys who come here to tell us you installed GD with package management: No one cares if you used packages management to install GD. This is for people who compile from source.
[#8] MIguel G [2013-07-13 17:43:02]
If your are suffering with PHP53 on CentOS and GD,
just
yum install php53-gd
[#9] alejo dot jm at gmail dot com [2012-07-20 06:47:47]
On Macox lion with mac port just use:
sudo port install php5-gd
[#10] Regular Guy [2012-02-05 04:51:17]
CentOS 6
yum install php-gd
worked, no need to recompile.
[#11] drummerpatch at gmail dot com [2012-01-29 09:45:55]
Running a Debian Squeeze server, all I had to do to add support for GD to my Apache server was simply run `apt-get install php5-gd` and then restart Apache. No recompiling or reconfiguring or anything. Simple!
[#12] florian [2011-07-31 02:50:47]
People having difficulties setting the --with-libdir option needs to set it like this :
--with-libdir=lib64
That option works fine. Doing --with-libdir=/usr/lib64 doesn't work because the configure script prepends the --prefix option before the --with-libdir option. So, doing --with-libdir=/usr/lib64 makes the configure script to look for libs in /usr/usr/lib64, which is wrong of course, and not in /usr/lib64.
[#13] Joseph Marlin [2011-06-23 06:07:23]
I also had to install the libgd package in addition to php5-gd:
sudo apt-get install libgd2-xpm-dev*
[#14] octopus at logicaloctopus dot com [2011-04-17 00:07:22]
I was running PHP on a SUSE box on amazon EC2.
to get gd to work all I had to do was to run:
> yast -i php5_gd
and when that completed I just restarted apache. voila!
[#15] boly38 at gmail dot com [2011-03-17 05:25:49]
To get GD bundled under Ubuntu, the way to recompile php5 with gd is described here (french) http://doc.ubuntu-fr.org/modules_php#php5-gd
[#16] lucaferr [2010-12-21 05:30:23]
In Slackware 64bit (I tested 13.1) you need to make symlinks to libpng and libjpeg if you want to compile php with GD, even if you've already installed them, otherwise configure will give you a "libpng not found" error, even if you set --with-libdir=/usr/lib64 (it seems to have no effects at all). So, run these before configuring:
ln -s /usr/lib64/libjpeg.so /usr/lib/libjpeg.so
ln -s /usr/lib64/libpng.so /usr/lib/libpngp.so
[#17] elassoto at hotmail dot com [2010-09-10 13:54:13]
If you have already compiled PHP and want to recompile '--with-gd', don't forget to run 'make clean' first!
[#18] Larry Kluger [2010-01-13 14:40:56]
On 64bit centos, needed to create links from lib64 to lib. Php seems to insist on looking in lib, even with "with-jpeg-dir" config.
Eg
ln -s /usr/lib64/libjpeg.so.62.0.0 /usr/lib/libjpeg.so
ln -s /usr/lib64/libpng.so.3.10.0 /usr/lib/libpng.so
./configure \
--with-config-file-path=/etc \
--prefix=/usr \
--with-bz2 \
--enable-zip \
--enable-mbstring \
--with-apxs2=/usr/sbin/apxs \
--with-zlib-dir=/usr/include \
--with-libxml-dir=/usr/lib64 \
--with-mcrypt=/usr/lib64 \
--with-mysql \
--with-gd \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--enable-calendar
[#19] ben at bluehype dot com dot au [2009-01-26 16:07:06]
If you have already compiled php without jpeg support and decide you want it , then before you compile again you might need to run "make clean" first.
[#20] msc at homofaber dot com [2008-10-30 07:45:43]
It should be noted that it might be pretty easy to install gd without the need to recompile php, when using debian:
apt-get install php5-gd
[#21] gerard at charlesconsulting dot com [2008-08-21 09:36:20]
On my system,I had to ensure I had not only libpng and libjpeg, but also the libpng-devel and libjpeg-devel packages installed.
[#22] kronn [2008-07-17 14:44:45]
Everytime I try to install the gd-lib as a dynamic extension, I run into the same problem: It wont work.
I get the following error:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/pkg/lib/php/20040412/gd.so' - dlopen(/usr/pkg/lib/php/20040412/gd.so, 9): Symbol not found: __cg_jpeg_resync_to_restart\n Referenced from: /System/Library/Frameworks/ApplicationServices. framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/ImageIO\n Expected in: /usr/pkg/lib/libjpeg.62.dylib\n in Unknown on line 0
I use pkgsrc for software package managment on my mac, as may be apparent from the paths.
The solution is, to edit the file /usr/pkg/sbin/envvars and remove or comment the DYLD_LIBRARY_PATH because it is causing the error...
[#23] mike at clove dot com [2008-04-18 09:40:07]
jpeg [jpg] file processing doesn't work unless you build php with '--with-jpeg-dir=<path to jpeg library>'.
It still doesn't work unless <path to jpeg library> points to the directory holding the directory holding the library unless libjpeg.<whatever> is in either /usr/lib or /usr/local/lib. For instance, on a mac with libjpeg.a installed via mac ports, you need '/opt/local' rather than '/opt/local/lib'