PHP---GD库

基本画图步骤:

<?php
//1、创建画布
$img=imagecreatetruecolor(300, 200);
//2、创建颜色
$bcak=imagecolorallocate($img, 0, 255, 0);
//3、填充画布
imagefill($img, 0, 0, $bcak);
//4、输出最终图像或保存最终图像
header('content-type:image/jpeg');
imagejpeg($img,);//输出图像
imagejpeg($img,'jin.jpg'); //保存图像
//5、释放画布资源
imagedestroy($img);
 ?>

绘制图像的方法:

绘制图像的方法:
绘制一个像素点:imagesetpixel(image, x, y, color)
绘制一条线:imageline(image, x1, y1, x2, y2, color);
绘制一个矩形:imagerectangle(image, x1, y1, x2, y2, color);
绘制一个矩形并填充:imagefilledrectangle(image, x1, y1, x2, y2, color);

绘制一个多边形:imagepolygon(image, points, num_points, color)
绘制一个多边形并填充:imagefilledpolygon(image, points, num_points, color)

绘制一个椭圆:imageellipse(image, cx, cy, width, height, color)
绘制一个椭圆并填充:imagefilledellipse(image, cx, cy, width, height, color)

绘制一个椭圆弧,并填充:imagefilledarc(image, cx, cy, width, height, start, end, color, style)
 

水平地画一行字符串:imagestring(image, font, x, y, string, color)
垂直地画一行字符串:imagestringup(image, font, x, y, string, color)

水平地画一个字符:imagechar(image, font, x, y, c, color)
垂直地画一个字符:imagecharup(image, font, x, y, c, color)

用truetype字符向图像画一个字符串:imagettftext(image, size, angle(角度), x, y, color, fontfile, text)

图片裁切和缩放

<?PHP
$img1=imagecreatefromjpeg(filename);
$img2=imagecreatetruecolor(150, 100);
imagecopyresampled(dst_image, src_image, dst_x, dst_y, src_x, src_y, dst_w, dst_h, )

dst_image:目标图片
src_image:原图片

dst_x、dst_y:

src_x, src_y:

dst_w, dst_h:

src_w, src_h:
?>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容