❶ 怎样开启php的gd库
Windows下开启PHP的GD库支持
找到php.ini,打开内容,找到:
;extension=php_gd2.dll
把最前面的分号“;”去掉,再保存即可,如果本来就没有分号,那就是已经开启了。
linux下开启PHP的GD库支持
#开启GD库支持有以下几种方法
##检测GD库是否安装命令
php5 -m | grep -i gd
或者
php -i | grep -i --color gd
##如未安装GD库,则为服务器安装,方法如下
### 如果是源码安装,则加入参数
--with-gd
### 如果是debian系的linux系统,用apt-get安装,如下
apt-get install php5-gd
### 如果是CentOS系的系统,用yum安装,如下
yum install php-gd
### 如果是suse系的linux系统,用yast安装,如下
yast -i php5_gd
### 如果嫌这个世界不够蛋疼呢,可以在原先编译PHP不支持GD的情况下附加
先下zlib源码,libpng源码,gd源码
解压后到源码目录
zlib目录
./configure --prefix=/usr/local/zlib
make ; make install
make clean
libpng目录
cp scripts/makefile.linux ./makefile
./configure --prefix=/usr/local/libpng
make ; make install
make clean
gd目录
./configure --prefix=/usr/local/libgd --with-png=/usr/local/libpng
make ; make install
make clean
最后在php.ini中,搜到[gd]后,在下面加一行
extension=/usr/local/libgdgd.so
然后重启php服务,如果不行,试试reboot
好了,不过最后提醒一下,要知道这个世界很多意外的,源码安装,只添加gd库这一个情况下,PHP版本和库的版本各异
,所以:
- 不保证这么付出了这么多后有回报
- 不保证能够成功加载gd.so
- 不保证不怀孕
所以如果是源码安装,最好还是在编译PHP的时候加参数--with-gd
GD库函数
GetImageSize
作用:取得图片的大小[即长与宽] 用法:array GetImageSize(string filename, array [imageinfo]);
ImageArc
作用:画弧线 用法:int ImageArc(int im, int cx, int cy, int w, int h, int s, int e, int col);
ImageChar
作用:写出横向字符 用法:int ImageChar(int im, int font, int x, int y, string c, int col);
ImageCharUp
作用:写出竖式字符 用法:int ImageCharup(int im, int font, int x, int y, string c, int col);
ImageColorAllocate
作用:匹配颜色 用法:int ImageColorAllocate(int im, int red, int green, int blue);
ImageColorTransparent
作用:指定透明背景色 用法:int ImageColorTransparent(int im, int [col]);
ImageCopyResized
作用:复制新图并调整大小 用法:int ImageCopyResized(int dst_im, int src_im, int dstX, int dstY, int srcX,
int srcY, int dstW, int dstH, int srcW, int srcH);
ImageCreate
作用:建立新图 用法:int ImageCreate(int x_size, int y_size);
ImageDashedLine
作用:绘虚线 用法:int ImageDashedLine(int im, int x1, int y1, int x2, int y2, int col);
ImageDestroy 作用:结束图形 用法解释:int ImageDestroy(int im);
ImageFill
作用:图形着色 用法:int ImageFill(int im, int x, int y, int col);
ImageFilledPolygon作用:多边形区域着色 用法:int ImageFilledPolygon(int im, array points, int num_points,
int col);
ImageFilledRectangle作用:矩形区域着色 用法:int ImageFilledRectangle(int im, int x1, int y1, int x2, int
y2, int col);
ImageFillToBorder作用:指定颜色区域内着色 用法:int ImageFillToBorder(int im, int x, int y, int border,
int col);
ImageFontHeight
作用:取得字型的高度 用法:int ImageFontHeight(int font);
ImageFontWidth作用:取得字型的宽度 用法:int ImageFontWidth(int font);
ImageInterlace作用:使用交错式显示与否 用法:int ImageInterlace(int im, int [interlace]);
ImageLine作用:绘实线 用法:int ImageLine(int im, int x1, int y1, int x2, int y2, int col);
ImageLoadFont作用:载入点阵字型 用法:int ImageLoadFont(string file);
ImagePolygon作用:绘多边形 用法:int ImagePolygon(int im, array points, int num_points, int col);
ImageRectangle作用:绘矩形 用法:int ImageRectangle(int im, int x1, int y1, int x2, int y2, int col);
ImageSetPixel作用:绘点 用法:int ImageSetPixel(int im, int x, int y, int col); ImageString 作用:绘横式
字符串 用法:int ImageString(int im, int font, int x, int y, string s, int col);
ImageStringUp作用:绘直式字符串 用法:int ImageStringUp(int im, int font, int x, int y, string s, int
col);
ImageSX
作用:取得图片的宽度 用法:int ImageSX(int im);
ImageSY
作用:取得图片的高度 用法:int ImageSY(int im);
ImageTTFBBox
作用:计算 TTF 文字所占区域 用法:array ImageTTFBBox(int size, int angle, string fontfile, string text);
ImageTTFText作用:写 TTF 文字到图中 用法:array ImageTTFText(int im, int size, int angle, int x, int y,
int col, string fontfile, string text); ImageColorAt 作用:取得图中指定点颜色的索引值 用法:int
ImageColorAt(int im, int x, int y);
ImageColorClosest
作用:计算色表中与指定颜色最接近者 用法:int ImageColorClosest(int im, int red, int green, int blue);
ImageColorExact
作用:计算色表上指定颜色索引值 用法:int ImageColorExact(int im, int red, int green, int blue);
ImageColorResolve
作用:计算色表上指定或最接近颜色的索引值 用法:int ImageColorResolve(int im, int red, int green, int
blue);
ImageColorSet
作用:设定色表上指定索引的颜色 用法:boolean ImageColorSet(int im, int index, int red, int green, int
blue); ImageColorsForIndex 作用:取得色表上指定索引的颜色 用法:array ImageColorsForIndex(int im, int
index);
ImageColorsTotal
作用:计算图的颜色数 用法:int ImageColorsTotal(int im); ImagePSLoadFont 作用:载入 PostScript 字型 用法
:int ImagePSLoadFont(string filename);
ImagePSFreeFont
作用:卸下 PostScript 字型 用法:void ImagePSFreeFont(int fontindex);
ImagePSEncodeFont
作用:PostScript 字型转成向量字 用法:int ImagePSEncodeFont(string encodingfile);
ImagePSText作用:写 PostScript 文字到图中 用法:array ImagePSText(int image, string text, int font, int
size, int foreground, int background, int x, int y, int space, int tightness, float angle, int
antialias_steps);
ImagePSBBox作用:计算 PostScript 文字所占区域 用法: array ImagePSBBox(string text, int font, int size,
int space, int width, float angle);
ImageCreateFromPNG作用:取出 PNG 图型 用法:int ImageCreateFromPng(string filename);
ImagePNG作用:建立 PNG 图型 用法:int ImagePng(int im, string [filename]);
ImageCreateFromGIF作用:取出 GIF 图型 用法:int ImageCreateFromGif(string filename);
ImageGIF作用:建立 GIF 图型 用法:int ImageGif(int im, string [filename]);
❷ 为什么使用php GD库图片输出中文字会出现乱码
原因:
1、服务器编码原因。由于imagettftext函数字符串参数的默认编码是UTF8,如果服务器编码不一致,而又没有进行相应的字符编码格式转换,很容易出现使用gd库输出图片时中文字符变成乱码。
2、没有选择正确的TTF字体文件。使用gd库时如果要输出中文字符,需要选择正确的TTF字体文件。
解决方法:
根据之前介绍的php gd库产生中文乱码的原理,解决php gd库中文乱码的方法其实很简单。
1、建议整站使用UTF8编码,如果你已使用的是GB2312或GBK编码,请使用iconv或自定义的gb2312与utf8转换函数进行字符编码转换。gb2312与utf8转换函数请参考PHP Ajax传值中文字符乱码如何解决。
2、如果你是刚进行php环境搭建,建议将Apache配置文件中的默认字符集修改为UTF8,即AddDefaultCharset UTF8。
3、如果上述方法还不行,请检查你在编译gd库时是否添加了–enable-gd-jis-conv选项,此选项是为了让gd库支持日文编码的字库,请取消此选项并重新编译。此方法我没验证过,估计主要是针对Unix下安装配置php环境。Windows环境一般不会出现这种情况,似乎默认PHP配置文件是注释掉的。
4、使用php gd库产生中文乱码的另一个原因是没有选择正确的TTF字体,你需要选择支持中文的字体,常用的中文字体文件是simsun.ttc和simhei.ttf。
OK,只要按照上述方法,基本上使用php gd库产生中文乱码时都能够解决。只要仔细排查其实gd库的中文乱码解决起来非常方便。
❸ linux系统如何让php使用GD库函数
linux下为php添加GD库的步骤如下:
一、下载
gd-2.0.33.tar.gz http://www.boutell.com/gd/
jpegsrc.v6b.tar.gz http://www.ijg.org/
libpng-1.2.7.tar.tar http://sourceforge.net/projects/libpng/
zlib-1.2.2.tar.gz http://sourceforge.net/projects/zlib/
freetype-2.1.9.tar.gz http://sourceforge.net/projects/freetype/
php-4.3.9.tar.gz http://www.php.net
二、安装
1.安装zlib
tar zxvf zlib-1.2.2.tar.gz
cd zlib-1.2.2
./configure
make
make install
2.安装libpng
tar zxvf libpng-1.2.7.tar.tar
cd libpng-1.2.7
cd scripts/
mv makefile.linux ../makefile
cd ..
make
make install
注意,这里的makefile不是用./configure生成,而是直接从scripts/里拷一个
3.安装freetype
tar zxvf freetype-2.1.9.tar.gz
cd freetype-2.1.9
./configure
make
make install
4.安装Jpeg
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b/
./configure --enable-shared
make
make test
make install
注意,这里configure一定要带--enable-shared参数,不然,不会生成共享库
5.安装GD
tar zxvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure --with-png --with-freetype --with-jpeg
make install
6.重新编译PHP
tar zxvf php-4.3.9.tar.gz
cd php-4.3.9
./configure (以前的参数) --with-gd --enable-gd-native-ttf --with-zlib --with-png --with-jpeg --with-freetype --enable-sockets
make
make install
<?php
phpinfo();
?>
Ok.....
❹ php编译完成后,怎样把gd库追加编译进php
进入gd库源码目录目录,然后输入如下命令:
phpize
./configure --prefix=/usr/bin/php --with-php-config=/usr/bin/php/php-config
make
sudo make install
接着你就可以看到生成的so路径,大致如下:
/usr/lib/php5/20060613+lfs/gd.so
然后在php.ini文件里加上:
extension_dir=/usr/lib/php5/20060613+lfs
extension=/usr/lib/php5/20060613+lfs/gd.so
❺ 如何在PHP中开启GD库支持
Linux下开启PHP的GD库支持
#开启GD库支持有以下几种方法
##检测GD库是否安装命令
php5 -m | grep -i gd
或者
php -i | grep -i --color gd
##如未安装GD库,则为服务器安装,方法如下
### 如果是源码安装,则加入参数
--with-gd
### 如果是debian系的linux系统,用apt-get安装,如下
apt-get install php5-gd
### 如果是CentOS系的系统,用yum安装,如下
yum install php-gd
### 如果是suse系的linux系统,用yast安装,如下
yast -i php5_gd
### 如果嫌这个世界不够蛋疼呢,可以在原先编译PHP不支持GD的情况下附加
先下zlib源码,libpng源码,gd源码
解压后到源码目录
zlib目录
./configure --prefix=/usr/local/zlib
make ; make install
make clean
libpng目录
cp scripts/makefile.linux ./makefile
./configure --prefix=/usr/local/libpng
make ; make install
make clean
gd目录
./configure --prefix=/usr/local/libgd --with-png=/usr/local/libpng
make ; make install
make clean
最后在php.ini中,搜到[gd]后,在下面加一行
extension=/usr/local/libgdgd.so
然后重启php服务,如果不行,试试reboot
好了,不过最后提醒一下,要知道这个世界很多意外的,源码安装,只添加gd库这一个情况下,PHP版本和库的版本各异,所以:
- 不保证这么付出了这么多后有回报
- 不保证能够成功加载gd.so
- 不保证不怀孕
所以如果是源码安装,最好还是在编译PHP的时候加参数--with-gd
Windows下开启PHP的GD库支持
找到php.ini,打开内容,找到:
;extension=php_gd2.dll
把最前面的分号“;”去掉,再保存即可,如果本来就没有分号,那就是已经开启了。
##安装完毕后
**请查看,AKCMS后台/index.php?file=welcome&action=phpmoles或者PHP探针,GD库是否安装成功**
❻ 如何在PHP中开启GD库支持详解
GD库是干什么用的呢!它是php处理图形的扩展库,GD库提供了一系列用来处理图片的API,使用GD库可以处理图片,或者生成图片。
GD库在php中默认是没有开启的,如果想让它支持图片处理功能,那么就要手动开启GD库。
开发工具为wampserer,步骤如下:
找到php.ini文件,有两种方法:
方法一:wampserver安装目录下找到路径wampinmysqlmysql5.5.24php.ini(我安装的根目录是D盘)
❼ PHP GD库错误
提示错误大意是:JPgGragh提示你:你安装php时,没有同时配置和编译你的GD库,你需要重新编辑你的PHP,以获得对GD库的支持
同时你函数imagetypes()和imagecreatefromstring()不存在,这有可能是你php.ini没有打开GD库的支持
同时附上编译PHP(with gd)时需加的参数
PHP4-Server:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-config-file-path=/etc --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --enable-xml --enable-mbstring
PHP4-Max:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --mandir=/usr/share/man --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --with-openssl=/usr/local/openssl-0.9.7e --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-bz2 --with-inifile --with-hyperwave --enable-xml --enable-track-vars --enable-dba --enable-dbase --enable-filepro --enable-ftp --enable-versioning --enable-memory-limit --enable-calendar --enable-session --enable-sockets --enable-sysmsg --enable-sysvsem --enable-sysvshm --enable-tokenizer --enable-overload --enable-ctype --enable-sigchild --enable-magic-quotes --enable-roxen-zts --enable-fastcgi --enable-dbx --enable-dio --enable-shmop --enable-mbstring
PHP5-Server:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-zlib-dir --with-bz2 --with-tiff-dir --with-libxml-dir --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf --enable-mbstring --with-mysql=/usr/lib/mysql --with-config-file-path=/etc --disable-ipv6 --enable-gd-native-ttf
PHP5-Standard:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --mandir=/usr/share/man --with-openssl=/usr/local/openssl-0.9.7e --with-zlib --with-bz2 --with-tiff-dir --with-libxml-dir --enable-dio --enable-ftp --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-bz2-dir --with-ttf --enable-mbstring --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --disable-ipv6 --enable-gd-native-ttf
PHP5-Max:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --mandir=/usr/share/man --with-openssl=/usr/local/openssl-0.9.7e --with-zlib --with-bz2 --with-tiff-dir --with-libxml-dir --enable-dio --enable-ftp --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-bz2-dir --with-ttf --with-inifile --enable-dba --enable-dbase --enable-filepro --enable-versioning --enable-memory-limit --enable-calendar --enable-sockets --enable-sysvsem --enable-sigchild --enable-magic-quotes --enable-roxen-zts --enable-fastcgi --enable-dbx --enable-shmop --enable-mbstring --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --disable-ipv6 --enable-gd-native-ttf
❽ linux安装php环境编译gd文件的时候出现如下错误,configure: error
目前你的gd版本过低,请先升级你的gd
❾ 编译的GD库,无法启动,提示 php_gd_gdImageCreateFromXbm in Unknown on line 0
make clean之后重新编译安装
phpize
./configure --with-png-dir --with-freetype-dir --with-jpeg-dir --with-gd --with-xpm-dir --with-xbm-dir
make
make install
别忘记带“--with-png-dir --with-freetype-dir --with-jpeg-dir --with-gd --with-xpm-dir --with-xbm-dir”这些参数。