🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
1、PHP绘制空心圆的函数: imageellipse($image, $cx, $cy, $width, $height, $color)。 代码如下: $img = imagecreatetruecolor(600, 600); $red = imagecolorallocate($img, 255, 255, 255); imagefill($img, 0, 0, $red); $x = imagesx($img); $y = imagesy($img); for($i=0;$i<20;$i++){ imageellipse($img, mt_rand(0,$x), mt_rand(0,$y), 200, 200, imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255))); } header('Content-type:image/jpeg'); imagejpeg($img); 效果图如下: ![](https://box.kancloud.cn/39556da8eb4f29b079bb2215f5f2cecd_567x442.jpg =500x400) 2、PHP绘制实心圆图像: imagefilledellipse($image, $cx, $cy, $width, $height, $color)。 代码如下: $img = imagecreatetruecolor(600, 600); $red = imagecolorallocate($img, 255, 0, 0); imagefill($img, 0, 0, $red); $x = imagesx($img); $y = imagesy($img); for($i=0;$i<40;$i++){ imagefilledellipse($img, mt_rand(0,$x), mt_rand(0,$y), 200, 200, imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255))); } header('Content-type:image/jpeg'); imagejpeg($img); 效果图如下: ![](https://box.kancloud.cn/a01792d4bcc54afe6a746d66d4fe3131_589x462.jpg =500x400) 3、PHP绘制圆弧线条: imagearc($image, $cx, $cy, $width, $height, $start, $end, $color)。 注意:0度是3点钟方向! 代码如下: $img = imagecreatetruecolor(600, 600); $white = imagecolorallocate($img, 255, 255, 255); imagefill($img, 0, 0, $white); imagearc($img, 300, 300, 100, 100, 0, 90, imagecolorallocate($img, 255, 0, 0)); header('Content-type:image/jpeg'); imagejpeg($img); 效果图如下: ![](https://box.kancloud.cn/553fdc04150ed4324bac6f2bfb4d12ea_343x239.jpg =500x400) 4、PHP绘制实心圆弧(饼状图): imagefilledarc($image, $cx, $cy, $width, $height, $start, $end, $color, $style)。 代码如下: $img = imagecreate(600, 600); imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255)); imagefilledarc($img, 300, 300, 200, 200, 0, 90, imagecolorallocate($img, 255, 255, 0), IMG_ARC_PIE); imagefilledarc($img, 300, 300, 200, 200, 90, 180, imagecolorallocate($img, 255, 0, 255), IMG_ARC_PIE); imagefilledarc($img, 300, 300, 200, 200, 180, 360, imagecolorallocate($img, 0, 255, 255), IMG_ARC_PIE); header('Content-type:image/jpeg'); imagejpeg($img); 效果图如下: ![](https://box.kancloud.cn/99939d1118c1ada92c9b44bfaadf6a97_383x284.jpg =500x400) 5、小实例,绘制一个数据统计饼状图: 代码如下: $messageArry = array('百度'=>'200','阿里巴巴'=>'300','腾讯'=>'400','联想'=>'230'); $img = imagecreate(600, 600); imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255)); $r1 = $r2 = $num = 0; foreach($messageArry as $k=>$v){ $r1 = $num==0 ? 0 : $r2; $r2 = $r1==0 ? ($v/array_sum($messageArry))*360 : ($v/array_sum($messageArry))*360+$r1; $r2 = min(360,ceil($r2)); imagefilledarc($img, 300, 300, 200, 200, $r1, $r2, imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)), IMG_ARC_PIE); $num+=1; } header('Content-type:image/jpeg'); imagejpeg($img); 效果图如下: ![](https://box.kancloud.cn/ffe38333b80eac4e3b9aa357575d4c64_341x272.jpg =500x400)