| NamePros Member | I hope you don't mind me posting this but I modified your code so I could just call it as an image file. I also changed some variable names to clear the code a little bit. PHP Code: <?php
/*
* ProgressBar.php by c0demonger
* Based on by ProgressBar.class.php by Lee Findlow / leefindlow@gmail.com
* ---------------------
* Sample Usage: <img src="ProgressBar.php?t=100&h=56" alt="56 Percent Full" />
*/
$Total = (int) $_GET['t'];
$Highlight = (int) $_GET['h'];
$Width = 200; //Width of the Bar
$Height = 20; //Height of the bar
//Background color attributes
$ColorBG_R = 255; //Red
$ColorBG_G = 255; //Green
$ColorBG_B = 255; //Blue
//Highlight Color Attributes
$ColorHighlight_R = 0; //Red
$ColorHighlight_G = 121; //Green
$ColorHighlight_B = 0; //Blue
//Border Color Attributes
$ColorBorder_R = 0; //Red
$ColorBorder_G = 0; //Green
$ColorBorder_B = 0; //Blue
//Send out type header
header ('Content-type: image/png');
//Create Image
$img = imagecreatetruecolor($Width, $Height);
//Colors and Borders
//Background
$color_back = imagecolorallocate($img, $ColorBG_R, $ColorBG_G, $ColorBG_B);
//Filled Area
$color_highlight = imagecolorallocate($img, $ColorHighlight_R, $ColorHighlight_G, $ColorHighlight_B);
//Border
$color_line = imagecolorallocate($img, $ColorBorder_R, $ColorBorder_G, $ColorBorder_B);
//Calculate Length of lit area
$length = (($Width - 2)/$Total) * $Highlight;
// draw background
imagefilledrectangle($img, 0, 0, $Width, $Height, $color_back);
// draw highlighted percentage
imagefilledrectangle($img, 1, 0, $length, $Height, $color_highlight);
// draw the border
imagerectangle($img, 0, 0, $Width - 1, $Height - 1, $color_line);
//Create Image
imagepng($img);
//Destroy temp image file
imagedestroy($img);
?>
Might come in handy for some one
Cheers. |