- Impact
- 9
I've just made this when i was messing about with GD functions in PHP, it is a progress bar type thing (not sure of the exact name). It takes 2 inputs, the total and used then creates a status bar type thing, could be useful for showing the amount of disk used.
Heres the main code:
ProgressBar.class.php
It creates it in PNG format, which can be changed but i've been experimenting and PNG seemed to eb the smallest filesize, below are example usages of it:
Basic - will take the default values set in the script
Or a more advanced version, where you can set additional variables (not everything needs to be set)
The only variables that need setting are total and highlight, any feedback appreciated
Thanks,
Lee
Heres the main code:
ProgressBar.class.php
PHP:
<?php
/*
Class For creating a progress bar, using gd image library
Created by: Lee Findlow
Contact: [email protected]
Website: http://lee.conceptsublime.com/
*/
class ProgressBar{
//Variables to be used
var $Width = 200; //Width of the Bar
var $Height = 20; //Height of the bar
var $Total; //The total amount, i.e. upper limit
var $Highlight; //The amount to be lit
//Background color attributes
var $ColorBG_R = 255; //Red
var $ColorBG_G = 255; //Green
var $ColorBG_B = 255; //Blue
//Highlight Color Attributes
var $ColorHighlight_R = 0; //Red
var $ColorHighlight_G = 255; //Green
var $ColorHighlight_B = 0; //Blue
//Border Attributes
var $ColorBorder_R = 0; //Red
var $ColorBorder_G = 0; //Green
var $ColorBorder_B = 0; //Blue
//Function to create image
function Create(){
//Send out type header
header ('Content-type: image/png');
//Create Image
$img = imagecreatetruecolor($this->Width, $this->Height);
//Colors and Borders
//Background
$back = imagecolorallocate($img, $this->ColorBG_R, $this->ColorBG_G, $this->ColorBG_B);
imagefilledrectangle($img, 0, 0, $this->Width, $this->Height, $back);
//Filled Area
$Highlight = imagecolorallocate($img, $this->ColorHighlight_R, $this->ColorHighlight_G, $this->ColorHighlight_B);
//Calculate Length of lit area
$length = (($this->Width - 2)/$this->Total) * $this->Highlight;
//Create Full
imagefilledrectangle($img, 1, 0, $length, $this->Height, $Highlight);
//Lines around border
$line = imagecolorallocate($img, $this->ColorBorder_R, $this->ColorBorder_G, $this->ColorBorder_B);
imagerectangle($img, 0, 0, $this->Width - 1, $this->Height - 1, $line);
//Create Image
imagepng($img);
echo $img;
//Destroy temp image file
imagedestroy($img);
}
};
?>
Basic - will take the default values set in the script
PHP:
<?php
include_once('ProgressBar.class.php');
$ProgressBar = new ProgressBar;
$ProgressBar->Total = 1024;
$ProgressBar->Highlight = 137;
$ProgressBar->Create();
?>
Or a more advanced version, where you can set additional variables (not everything needs to be set)
PHP:
<?php
include_once('ProgressBar.class.php');
$ProgressBar = new ProgressBar;
$ProgressBar->Width = 300;
$ProgressBar->Height = 45;
$ProgressBar->Total = 1024;
$ProgressBar->Highlight = 137;
//Background of Bar (RGB)
$ProgressBar->ColorBG_R = 255;
$ProgressBar->ColorBG_G = 255;
$ProgressBar->ColorBG_B = 255;
//Highlighted portion
$ProgressBar->ColorHighlight_R = 0;
$ProgressBar->ColorHighlight_G = 205;
$ProgressBar->ColorHighlight_B = 0;
//Border
$ProgressBar->ColorBorder_R = 0;
$ProgressBar->ColorBorder_G = 0;
$ProgressBar->ColorBorder_B = 0;
$ProgressBar->Create();
?>
Thanks,
Lee