首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >PHP GD库

PHP GD库

作者头像
Yiiven
发布2022-12-15 11:55:14
发布2022-12-15 11:55:14
2.5K00
代码可运行
举报
文章被收录于专栏:怡文菌怡文菌
运行总次数:0
代码可运行

GD库 图片处理的典型流程

1:造画布(或读入一幅图作画布)

2:造颜料

3:利用颜料在画布上写字或填充颜色或画形状

4:输出/生成图片

5:销毁画布

1、GD库 之生成验证码

创建画布(imagecreatetruecolor)

往图片写字(imagestring)

形成图片(imagejpeg|png|gif)

销毁画布(imagedestroy)

2、GD库 之生成缩略图

读取图片,形成资源(imagecreatefrom***)

创建缩略画布(imagecreatetruecolor)

复制图片资源(imagecopyresampled)

形成图片(imagejpeg|png|gif)

销毁画布(imagedestroy)

3、GD库 之加水印

读取大图,形成资源(imagecreatefrom***)

读取水印图片,(同上) 复制图片资源(imagecopymerge)

形成图片(imagejpeg|png|gif)

销毁画布(imagedestroy)

代码语言:javascript
代码运行次数:0
运行
复制
//创建画布
$im = imagecreatetruecolor(200, 100);
//颜料
$bg = imagecolorallocate($im , 100, 100, 100);
//填充图片
imagefill($im, 0, 0, $bg);
//生成图片
imagepng($im, './first.png')

//-------------------------------------------------------
//创建x像素宽,y像素高的图片资源
resource imagecreatetruecolor ( int $x_size , int $y_size )
//通过读取一幅gif图片作为图片资源
resource imagecreatefromgif ( string $filename )
//通过读取一幅jpg图片作为图片资源
resource imagecreatefromjpeg ( string $filename )
//通过读取一幅png图片作为图片资源
resource imagecreatefrompng ( string $filename )
//创建一个颜色
int imagecolorallocate ( resource $image , int $red , int $green , int $blue )
//获得图像宽度(像素)
int imagesx ( resource $image )
//获得图像高度(像素)
int imagesy ( resource $image ) 
//往图片上写一串字符(无法换行)
bool imagestring ( resource $image , int $font , int $x , int $y , string $s , int $col )
//往图片上写一个字符
bool imagechar( resource $image , int $font , int $x , int $y , string $c , int $color )
//往图片片竖着写一个字符
bool imagecharup( resource $image , int $font , int $x , int $y , string $c , int $color )

//-----
imageline //画一条线段
imagerectangle //画矩形
imageellipse //画一个椭圆
imagefilledrectangle //画一矩形并填充
imagefilledellipse //画一椭圆并填充
imagefilledarc //画一椭圆弧且填充
imagefilledpolygon //画一多边形并填充
imagefill //区域填充

//---
//保存透明通道
imagesavealpha(resource $dst_image, true)
//复制图片某一部分到另外一图片上去
imagecopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h )
//同上,但多了"透明"选项
imagecopymerge ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h , int $pct )
//拷贝部分图像并调整大小
imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
//TrueType 字体向图像写入文本
imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )
//销毁图像资源
bool imagedestroy ( resource $image )

本文采用 「CC BY-NC-SA 4.0」创作共享协议,转载请标注以下信息:

原文出处:Yiiven https://cloud.tencent.com/developer/article/2193090

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-09-14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档