时间:2014年4月9日19:50:31 画矩形及饼状图


画矩形:

bool imagerectangle ( resource $image , int $x1 ,int $y1 , int $x2 , int $y2 , int $col )

参数分别是:画布资源,左上角坐标,右下角坐标,颜色

<?php

/*造画布*/

$image = imagecreatetruecolor(800, 600);

/*造颜料*/

$gray = imagecolorallocate($image, 180,  200, 200);

$blue = imagecolorallocate($image, 0, 0,  255);

/*填充*/

imagefill($image , 0, 0, $gray);

/*画矩形*/

imagerectangle($image, 200, 150, 600,  450, $blue);

/*输出*/

header('content-type:image/jpeg');

imagejpeg($image);

/*销毁*/

imagedestroy($image);

?>


画椭圆

bool imageellipse ( resource $image , int $cx ,int $cy , int $width , int $height , int $color )

<?php

/*造画布*/

$image = imagecreatetruecolor(800, 600);

/*造颜料*/

$gray = imagecolorallocate($image, 180, 200, 200);

$blue = imagecolorallocate($image, 0, 0, 255);

/*填充*/

imagefill($image , 0, 0, $gray);

/*画图*/

imagerectangle($image, 200, 150, 600, 450, $blue);

imageellipse($image, 400, 300, 400, 300, $blue);

imageellipse($image, 400, 300, 300, 300, $blue);//画圆,

imageellipse($image, 400, 300, 200, 300, $blue);

imageellipse($image, 400, 300, 100, 300, $blue);

/*输出*/

header('content-type:image/jpeg');

imagejpeg($image);

/*销毁*/

imagedestroy($image);

?>


画矩形,并填充

bool imagefilledellipse ( resource $image ,int $cx , int $cy , int $width , int $height , int $color )

<?php

/*造画布*/

$image = imagecreatetruecolor(800, 600);

/*造颜料*/

$gray = imagecolorallocate($image, 180,  200, 200);

$blue = imagecolorallocate($image, 0, 0,  255);

/*填充*/

imagefill($image , 0, 0, $gray);

/*画图*/

imagerectangle($image, 200, 150, 600,  450, $gray);

imagefilledellipse($image, 400, 300, 400,  300, $blue);

imagefilledellipse($image, 400, 300, 300,  300, $gray);//画圆

imagefilledellipse($image, 400, 300, 200,  300, $blue);

imagefilledellipse($image, 400, 300, 100,  300, $gray);

/*输出*/

header('content-type:image/jpeg');

imagejpeg($image);

/*销毁*/

imagedestroy($image);

?>


画圆弧

bool imagearc ( resource $image , int $cx ,int $cy , int $w , int $h , int $s , int $e , int $color )

cx cy (图像左上角为 0, 0)为中心在 image 所代表的图像中画一个椭圆弧。 w h 分别指定了椭圆的宽度和高度,起始和结束点以 s e 参数以角度指定。0°位于三点钟位置,以顺时针方向绘画。

<?php

/*造画布*/

$image = imagecreatetruecolor(800, 600);

/*造颜料*/

$gray = imagecolorallocate($image, 180,  200, 200);

$blue = imagecolorallocate($image, 0, 0,  255);

$red = imagecolorallocate($image, 255, 0,  0);

/*填充*/

imagefill($image , 0, 0, $gray);

/*画图*/

imagearc($image,400,300, 300, 300, 270, 0,  $blue);

  imagearc($image,400,300, 305, 305, -90, 0, $red);

/*输出*/

header('content-type:image/jpeg');

imagejpeg($image);

/*销毁*/

imagedestroy($image);

?>

画圆弧并填充

bool imagefilledarc ( resource $image , int$cx , int $cy , int $width , int $height , int $start , int $end , int $color ,int $style )

参数style:填充方式值可以是下列值的按位或(OR):

两个点如何相连:

可以直接连IMG_ARC_CHORD

可以弧线连接IMG_ARC_PIE

0.IMG_ARC_PIE      弧线连接圆弧两端

1.IMG_ARC_CHORD  直线连接圆弧两端

2.IMG_ARC_NOFILL  直线将起始和结束点与中心点相连

4.IMG_ARC_EDGED  不填充轮廓

IMG_ARC_PIE IMG_ARC_CHORD 是互斥的;

IMG_ARC_CHORD 只是用直线连接了起始和结束点,

IMG_ARC_PIE 则产生圆形边界

IMG_ARC_NOFILL 指明弧或弦只有轮廓,不填充。

IMG_ARC_EDGED 指明用直线将起始和结束点与中心点相连,和 IMG_ARC_NOFILL 一起使用是画饼状图轮廓的好方法(而不用填充)。

<?php

/*造画布*/

$image = imagecreatetruecolor(800, 600);

/*造颜料*/

$gray = imagecolorallocate($image, 180,  200, 200);

$blue = imagecolorallocate($image, 0, 0,  255);

$red = imagecolorallocate($image, 255, 0,  0);

/*填充*/

imagefill($image , 0, 0, $gray);

/*画图*/

imagefilledarc($image,400,300, 305, 305,  -90, 0, $red,4);

imagefilledarc($image,400,300, 300, 300,  270, 0, $blue,4);


/*输出*/

header('content-type:image/jpeg');

imagejpeg($image);

/*销毁*/

imagedestroy($image);

?>

Imagefill

bool imagefill ( resource $image , int $x ,int $y , int $color )

imagefill() image 图像的坐标 x y (图像左上角为 0, 0)处用 color 颜色执行区域填充(即与 x, y 点颜色相同且相邻的点都会被填充)。

<?php

/*造画布*/

$image = imagecreatetruecolor(800, 600);

/*造颜料*/

$gray = imagecolorallocate($image, 180,  200, 200);

$blue = imagecolorallocate($image, 0, 0,  255);

$red = imagecolorallocate($image, 255, 0,  0);

/*填充*/

imagefill($image , 0, 0, $gray);

/*画图*/

imageellipse($image, 400, 300, 300, 300,  $blue);

//imagefill($image, 0, 0, $red);

imagefill($image, 400, 300, $red);

/*输出*/

header('content-type:image/jpeg');

imagejpeg($image);

/*销毁*/

imagedestroy($image);

?>


你可能感兴趣的:(资源)