[分享] 用GD畫進度條

看板PHP作者 (一車干)時間16年前 (2009/10/30 18:37), 編輯推噓3(301)
留言4則, 4人參與, 最新討論串1/1
用GD畫的,請確定你的系統支援GD 有許多parameter沒加,可以隨便改 用img插入即可 可以指定背景色,進度色,寬高 數值用整數輸入 <img src="bar.php?width=200&height=20&back=00-00-00&fore=FF-FF-FF&value=35"> <? function draw_string($image, $x_pos, $y_pos, $string, $font_size, $color) { $len=strlen($string); for($i=0;$i<$len;$i++) { $xpos=$x_pos+$i*imagefontwidth($font_size); $ypos=$y_pos; imagechar($image, $font_size, $xpos, $ypos, $string, $color); $string = substr($string,1); } } //request format: //img src=progressbar.php?width=w&height=h&back=R-G-B&fore=R-G-B&value=int% // //default if(!isset($_GET['width'])) $_GET['width']="200"; if(!isset($_GET['height'])) $_GET['height']="14"; if(!isset($_GET['back'])) $_GET['back']="CC-CC-CC"; if(!isset($_GET['fore'])) $_GET['fore']="00-FF-00"; $width=round($_GET['width']*1); $height=round($_GET['height']*1); $bar=imagecreatetruecolor($width, $height); imageantialias($bar, true); imagealphablending($bar, true); $_GET['warn']="FF-FF-00"; $backcolor=explode("-", $_GET['back']); $forecolor=explode("-", $_GET['fore']); $warncolor=explode("-", $_GET['warn']); //$back_color=imagecolorallocate($bar, 0, 10, 20); $black = imagecolorallocate($bar, 0, 0, 0); $white = imagecolorallocate($bar, 255, 255, 255); $back_color=imagecolorallocate($bar, hexdec($backcolor[0]), hexdec($backcolor[1]), hexdec($backcolor[2])); $fore_color=imagecolorallocate($bar, hexdec($forecolor[0]), hexdec($forecolor[1]), hexdec($forecolor[2])); $warn_color=imagecolorallocate($bar, hexdec($warncolor[0]), hexdec($warncolor[1]), hexdec($warncolor[2])); $value=round($_GET['value']*1); $percent=round($width*$value)*0.01; $threshold_rate="90"; $threshold=round($width*$threshold_rate)*0.01; imagefilledrectangle($bar, 0, 0, $width, $height, $back_color); imagefilledrectangle($bar, 0, 0, $percent, $height, $fore_color); imagefilledrectangle($bar, $threshold, 0, $threshold+1, $height, $warn_color); $limit="soft cap ".$threshold_rate."%"; $host="FTP disk usage "; if($height>=14) { // draw_string($bar, 2, $height-13, $host.$value."%", 2, $black); draw_string($bar, 2, $height-13, $value."%", 2, $black); draw_string($bar, $threshold-(strlen($limit)*5)-2, $height-8, $limit, 1, $black); } header("Content-type: image/png"); imagepng($bar); ?> -- 被掛木馬討厭的彈出視窗他奶奶的病毒擱再來系統不穩殺千刀的死微軟給林鄒罵記住 藍底白字天空好藍雲好白telnet://bs2.to P_tonysan 電腦維修站又要重灌浪費生命 這三洨錯誤報告考試錯的已經夠多了你還報告個雕記憶體嚴重不足加一駒不到二千五 跟荷包過不去把XP光碟絞碎寄回微軟抗議視窗作業系統根本就是廢渣還期待Vista? 老娘不知道怎麼調敗歐死全部 0-800-956-956-cm.tonysan.org 都是盎格薩薩滷蛋文 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.119.235.83

10/30 21:03, , 1F
有圖片可以直接看結果嗎 >"<
10/30 21:03, 1F

10/31 02:05, , 2F
應該說 有可以預覽的嗎?
10/31 02:05, 2F

10/31 09:52, , 3F
用JPGRAPH應該更快喔XD
10/31 09:52, 3F

10/31 15:29, , 4F
先推
10/31 15:29, 4F
文章代碼(AID): #1Awi7d1x (PHP)
文章代碼(AID): #1Awi7d1x (PHP)