用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):
IMG_ARC_PIE
IMG_ARC_CHORD
IMG_ARC_NOFILL
IMG_ARC_EDGED
可以用数字相加来叠加多个方式的效果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <?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 ); ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <?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 ); ?> |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步