NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page [PHP] Progress/Status Bar

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search
7 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 01-24-2007, 11:16 AM THREAD STARTER               #1 (permalink)
NamePros Regular
Join Date: Mar 2006
Location: United Kingdom
Posts: 413
lee101 is a jewel in the roughlee101 is a jewel in the roughlee101 is a jewel in the rough
 




[PHP] Progress/Status Bar


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
PHP Code:
<?php
/*
    Class For creating a progress bar, using gd image library
    
    Created by: Lee Findlow
    Contact:     leefindlow@gmail.com
    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
????: NamePros.com http://www.namepros.com/code/285609-php-progress-status-bar.html
        
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($img00$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($img10$length$this->Height$Highlight);
            
//Lines around border
            
$line imagecolorallocate($img$this->ColorBorder_R$this->ColorBorder_G$this->ColorBorder_B);
            
imagerectangle($img00$this->Width 1$this->Height 1$line);
        
//Create Image
            
imagepng($img);
            echo 
$img;
        
//Destroy temp image file
            
imagedestroy($img);
    }
};
?>
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
PHP Code:
<?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 Code:
<?php
????: NamePros.com http://www.namepros.com/showthread.php?t=285609
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();
?>
The only variables that need setting are total and highlight, any feedback appreciated

Thanks,
Lee
__________________
Linux Screenshots
lee101 is offline  
Old 01-24-2007, 11:19 AM   #2 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,267
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Very nice, very nice indeed.

- Steve
__________________
I feel old.
iNod is offline  
Old 01-27-2007, 03:39 PM   #3 (permalink)
Senior Member
 
RegisterRants's Avatar
Join Date: Oct 2006
Location: NJ
Posts: 1,147
RegisterRants has a spectacular aura aboutRegisterRants has a spectacular aura aboutRegisterRants has a spectacular aura about
 




The function imagecreatetrueimage() is not valid

Maybe its just my GD acting up.

Anyways, you have to move the header() call to the line before the include("ProgressBar.class.php"); line
__________________
Web Development
RegisterRants is offline  
Old 01-27-2007, 03:52 PM   #4 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,792
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
Works fine for me.
The header call just needs to be before any actual output, to it's fine where it is.
Dan is offline  
Old 01-27-2007, 03:57 PM   #5 (permalink)
Senior Member
 
RegisterRants's Avatar
Join Date: Oct 2006
Location: NJ
Posts: 1,147
RegisterRants has a spectacular aura aboutRegisterRants has a spectacular aura aboutRegisterRants has a spectacular aura about
 




I think that my GD is odd...gotta fix that.

Ah, I put some whitespace in the wrong place. That's why.
__________________
Web Development
RegisterRants is offline  
Old 02-04-2007, 07:33 AM   #6 (permalink)
Account Suspended
 
DeViAnThans3's Avatar
Join Date: Apr 2006
Location: Belgium
Posts: 442
DeViAnThans3 is a name known to allDeViAnThans3 is a name known to allDeViAnThans3 is a name known to allDeViAnThans3 is a name known to allDeViAnThans3 is a name known to allDeViAnThans3 is a name known to all
 



Great script! Rep updated
Thanks for nice scriptie
DeViAnThans3 is offline  
Old 02-04-2007, 07:37 AM THREAD STARTER               #7 (permalink)
NamePros Regular
Join Date: Mar 2006
Location: United Kingdom
Posts: 413
lee101 is a jewel in the roughlee101 is a jewel in the roughlee101 is a jewel in the rough
 




Thanks Hans
Just wondered if you've had any problems with it, it's the first time I''ve used GD and it [surprisingly] seems to be working

Lee
__________________
Linux Screenshots
lee101 is offline  
Old 02-04-2007, 06:55 PM   #8 (permalink)
 
BillyConnite's Avatar
Join Date: Jul 2005
Location: Coffs H, Australia
Posts: 3,456
BillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond repute
 


Wildlife Parkinson's Disease Parkinson's Disease
Nice one, although you might want to look into just using an image and resizing it to a percentage of the table it's in.
BillyConnite is offline  
Old 03-09-2007, 06:37 PM   #9 (permalink)
NamePros Member
Join Date: Nov 2005
Posts: 25
c0demonger is an unknown quantity at this point
 



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
????: NamePros.com http://www.namepros.com/showthread.php?t=285609

/*
 * 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($img00$Width$Height$color_back);

// draw highlighted percentage
imagefilledrectangle($img10$length$Height$color_highlight);
????: NamePros.com http://www.namepros.com/showthread.php?t=285609

// draw the border
imagerectangle($img00$Width 1$Height 1$color_line);

//Create Image
imagepng($img);

//Destroy temp image file
imagedestroy($img); 

?>
Might come in handy for some one


Cheers.
c0demonger is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 03:26 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger