PHP 画出饼形图表

发布时间:2009年02月03日      浏览次数:940 次
<?php
////////////////////////////////////////////////////////////////////////////////////////////
// 画出饼形图表 
////////////////////////////////////////////////////////////////////////////////////////////
//新旧图片的宽和高
$height=400;
$width=600;
$oldmap= "tmp/bg.jpg";
$barbg="tmp/barbg.jpg";
$barwidth=18;
//定义边界距离 
$top=10;
$left=10;
$right=10;
$bottom=10;
//以下为动态获取边界数值,如果不需要可注释掉
if($_GET['top']!='')$top=$_GET['top'];
if($_GET['left']!='')$top=$_GET['left'];
if($_GET['right']!='')$top=$_GET['right'];
if($_GET['bottom']!='')$top=$_GET['bottom'];
//png文件头
header("Content-type: image/jpeg;");
$im= imagecreatefromjpeg($oldmap);
$img =imagecreatetruecolor($width,$height) ;
//背景图
@imagecopyresized($img,$im,0,0,0,0,$width,$height,imagesx($im),imagesy($im));
//定义颜色
imagedestroy($im);
$white            = imagecolorallocate($img, 255,255,255);
$black            = imagecolorallocate($img, 0,0,0);
$red            = imagecolorallocate($img, 255,0,0);
$blue            = imagecolorallocate($img, 0,0,255);
$lightblue      = imagecolorallocate($img, 0,0,200);
//定义字体
$fontfile = 'tmp/font.ttf';
//定义标题
if($_GET['title'] <> "" ) $title = $_GET['title']; //此行为动态获取标题数据,只支持英文,如果不需要可注释掉
if( $title <> "" ) @ImageTTFText($img,12,0,200,15,$white,$fontfile,$title);
//画出坐标x轴
@imageline($img,$left,$height-$bottom,$width-$right,$height-$bottom, $white);
//画出坐标y轴
@imageline($img,$left,$top,$left,$height-$bottom, $white);
//数据,0-75,75-150,150-290,290-360,即一共为360度,中间的差值为扇形的角度
$img = draw_arc_3d($img,210,230,400,300,0,75,123,23,94);
$img = draw_arc_3d($img,210,230,400,300,75,150,163,23,54);
$img = draw_arc_3d($img,210,230,400,300,150,290,123,93,94);
$img = draw_arc_3d($img,210,230,400,300,290,360,163,223,54);
//生成图片
imagejpeg( $img);
imagedestroy($img);
////////////////////////////////////////////////////////////////////////////////////////////
// 相关函数
////////////////////////////////////////////////////////////////////////////////////////////
//画有3d效果的扇形 
//参数说明:
//$img_为返回的图形数据,$x为坐标x轴,$y为坐标y轴,$width为图形的宽,$height为图形的高,$start为扇形的起始坐标,$end为扇形的角度值,$color_red、$color_green、$color_blue为图形的颜色值红、绿、蓝
function draw_arc_3d($img_,$x,$y,$width,$height,$start,$end,$color_red,$color_green,$color_blue){
$color = imagecolorallocate($img_, ($color_red+120) % 255,($color_green+80)%255,($color_blue+20)%255);
      for($i=0;$i<8;$i++) //用循环画出3D效果
            imagefilledarc($img_,$x,$y+$i,$width,$height,$start,$end,$color, IMG_ARC_PIE);
      ///画出扇形并填充
      $color = imagecolorallocate($img_,$color_red,$color_green,$color_blue);
      imagefilledarc($img_, $x,$y,$width,$height,$start,$end,$color, IMG_ARC_PIE);
      return $img_;
      imagedestroy($img_);
}
?>
文章来源:桂林唯创网络
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!