php gd库
手册网址:http://php.net/manual/zh/ref.image.php
gd 画图:
1:创建一个画布;
$image=resource imagecreatetruecolor ( int $x_size , int $y_size );
2:创建原料;
$color=int imagecolorallocate ( resource $image , int $red , int $green , int $blue );
3:画图;
bool imagefill ( resource $image , int $x , int $y , int $color );
4:保存;
bool imagepng ( resource $image [, string $filename ] );
bool imagegif ( resource $image [, string $filename ] );
5:销毁画布;
bool imagedestroy ( resource $image );
画图流程详解:
1)坐标系的讲解:【4个参数】
两个点确定一个矩形
左上角的点+宽度+高度
第一步:创建画布:
1)可以直接用imagecreatetruecolor 创建画布
2)也可以直接打开一幅图片做画布
imagecreatefromjpeg('文件');
第二步:配置颜色:
$red=imagecolorallocate($im,255,0,0);
$blue=imagecolorallocate($im,0,0,255);
/*画线*/
bool imageline ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color )
image
第三步:保存图片
1)imagegif imagejpeg
2)也可以是图片不保存而直接输出【在验证码里比较实用】
此时会输出到浏览器,但是我们必须要告诉浏览器是什么格式的:
header('Content-type: image/png');
bool imagepng ( resource $image [, string $filename ] );第二个参数不需要
浙公网安备 33010602011771号