PHP GD库
2023-02-18 16:29:49 时间
GD库 图片处理的典型流程
1:造画布(或读入一幅图作画布)
2:造颜料
3:利用颜料在画布上写字或填充颜色或画形状
4:输出/生成图片
5:销毁画布
1、GD库 之生成验证码
创建画布(imagecreatetruecolor)
往图片写字(imagestring)
形成图片(image[jpeg|png|gif])
销毁画布(imagedestroy)
2、GD库 之生成缩略图
读取图片,形成资源(imagecreatefrom***)
创建缩略画布(imagecreatetruecolor)
复制图片资源(imagecopyresampled)
形成图片(image[jpeg|png|gif])
销毁画布(imagedestroy)
3、GD库 之加水印
读取大图,形成资源(imagecreatefrom***)
读取水印图片,(同上) 复制图片资源(imagecopymerge)
形成图片(image[jpeg|png|gif])
销毁画布(imagedestroy)
//创建画布
$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://www.yiiven.cn/php-gd.html
相关文章
- 2022-12-29:nsq是go语言写的消息队列。请问k3s部署nsq,yaml如何写?
- 不背锅运维:上篇:Go并发编程
- CVE-2022-2639:Linux Kernel openvswitch提权漏洞
- linux shell脚本sh和source区别
- 专注效率提升「GitHub 热点速览 v.22.36」
- Git + Jenkins 自动化 NGINX 发布简易实现
- Caddy-用Go写的新一代可扩展WebServer
- 将git仓库从submodule转换为subtree
- 容器开发运维人员的 Linux 操作机配置优化建议
- 《前端运维》一、Linux基础--12网络
- 《前端运维》一、Linux基础--11服务
- 《前端运维》一、Linux基础--10定时任务
- 《前端运维》一、Linux基础--08Shell其他及补充
- 《前端运维》一、Linux基础--09常用软件安装
- 《前端运维》一、Linux基础--07Shell函数
- 《前端运维》一、Linux基础--06Shell流程控制
- 《前端运维》一、Linux基础--05Shell运算符
- 在Visual Studio 中使用git系列文章目录
- 《前端运维》一、Linux基础--04Shell变量
- 《前端运维》一、Linux基础--03Shell基础及补充