<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[阿Tim日志]]></title> 
<link>https://atim.cn/index.php</link> 
<description><![CDATA[专业的php开发者.开发团队的带队人]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[阿Tim日志]]></copyright>
<item>
<link>https://atim.cn/post//</link>
<title><![CDATA[生成图饼代码]]></title> 
<author>bkkkd &lt;partybase@gmail.com&gt;</author>
<category><![CDATA[开发应用]]></category>
<pubDate>Sat, 03 Feb 2007 16:02:58 +0000</pubDate> 
<guid>https://atim.cn/post//</guid> 
<description>
<![CDATA[ 
	<a href="https://atim.cn/attachment/1170521000_0.gif" target="_blank"><img src="https://atim.cn/attachment/1170521000_0.gif" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/><div class="code"><br/><br/>//+------------------------+ <br/>//&#124; pie3dfun.PHP//公用函数 &#124; <br/>//+------------------------+ <br/><br/>define(&quot;ANGLE_STEP&quot;, 5); //定义画椭圆弧时的角度步长 <br/><br/>function draw_getdarkcolor($img,$clr) //求$clr对应的暗色 <br/>&#123; <br/>$rgb = imagecolorsforindex($img,$clr); <br/>return array($rgb&#91;&quot;red&quot;&#93;/2,$rgb&#91;&quot;green&quot;&#93;/2,$rgb&#91;&quot;blue&quot;&#93;/2); <br/>&#125; <br/><br/>function draw_getexy($a, $b, $d) //求角度$d对应的椭圆上的点坐标 <br/>&#123; <br/>$d = deg2rad($d); <br/>return array(round($a*Cos($d)), round($b*Sin($d))); <br/>&#125; <br/><br/>function draw_arc($img,$ox,$oy,$a,$b,$sd,$ed,$clr) //椭圆弧函数 <br/>&#123; <br/>$n = ceil(($ed-$sd)/ANGLE_STEP); <br/>$d = $sd; <br/>list($x0,$y0) = draw_getexy($a,$b,$d); <br/>for($i=0; $i&lt;$n; $i++) <br/>&#123; <br/>$d = ($d+ANGLE_STEP)&gt;$ed?$ed:($d+ANGLE_STEP); <br/>list($x, $y) = draw_getexy($a, $b, $d); <br/>imageline($img, $x0+$ox, $y0+$oy, $x+$ox, $y+$oy, $clr); <br/>$x0 = $x; <br/>$y0 = $y; <br/>&#125; <br/>&#125; <br/><br/>function draw_sector($img, $ox, $oy, $a, $b, $sd, $ed, $clr) //画扇面 <br/>&#123; <br/>$n = ceil(($ed-$sd)/ANGLE_STEP); <br/>$d = $sd; <br/>list($x0,$y0) = draw_getexy($a, $b, $d); <br/>imageline($img, $x0+$ox, $y0+$oy, $ox, $oy, $clr); <br/>for($i=0; $i&lt;$n; $i++) <br/>&#123; <br/>$d = ($d+ANGLE_STEP)&gt;$ed?$ed:($d+ANGLE_STEP); <br/>list($x, $y) = draw_getexy($a, $b, $d); <br/>imageline($img, $x0+$ox, $y0+$oy, $x+$ox, $y+$oy, $clr); <br/>$x0 = $x; <br/>$y0 = $y; <br/>&#125; <br/>imageline($img, $x0+$ox, $y0+$oy, $ox, $oy, $clr); <br/>list($x, $y) = draw_getexy($a/2, $b/2, ($d+$sd)/2); <br/>imagefill($img, $x+$ox, $y+$oy, $clr); <br/>&#125; <br/><br/>function draw_sector3d($img, $ox, $oy, $a, $b, $v, $sd, $ed, $clr) //3d扇面 <br/>&#123; <br/>draw_sector($img, $ox, $oy, $a, $b, $sd, $ed, $clr); <br/>if($sd&lt;180) <br/>&#123; <br/>list($R, $G, $B) = draw_getdarkcolor($img, $clr); <br/>$clr=imagecolorallocate($img, $R, $G, $B); <br/>if($ed&gt;180) $ed = 180; <br/>list($sx, $sy) = draw_getexy($a,$b,$sd); <br/>$sx += $ox; <br/>$sy += $oy; <br/>list($ex, $ey) = draw_getexy($a, $b, $ed); <br/>$ex += $ox; <br/>$ey += $oy; <br/>imageline($img, $sx, $sy, $sx, $sy+$v, $clr); <br/>imageline($img, $ex, $ey, $ex, $ey+$v, $clr); <br/>draw_arc($img, $ox, $oy+$v, $a, $b, $sd, $ed, $clr); <br/>list($sx, $sy) = draw_getexy($a, $b, ($sd+$ed)/2); <br/>$sy += $oy+$v/2; <br/>$sx += $ox; <br/>imagefill($img, $sx, $sy, $clr); <br/>&#125; <br/>&#125;<br/>function draw_getindexcolor($img, $clr) //RBG转索引色 <br/><br/>&#123; <br/>$R = ($clr&gt;&gt;16) &amp; 0xff; <br/>$G = ($clr&gt;&gt;8)&amp; 0xff; <br/>$B = ($clr) &amp; 0xff; <br/>return imagecolorallocate($img, $R, $G, $B); <br/>&#125; <br/><br/>// 绘图主函数，并输出图片 <br/>// $datLst 为数据数组, $datLst 为标签数组, $datLst 为颜色数组 <br/>// 以上三个数组的维数应该相等 <br/>function draw_img($datLst,$labLst,$clrLst,$a=250,$b=120,$v=20,$font=10) <br/>&#123; <br/>$ox = 5+$a; <br/>$oy = 5+$b; <br/>$fw = imagefontwidth($font); <br/>$fh = imagefontheight($font); <br/><br/>$n = count($datLst);//数据项个数 <br/><br/>$w = 10+$a*2; <br/>$h = 10+$b*2+$v+($fh+2)*$n; <br/><br/>$img = imagecreate($w, $h); <br/><br/>//转RGB为索引色 <br/>for($i=0; $i&lt;$n; $i++) <br/>$clrLst&#91;$i&#93; = draw_getindexcolor($img,$clrLst&#91;$i&#93;); <br/><br/>$clrbk = imagecolorallocate($img, 0xff, 0xff, 0xff); <br/>$clrt = imagecolorallocate($img, 0x00, 0x00, 0x00); <br/><br/>//填充背景色 <br/>imagefill($img, 0, 0, $clrbk); <br/><br/>//求和 <br/>$tot = 0; <br/>for($i=0; $i&lt;$n; $i++) <br/>$tot += $datLst&#91;$i&#93;; <br/>$sd = 0; <br/>$ed = 0; 333 <br/>$ly = 10+$b*2+$v; <br/>for($i=0; $i&lt;$n; $i++) <br/>&#123; <br/>$sd = $ed; <br/>$ed += $datLst&#91;$i&#93;/$tot*360; <br/><br/>//画圆饼 <br/>draw_sector3d($img, $ox, $oy, $a, $b, $v, $sd, $ed, $clrLst&#91;$i&#93;); //$sd,$ed,$clrLst&#91;$i&#93;); <br/><br/>//画标签 <br/>imagefilledrectangle($img, 5, $ly, 5+$fw, $ly+$fh, $clrLst&#91;$i&#93;); <br/>imagerectangle($img, 5, $ly, 5+$fw, $ly+$fh, $clrt); <br/>//imagestring($img, $font, 5+2*$fw, $ly, $labLst&#91;$i&#93;.&quot;:&quot;.$datLst&#91;$i&#93;.&quot;(&quot;.(round(10000*($datLst&#91;$i&#93;/$tot))/100).&quot;%)&quot;, $clrt); <br/><br/>$str = iconv(&quot;GB2312&quot;, &quot;UTF-8&quot;, $labLst&#91;$i&#93;); <br/>ImageTTFText($img, $font, 0, 5+2*$fw, $ly+13, $clrt, &quot;./simsun.ttf&quot;, $str.&quot;:&quot;.$datLst&#91;$i&#93;.&quot;(&quot;.(round(10000*($datLst&#91;$i&#93;/$tot))/100).&quot;%)&quot;); <br/>$ly += $fh+2; <br/>&#125; <br/><br/>//输出图形 <br/>header(&quot;Content-type: image/png&quot;); <br/><br/>//输出生成的图片 <br/>$imgFileName = &quot;../temp/&quot;.time().&quot;.png&quot;; <br/>imagepng($img,$imgFileName); <br/>echo &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039; <br/>&#125; <br/><br/>$datLst = array(30, 10, 20, 20, 10, 20, 10, 20); //数据 <br/>$labLst = array(&quot;中国科技大学&quot;, &quot;安徽理工大学&quot;, &quot;清华大学&quot;, &quot;北京大学&quot;, &quot;南京大学&quot;, &quot;上海大学&quot;, &quot;河海大学&quot;, &quot;中山大学&quot;); //标签 <br/>$clrLst = array(0x99ff00, 0xff6666, 0x0099ff, 0xff99ff, 0xffff99, 0x99ffff, 0xff3333, 0x009999); <br/><br/>//画图 <br/>draw_img($datLst,$labLst,$clrLst); <br/>?&gt; <br/></div><br/>Tags - <a href="https://atim.cn/tags/php/" rel="tag">php</a> , <a href="https://atim.cn/tags/%25E5%259B%25BE%25E9%25A5%25BC/" rel="tag">图饼</a> , <a href="https://atim.cn/tags/%25E4%25BB%25A3%25E7%25A0%2581/" rel="tag">代码</a>
]]>
</description>
</item><item>
<link>https://atim.cn/post//#blogcomment</link>
<title><![CDATA[[评论] 生成图饼代码]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://atim.cn/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>