本程序是根據用戶提供的數據生成3D效果的百分比圖片統計效果,實例代碼如下:
- $image = imagecreatetruecolor(200,200); //創建一張200*200的畫布;
- //創建多種又區分的顏色
- $red = imagecolorallocate($image,255,0,0);
- $blue = imagecolorallocate($image,0,0,255);
- $yellow = imagecolorallocate($image,255,255,0);
- $violet = imagecolorallocate($image,255,0,255);
- $white = imagecolorallocate($image,255,255,255);
- $black = imagecolorallocate($image,0,0,0);
- //使用for循環創建3d效果底層效果
- for($i=120;$i>100;$i--){
- imagefilledarc($image,100,$i,200,120,0,30,$red,img_arc_pie);//img_arc_pie注釋如下:
- imagefilledarc($image,100,$i,200,120,30,80,$blue,img_arc_pie);
- imagefilledarc($image,100,$i,200,120,80,360,$yellow,img_arc_pie);
- }
- //bool imagefilledarc ( resource image, int cx, int cy, int w, int h, int s, int e, int color, int style )
- //
- //imagefilledarc() 在 image 所代表的圖像中以 cx,cy(圖像左上角為 0, 0)畫一橢圓弧。如果成功則返回 true,失敗則返回 false。w 和 h 分別指定了橢圓的寬和高,s 和 e 參數以角度指定了起始和結束點。style 可以是下列值按位或(or)后的值:
- //
- //img_arc_pie
- //
- //img_arc_chord
- //
- //img_arc_nofill
- //
- //img_arc_edged
- //這個層是最上面一層的效果,這樣立體效果就出來了!
- imagearc($image,100,100,200,120,0,360,$black);//添加一個黑色的邊圈,這樣3d效果看起來更加明顯點
- imagefilledarc($image,100,100,200,120,0,30,$red,img_arc_pie);
- imagefilledarc($image,100,100,200,120,30,80,$blue,img_arc_pie);
- imagefilledarc($image,100,100,200,120,80,360,$yellow,img_arc_pie);
- //添加百分比數據,當然此處必要的時候可以批量的進行一定的運算將輸入輸入到圖片上
- $str = iconv ("gbk","utf-8","36%");//如果要輸入中文需要此轉換。example:占用:30%;
- imagettftext($image,10,360-15,100+70,115,$white,"simhei.ttf",$str);
- //開源代碼Vevb.com
- imagejpeg($image);
- imagedestroy($image);
新聞熱點
疑難解答