前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PHP GD库

PHP GD库

作者头像
Yiiven
发布2022-12-15 11:55:14
2.1K0
发布2022-12-15 11:55:14
举报
文章被收录于专栏:怡文菌怡文菌

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
复制
//创建画布
$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 条评论
热度
最新
推荐阅读
相关产品与服务
图片处理
图片处理(Image Processing,IP)是由腾讯云数据万象提供的丰富的图片处理服务,广泛应用于腾讯内部各产品。支持对腾讯云对象存储 COS 或第三方源的图片进行处理,提供基础处理能力(图片裁剪、转格式、缩放、打水印等)、图片瘦身能力(Guetzli 压缩、AVIF 转码压缩)、盲水印版权保护能力,同时支持先进的图像 AI 功能(图像增强、图像标签、图像评分、图像修复、商品抠图等),满足多种业务场景下的图片处理需求。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档