PHP---GD库

2018-08-18  本文已影响0人  大菜鸟呀

基本画图步骤:

<?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:
?>
上一篇 下一篇

猜你喜欢

热点阅读