欢迎光临
感谢一路有你

PHPGD库

如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
 

思路

  1. 建立画布
  2. 设置颜色
  3. 设置背景
  4. 作画(重要)
  5. 保存输出
  6. 移除画布

建立画布

只需设置宽和高

$img = imagecreatetruecolor(500,500);

设置颜色

imagecolorallocate(画布资源,R,G,B)

$white = imagecolorallocate($img,255,255,255);
$black = imagecolorallocate($img,0,0,0);
$red = imagecolorallocate($img,255,0,0);
$blue = imagecolorallocate($img,0,0,255);
$green = imagecolorallocate($img,0,255,0);

填充背景

imagefill(画布资源,0,0,填充的颜色);

imagefill($img,0,0,$black);

作图

  1. 画点(imagesetpixel)
imagesetpixel(画布资源,坐标x,坐标y,颜色);

imagesetpixel($img,255,255,$white);
  1. 划线(imageline)
imageline(画布资源,起点x,起点y,终点x,终点y,颜色);

imageline($img,100,100,200,200,$white);
  1. 画矩形(imagerectangle)
imagerectangle(画布资源,起点x,起点y,终点x,终点y,颜色);
imagefilledrectangle(画布资源,起点x,起点y,终点x,终点y,颜色);//填充(filled)

imagerectangle($img,100,100,400,400,$white);
imagefilledrectangle($img,100,100,400,400,$white);
  1. 画多边形(imagepolygon)
imagepolygon($img,array(各坐标),几边形,颜色);
imagefilledpolygon($img,array(各坐标),几边形,颜色);//填充

imagepolygon($img,array(100,100,100,400,400,400),3,$white);
imagefilledpolygon($img,array(100,100,100,400,400,400),3,$white);
  1. 画圆(imageellipse)
imageellipse(画布资源,圆心x,圆心y,x长,y长,颜色);
imagefilledellipse(画布资源,圆心x,圆心y,x长,y长,颜色);//填充

imageellipse($img,250,250,400,300,$white);
imagefilledellipse($img,250,250,400,300,$white);
  1. 画弧线

  2. 文本(imagettftext)

imagettftext(画布资源,大小,弧度,开始x,开始y,颜色,字体,文本);

imagettftext($img,30,45,100,200,$white,'./font/1.ttf','hahahhahaha');

保存

image/png image/gif image/jpeg

header("content-type:image/jpeg");
imagejpeg($img);

销毁

imagedestroy($img);

赞(1) 打赏
未经允许不得转载:王明昌博客 » PHPGD库
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏