• PHP画矩形,椭圆,圆,画椭圆弧 ,饼状图


    1:画矩形:

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

    imagerectangle()col 颜色在 image 图像中画一个矩形,其左上角坐标为 x1, y1,右下角坐标为 x2, y2。图像的左上角坐标为 0, 0。

    2:画椭圆:

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

    cx中间的 X 坐标。cy中间的 Y 坐标。width椭圆的宽度。height椭圆的高度。color椭圆的颜色。

    3:画椭圆弧:

    imagearc ( resource $image , int $cx , int $cy , int $w , int $h , int $s , int $e , int $color )(即在椭圆中截取一定的弧度)

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

    4:画饼状图:先循环画多个圆心在一条直线上的椭圆并填充

    1 for($i=100;$i>50;$i--){
    2 imagefilledarc($image, 150, $i, 150, 100, 0, 270, $gray,IMG_ARC_EDGED );
    3 }

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

    cx:中间的 x 坐标。cy:中间的 y 坐标。width:椭圆弧的宽度。height:椭圆弧的高度。start:起点角度。end:终点角度。 0°color:颜色标识符。

    style:

    1. IMG_ARC_PIE  :则产生圆形边界并填充
    2. IMG_ARC_CHORD :只是用直线连接了起始和结束点并填充
    3. IMG_ARC_NOFILL:则产生圆形边界不填充
    4. IMG_ARC_EDGED:指明用直线将起始和结束点与中心点相连

    简单事例:

    前台代码:

     1 <div style="300px;height:400px;border:1px solid gray;margin:auto;">
     2 <h2 style="text-align:center">全校学生分布统计</h2>
     3 <center>
     4     <form action="11Pro.php" method="post">
     5             安徽:<input type="text" name="anhui"><br/>
     6             浙江:<input type="text" name="zhejiang"><br/>
     7             吉林:<input type="text" name="jilin"><br/>
     8             北京:<input type="text" name="beijing"><br/><br/>
     9             <input style="160px;" type="submit" value="生成饼状图"><br/>
    10             <input style="160px;" type="reset" value="重置">
    11     </form>
    12 </center>
    13 </div>

    前台界面:

    后台PHP代码:

     1 <?php 
     2 
     3 //创建画布
     4 $image=imagecreatetruecolor(200,200);
     5 
     6 
     7 //定义颜色
     8 $red=imagecolorallocate($image, 255, 0, 0);
     9 $darkred=imagecolorallocate($image, 102, 0, 0);
    10 
    11 $blue=imagecolorallocate($image, 0, 0, 255);
    12 $darkblue=imagecolorallocate($image, 0, 51, 102);;
    13 
    14 
    15 $green=imagecolorallocate($image, 0, 255, 0);
    16 $darkgreen=imagecolorallocate($image, 51, 102, 51);
    17 
    18 $gray=imagecolorallocate($image, 125, 125, 125);
    19 $darkgray=imagecolorallocate($image, 102, 102, 102);
    20 
    21 $anhui=$_POST['anhui'];
    22 $jilin=$_POST['jilin'];
    23 $beijing=$_POST['beijing'];
    24 $zhejiang=$_POST['zhejiang'];
    25 
    26 $count=$anhui+$beijing+$jilin+$zhejiang;
    27 
    28 //循环画饼状图
    29 for($i=100;$i>85;$i--){
    30     imagefilledarc($image, 100, $i, 150, 100, 0, ($anhui/$count)*360, $darkgray, IMG_ARC_PIE);
    31     imagefilledarc($image, 100, $i, 150, 100, ($anhui/$count)*360, (($anhui+$jilin)/$count)*360, $darkblue, IMG_ARC_PIE);
    32     imagefilledarc($image, 100, $i, 150, 100, (($anhui+$jilin)/$count)*360, (($anhui+$jilin+$beijing)/$count)*360, $darkgreen, IMG_ARC_PIE);
    33     imagefilledarc($image, 100, $i, 150, 100, (($anhui+$jilin+$beijing)/$count)*360, 360, $darkred, IMG_ARC_PIE);
    34 }
    35 imagefilledarc($image, 100, 85, 150, 100, 0, ($anhui/$count)*360, $gray, IMG_ARC_PIE);
    36 imagefilledarc($image, 100, 85, 150, 100, ($anhui/$count)*360, (($anhui+$jilin)/$count)*360, $blue, IMG_ARC_PIE);
    37 imagefilledarc($image, 100, 85, 150, 100, (($anhui+$jilin)/$count)*360, (($anhui+$jilin+$beijing)/$count)*360, $green, IMG_ARC_PIE);
    38 imagefilledarc($image, 100, 85, 150, 100, (($anhui+$jilin+$beijing)/$count)*360, 360, $red, IMG_ARC_PIE);
    39 
    40 header("Content-type: image/png");
    41 
    42 imagepng($image);
    43 
    44 imagedestroy($image);
    45 
    46 ?>

    后台处理结果:

  • 相关阅读:
    Android开发:《Gradle Recipes for Android》阅读笔记(翻译)5.2——使用Android Testing Support Library进行测试
    Android开发:《Gradle Recipes for Android》阅读笔记(翻译)5.1——单元测试
    Android开发:《Gradle Recipes for Android》阅读笔记(翻译)4.5——使用Android Libraries
    Android开发:《Gradle Recipes for Android》阅读笔记(翻译)4.4——自定义代码集合
    Android开发:《Gradle Recipes for Android》阅读笔记(翻译)4.3——排除任务
    10.13总结
    10.7号解题报告
    no zuo no die
    发誓!
    NOIP2016天天爱跑步
  • 原文地址:https://www.cnblogs.com/yhqq512/p/6940764.html
Copyright © 2020-2023  润新知