PHP商城笔记(验证码2) —— 画矩形和饼状图

矩形和椭圆画法
// 画布
$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);

这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

烟敛寒林o

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值