用gd库画矩形和椭圆

画矩形:bool imagerectangle ( resource $image画布资源 , int $x1左上角的坐标 , int $y1 , int $x2 右下角坐标, int $y2 , int $col颜色 )

填充颜色用imagefilledrectangle();参数和上面的一样

画椭圆:bool imageellipse ( resource $image , int $cx中心坐标 , int $cy , int $width宽度 , int $height高度 , int $color颜色)

画圆弧:bool imagearc ( resource $image , int $cx中心坐标 , int $cy , int $width宽度 , int $height高度 , int $start起始角度 , int $end结束角度 , int $color颜色)顺时针计算

画圆弧填充颜色,bool imagefilledarc ( resource $image , int $cx , int $cy , int $width , int $height , int $start , int $end , int $color , int $style 样式)

style

值可以是下列值的按位或(OR):

  1. IMG_ARC_PIE
  2. IMG_ARC_CHORD
  3. IMG_ARC_NOFILL
  4. IMG_ARC_EDGED

可以用数字相加来叠加多个方式的效果

<?php
//画矩形和椭圆

//画布
$rs=imagecreatetruecolor(600,400);

//颜料
$gray=imagecolorallocate($rs,200,200,200);
$red=imagecolorallocate($rs,255,0,0);
$green=imagecolorallocate($rs,0,255,0);
$blue=imagecolorallocate($rs,0,0,255);


//绘画
//画矩形
imagerectangle($rs,100,50,500,350,$gray);
//填充颜色
imagefill($rs,0,0,$red);

//画椭圆
imagefilledellipse($rs,300,200,400,300,$green);
imagefilledellipse($rs,300,200,300,300,$blue);
imagefilledellipse($rs,300,200,200,300,$green);
imagefilledellipse($rs,300,200,100,300,$blue);
//输出
header('content-type:image/jpeg');
imagejpeg($rs);


//销毁对象
imagedestroy($rs);


?>

<?php
//画圆弧

//画布
$rs=imagecreatetruecolor(600,400);

//颜料
$gray=imagecolorallocate($rs,200,200,200);
$red=imagecolorallocate($rs,255,0,0);
$green=imagecolorallocate($rs,0,255,0);
$blue=imagecolorallocate($rs,0,0,255);


//绘画
//画矩形
imagerectangle($rs,100,50,500,350,$gray);
//填充颜色
imagefill($rs,0,0,$red);

//画圆弧
imagearc($rs,300,200,200,150,90,180,$green);

//如果填充颜色用
imagefilledarc($rs,300,200,200,150,185,275,$blue,1+4);
//输出
header('content-type:image/jpeg');
imagejpeg($rs);


//销毁对象
imagedestroy($rs);



?>
原文地址:https://www.cnblogs.com/lzzhuany/p/4793096.html