矩形和椭圆画法
// 画布
$im = imagecreatetruecolor(800,600);
// 颜料
$gray = imagecolorallocate($im,200,200,200);
$blue = imagecolorallocate($im,0,0,255);
$red = imagecolorallocate($im,255,0,0);
// 填充
imagefill($im,0,0,$gray);
// -------------------------------------
// 画一个矩形
/*
bool imagerectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $col )
参数:
画布资源
左上角x坐标
左上角y坐标
右下角x坐标
右下角y坐标
颜色
*/
imagerectangle($im,200,150,600,450,$blue);
// -------------------------------------
// -------------------------------------
// 画椭圆和圆
/*
bool imageellipse ( resource $image , int $cx , int $cy , int $width , int $height , int $color )
参数:
画布资源
圆心x坐标
圆心y坐标
宽
高
颜色
*/
imageellipse($im,400,300,400,300,$red);
imageellipse($im,400,300,300,300,$blue);
imageellipse($im,400,300,200,300,$red);
imageellipse($im,400,300,100,300,$blue);
// -------------------------------------
// 输出
header('content-type:image/png;');
imagepng($im);
// 销毁
imagedestroy($im);

圆弧画法
// 画布
$im = imagecreatetruecolor(800,600);
// 颜料
$gray = imagecolorallocate($im,200,200,200);
$blue = imagecolorallocate($im,0,0,255);
$red = imagecolorallocate($im,255,0,0);
// 填充
imagefill($im,0,0,$gray);
// -------------------------------------
// 画一段圆弧并填充
/*
bool imagearc ( resource $image , int $cx , int $cy , int $w , int $h , int $s , int $e , int $color )
参数:
画布资源
圆心x值
圆心y值
宽
高
起始角度
结果角度
颜色
bool imagefilledarc ( resource $image , int $cx , int $cy , int $width , int $height , int $start , int $end , int $color , int $style )
参数:
多一个填充方式
1. IMG_ARC_PIE
2. IMG_ARC_CHORD
3. IMG_ARC_NOFILL
4. IMG_ARC_EDGED
IMG_ARC_PIE 和 IMG_ARC_CHORD 是互斥的
1 IMG_ARC_CHORD 只是用直线连接了起始和结束点
0 IMG_ARC_PIE 则产生圆形边界
2 IMG_ARC_NOFILL 指明弧或弦只有轮廓,不填充
4 IMG_ARC_EDGED 指明用直线将起始和结束点与中心点相连
和
IMG_ARC_NOFILL 一起使用是画饼状图轮廓的好方法(而不用填充)
*/
imagefilledarc($im,400,300,300,300,270,0,$blue,IMG_ARC_CHORD);
//imagearc($im,400,300,310,310,-90,0,$blue);
imagefilledarc($im,400,300,300,300,270,0,$blue,1+2+4);
imagefilledarc($im,0,400,310,310,0,45,$blue,0+4);
imagefilledarc($im,0,400,300,300,0,45,$red,0+4);
// -------------------------------------
// 输出
header('content-type:image/png;');
imagepng($im);
// 销毁
imagedestroy($im);
