-
2022-01-17 10:25:30
Linux gd库安装步骤说明
gd 库是 PHP 处理图形的扩展库,它提供了一系列用来处理图片的 API(应用程序编程接口),使用 gd 库可以处理图片或者生成图片。在网站上,gd 库通常用来生成缩略图,或者对图片加水印,或者生成汉字验证码,或者对网站数据生成报表等。
gd库安装步骤如下。
1) 建立 gd 库安装目录,进入 gd 库解压缩目录
[root@localhost autoconf-2.61]# cd /usr/local/src/gd-2.0.35
2) 修改gd_png.c文件
[root@localhost gd-2.0.35]# vi gd_png.c #把文件中 include "png.h"改为 include "/usr/local/libpng/include/png.h"
如果不修改 gd_png.c 文件,则默认会在当前目录下搜索 png.h 文件。我们已知 libpng 安装在 /usr/local/libpng/ 目录中,所以当然不能找到,就会报错。把 png.h 的正确路径“/usr/local/libpng/include/png.h”写入,报错就能解决。
3) 编译安装
[root@localhost gd-2.0.35]# ./configure \ --prefix=/usr/local/gd2/ \ #指定安装位置 --with-jpeg=/usr/local/jpeg6/ \ #指定jpeg6的位置 --with-freetype=/usr/local/freetype/ \ #指定freetype的位置 --with-png=/usr/local/libpng/ #指定libpng的位置 #编译前配置 #因为gd库需要调用前面安装的zlib、jpeg、freetype和libpng,所以需要指定它们的安装位置,才能正确调用这些软件。不过因为前面安装zlib时没有指定安装位置,所以不用指定——with-zlib=/usr/local/zlib/选项,gd会自动到默认安装位置中寻找zlib [root@localhost gd-2.0.35]# make #编译 [root@localhost gd-2.0.35]# make install #编译安装
更多相关内容 -
Gd.php GD库文件免费下载
2019-12-18 10:55:18GD库配置文件 免费分享 -
Centos7下PHP安装gd库的实例讲解
2021-01-10 10:11:08Centos7下安装php, 或php的gd库支持,都是很简单的。 一切通过yum搞定。 yum install php-gd 以上命令就搞定php-gd的支持,快快看看phpinfo是否支持了? 可是,如果需要采用不同版本的php时,那就是相当的麻烦,... -
PHP GD库添加freetype拓展的方法
2020-12-18 05:42:58背景:业务需求要用到 imagefttext 函数,发现GD库一开始安装时没有添加 FreeType linux版本 centos 6.6 安装流程(由于服务器为分布式内网服务器,无法使用yum安装,以下均为下载资源包后的编译安装): 安装... -
PHP使用GD库输出汉字的方法【测试可用】
2021-01-20 01:10:10本文实例讲述了PHP使用GD库输出汉字的方法。分享给大家供大家参考,具体如下: 一、原理 PHP中的GD库支持中文,但是必须要以UTF-8格式的参数来进行传递。下面先说一下汉字的UTF-8编码的求得。 1. 用WORD2000或WINDOW... -
PHP下使用GD库将图形中白色部分变为透明(不用imagecolortransparent)
2021-08-25 13:27:40在PHP下使用GD库将图形中白色部分变为透明,由于使用imagecolortransparent不明原因的转换失败,便改变思路为:新建同尺寸透明图,然后遍历原图,在透明图上再填颜色,脚本内容亲测可用。 -
php的GD库imagettftext函数解决中文乱码问题
2020-12-19 10:40:08本文实例讲述了php的GD库imagettftext函数解决中文乱码问题的方法。分享给大家供大家参考。具体如下: 使用imagettftext写中文时,常出现乱码问题。解决方法是将中文字符串转为utf-8格式即可。具体代码如下(文件... -
PHP安装gd库依赖包
2018-05-27 20:28:34包含: freetype-2.4.0.tar.bz2, jpegsrc.v9.tar.gz, zlib-1.2.8.tar.gz, libpng-1.6.16.tar.gz, ...安装PHP的gd扩展依赖库之一,安装步骤参考: https://blog.csdn.net/u014740338/article/details/80471655 -
PHP 技巧 * GD 库生成表格图片演示
2021-01-08 14:46:07一、数据准备 下载字体; 二、示例代码: ... [id => 1, username => 给你最好的我丶, score => 92], [id => 2, username => 抬首轻笑, score => 95], [id => 3, username => 嘉恒帅比等你王者归来, score => 74] ... -
php利用gd库为图片添加水印
2020-12-19 01:41:41本文实例为大家分享了php利用gd库为图片添加水印的方法,供大家参考,具体内容如下 <?php $dst_path = '1.jpg';//目标图片 $src_path = 'logo1.png';//水印图片 //创建图片的实例 $dst = imagecreatefromstring... -
PHP GD库生成图像的几个函数总结
2020-12-19 13:00:30使用GD库中提供的函数动态绘制完成图像以后,就需要输出到浏览器或者将图像保存起来。在PHP中,可以将动态绘制完成的画布,直接生成GIF、JPEG、PNG和WBMP四种图像格式。可以通过调用下面四个函数生成这些格式的图像... -
PHP使用GD库制作验证码的方法(点击验证码或看不清会刷新验证码)
2020-12-20 04:02:59这是利用GD库生成验证码的页面 test.PHP <?php header('Content-Type:image/jpeg'); $img = imagecreatetruecolor(100, 40); $black = imagecolorallocate($img, 0x00, 0x00, 0x00); $green = ... -
PHP通过GD库实现验证码功能示例
2021-01-02 21:10:08本文实例讲述了PHP通过GD库实现验证码功能。分享给大家供大家参考,具体如下: 首先看看实现的效果: 具体实现: <?php /*PHP实现验证码*/ session_start();//开启会话 //创建画布 $image=imagecreatetruecolor... -
如何打开php的gd2库
2020-12-19 09:16:03第二步:用记事本打开该文件,并按 “ctrl+F” 输入 “extension=php_gd2.dll” 回车即可。(见图一) 第三步:去掉句首分号(图二) 我使用的php版本:5.6.19 您可能感兴趣的文章:PHP图像处理技术实例总结【绘图... -
php利用GD库生成缩略图示例
2020-12-15 04:36:30php利用GD库生成缩略图。 代码如下: <form method=”post” action=”suo_do.php” enctype=”multipart/form-data”> <input type=”file” name=”pic” /> <input type=”submit” value=”上传1... -
在windows服务器开启php的gd库phpinfo中未发现
2020-12-18 13:40:24在windows服务器开启php的gd库时,使用cgi之后phpinfo()得到的结果中 Configure Command 中并没有出现gd. Configure Command 后显示的是: 复制代码 代码如下: 1 cscript /nologo configure.js “–enable-snapshot-... -
phpgd库图片合成跟添加文字
2019-01-11 15:36:51自己把图片路径改了跟下载字体文件,封装了一个curl直接用,自己也是学习阶段 -
php中使用gd库实现下载网页中所有图片
2020-10-24 06:14:43主要介绍了php中使用gd库实现下载网页中所有图片,本文直接给出实现代码,需要的朋友可以参考下 -
php扩展gd库详解
2021-05-23 16:32:15php扩展gd库详解,常码字不易,出精品更难,没有特别幸运,那么请先特别努力,别因为懒惰而失败,还矫情地将原因归于自己倒霉。你必须特别努力,才能显得毫不费力。如果这篇文章能给你带来一点帮助,希望给飞兔小...〝 古人学问遗无力,少壮功夫老始成 〞
php扩展gd库详解,常码字不易,出精品更难,没有特别幸运,那么请先特别努力,别因为懒惰而失败,还矫情地将原因归于自己倒霉。你必须特别努力,才能显得毫不费力。如果这篇文章能给你带来一点帮助,希望给飞兔小哥哥一键三连,表示支持,谢谢各位小伙伴们。
目录
一、创建画布
-
三种方式,创建普通的画布、真彩画布、把图片当做背景画布
<?php //创建普通画布 $gd = imagecreate(画布宽度, 画布高度); //创建真彩画布,失真少 $gd = imagecreatetruecolor(画布宽度, 画布高度); //将图片作为画布 $gd = imagecreatefromjpeg('图片路径');
二、给画布填充颜色
-
分配颜色:imagecolorallocate( 画布资源, 三原色之red, 三原色之green, 三原色之blue )
-
填充画布:imagefill( 画布资源, 填充初始x轴, 填充初始y轴, 填充颜色 )
<?php //创建画布 $gd = imagecreatetruecolor(1000, 700); //分配颜色 $gray = imagecolorallocate($gd, 255, 255, 255); //给画布填充颜色 imagefill($gd, 0, 0, $gray); //显示画布 header('Content-type:image/png'); imagepng($gd);
三、画布上绘制直线
-
绘制直线:imageline( 画布资源, 开始点的x轴, 开始点的y轴, 结束点的x轴, 结束点的y轴, 颜色 )
<?php //分配直线的颜色 $purple = imagecolorallocate($gd, 255, 0, 244); //画直线 imageline($gd, 100, 100, 600, 600, $purple);
四、绘制矩形
-
绘制矩形:imagerectangle( 画布资源, 开始点的x轴, 开始点的y轴, 结束点的x轴, 结束点的y轴, 颜色 )
<?php //给矩形分配颜色 $pink = imagecolorallocate($gd, 255, 200, 200); //绘制矩形 imagerectangle( $gd, 200, 200, 500, 500, $pink);
五、绘制圆弧
-
绘制圆弧:imagearc( 画布资源, 圆心点x轴, 圆心点y轴, 长轴长, 短轴长, 角度初始位, 角度结束位, 颜色 )
<?php //给圆弧分配颜色 $black = imagecolorallocate($gd, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); //绘制圆弧 imagearc($gd, mt_rand(0, 360), mt_rand(0, 360), 200, 150, 0, mt_rand(0, 360), $black);
六、绘制文字
-
绘制文字:imagestring( 画布资源, 字体大小, 开始绘制的x轴, 开始绘制的y轴, 绘制的字符, 颜色 )
<?php //给文字分配颜色 $red = imagecolorallocate($gd, 255, 0, 0); //绘制文字 imagestring( $gd, 20, 100, 200, "hello world", $red);
-
该 imagestring 方法不支持绘制中文,如果想使用中文,请使用TTF字符绘制
七、绘制TTF字符
-
绘制ttf: imagettftext( 画布资源, 字体大小, 角度, 位置x, 位置y, 颜色, 字体路径, 绘制的字符 )
<?php //给ttf文字分配颜色 $blue = imagecolorallocate($gd, 0, 0, 255); //绘制ttf字符 imagettftext($gd, 20, 15, 700, 300, $blue, './font/bootstrap.ttf', "ttf");
八、增加噪点
-
绘制噪点:imagesetpixel( 画布资源, 噪点位置x轴, 噪点位置y轴, 噪点颜色 )
<?php //随机分配噪点颜色 $color = imagecolorallocate($gd, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); //绘制噪点 imagesetpixel($gd, mt_rand(0, 1000), mt_rand(0, 700), $color);
九、输出图片和保存图片
<?php //输出图片 imagepng($gd); //保存图片 imagejpeg($gd, 保存路径, 保存质量);
十、销毁画布
<?php //销毁画布 imagedestroy($gd);
十一、验证码实战
<?php /** * Created by PhpStorm. * User: autofelix * Date: 2021/5/23 * Time: 17:20 * Desc: gd验证码类封装. */ class Captcha { /** * @var array */ private $disposition = []; /** * @var resource */ private $gd; /** * Captcha constructor. * @param array $_config */ public function __construct($_config = []) { $this->disposition = [ 'num' => isset($_config['num']) ? $_config['num'] : 4, //验证码数字 'width' => isset($_config['width']) ? $_config['width'] : 200, //验证码宽度 'height' => isset($_config['height']) ? $_config['height'] : 100, //验证码高度 'font' => isset($_config['font']) ? $_config['font'] : 5, //验证码字体大小 'arcNum' => isset($_config['arcNum']) ? $_config['arcNum'] : 1, //圆弧数 'lineNum' => isset($_config['lineNum']) ? $_config['lineNum'] : 3, //直线数 'pixelNum' => isset($_config['pixelNum']) ? $_config['pixelNum'] : 1000, //噪点数 'rectangleNum' => isset($_config['rectangleNum']) ? $_config['rectangleNum'] : 0, //矩形数 ]; $this->gd = imagecreatetruecolor($this->disposition['width'], $this->disposition['height']); $color = imagecolorallocate($this->gd, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagefill($this->gd, 0, 0, $color); } /** * 程序入口 */ public function run() { header('Content-type:image/png'); for ($i=0; $i<$this->disposition['arcNum']; $i++) { $this->createArc(); } for ($i=0; $i<$this->disposition['lineNum']; $i++) { $this->createLine(); } for ($i=0; $i<$this->disposition['pixelNum']; $i++) { $this->createPixel(); } for ($i=0; $i<$this->disposition['rectangleNum']; $i++) { $this->createRectangle(); } $this->createStr(); imagepng($this->gd); } /** * 绘制验证码 */ private function createStr() { $code = $this->createCode(); $x = mt_rand(0, $this->disposition['width']); $y = mt_rand(0, $this->disposition['height']); $x = $x > $this->disposition['width'] * 4 / 5 ? $x - $this->disposition['width'] / 5 : $x; $y = $y > $this->disposition['height'] * 4 / 5 ? $y - $this->disposition['height'] / 5 : $y; $color = imagecolorallocate($this->gd, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagestring ($this->gd, $this->disposition['font'], $x, $y, $code, $color); } /** * 绘制直线 */ private function createLine() { $x1 = mt_rand(0, $this->disposition['width']); $y1 = mt_rand(0, $this->disposition['height']); $x2 = mt_rand(0, $this->disposition['width']); $y2 = mt_rand(0, $this->disposition['height']); $color = imagecolorallocate($this->gd, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imageline($this->gd, $x1, $y1, $x2, $y2, $color); } /** * 绘制矩形 */ private function createRectangle() { $x1 = mt_rand(0, $this->disposition['width']); $y1 = mt_rand(0, $this->disposition['height']); $x2 = mt_rand(0, $this->disposition['width']); $y2 = mt_rand(0, $this->disposition['height']); $color = imagecolorallocate($this->gd, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagerectangle ($this->gd, $x1, $y1, $x2, $y2, $color); } /** * 绘制圆弧 */ private function createArc() { $x = mt_rand(0, $this->disposition['width']); $y = mt_rand(0, $this->disposition['height']); $width = mt_rand(0, 200); $height = mt_rand(0, 150); $start = mt_rand(0, 360); $end = mt_rand(0, 360); $color = imagecolorallocate($this->gd, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagearc ($this->gd, $x, $y, $width, $height, $start, $end, $color); } /** * 增加噪点 */ private function createPixel() { $x = mt_rand(0, $this->disposition['width']); $y = mt_rand(0, $this->disposition['height']); $color = imagecolorallocate($this->gd, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagesetpixel ($this->gd, $x, $y, $color); } /** * 随机验证码 * @return string */ private function createCode() { $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $str = ""; for ($i = 0; $i < $this->disposition['num']; $i++) { $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); } return $str; } /** * 销毁画布 */ public function __destruct() { imagedestroy($this->gd); } } (new Captcha([ 'num' => 4, //验证码数字 'width' => 100, //验证码宽度 'height' => 80, //验证码高度 'font' => 5, //验证码字体大小 'arcNum' => 2, //圆弧数 'lineNum' => 3, //直线数 'pixelNum' => 200, //噪点数 'rectangleNum' => 1, //矩形数 ]))->run();
-
-
PHP用GD库生成高质量的缩略图片
2021-01-20 00:20:07以下是PHP源代码(ResizeImage.php)。 复制代码 代码如下: <?php $FILENAME=”image.thumb”; // 生成图片的宽度 $RESIZEWIDTH=400; // 生成图片的高度 $RESIZEHEIGHT=400; function ResizeImage($im,$maxwidth,$... -
php开启GD库实现方法
2021-03-23 08:08:40GD库在php中默认是没有开启的,如果想让它支持图片处理功能我们需要在php.ini中把extension=php_gd2.dll 去掉前面的;就行了就行了。在windows服务器开启php的gd库时,使用cgi之后phpinfo()得到的结果中 Configure ...GD库在php中默认是没有开启的,如果想让它支持图片处理功能我们需要在php.ini中把extension=php_gd2.dll 去掉前面的;就行了就行了。
在windows服务器开启php的gd库时,使用cgi之后phpinfo()得到的结果中 Configure Command 中并没有出现gd.
将php.ini文件找到extension=php_gd2.dll 去掉前面的;就行了。
另外附上如何检测是否已经安装好GD库代码!
代码如下
复制代码
结果显示为:你可以使用gd
GD Version: bundled (2.0.34 compatible)
FreeType Support: 1
FreeType Linkage: with freetype
T1Lib Support: 1
GIF Read Support: 1
GIF Create Support: 1
JPG Support: 1
PNG Support: 1
WBMP Support: 1
XPM Support:
XBM Support: 1
JIS-mapped Japanese Font Support:
如果有问题,
Configure Command 后显示的是:
1 cscript /nologo configure.js "--enable-snapshot-build" "--disable-isapi" "--enable-debug-pack" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=C:php-sdkoracleinstantclient10sdk,shared" "--with-oci8=C:php-sdkoracleinstantclient10sdk,shared" "--with-oci8-11g=C:php-sdkoracleinstantclient11sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--disable-static-analyze" "--with-pgo"
可能的原因:
1.权限问题;
2.双通道是否存在问题,或者是硬件是否松动
-
解决Mac OS X 自带PHP环境gd库扩展缺少freetype的问题
2020-10-18 15:32:58下面小编就为大家分享一篇解决Mac OS X 自带PHP环境gd库扩展缺少freetype的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧 -
GD字体产生器 php gd库大家都知道把
2019-12-29 19:30:22GD字体产生器 php gd库大家都知道把,抓紧下载使用。让gd产生的字变好看。选择字体后就可以变化了。 -
php中使用GD库做验证码
2020-10-22 14:45:28本文给大家分享的是使用php的GD库来实现验证码功能的方法和全部代码,有需要的小伙伴可以参考下 -
PHP GD库相关图像生成和处理函数小结
2020-10-21 09:57:42主要介绍了PHP GD库相关图像生成和处理函数,分类总结并分析了php GD库相关图像处理函数的功能与用法,需要的朋友可以参考下 -
php实现的支持imagemagick及gd库两种处理的缩略图生成类
2020-10-25 10:12:05主要介绍了php实现的支持imagemagick及gd库两种处理的缩略图生成类,包含了用法的详细描述,非常实用,需要的朋友可以参考下