[advanced search]
Results from the most recent live auction are here.
15 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read

System Maintenance: NamePros will be offline for 20 minutes at the top of the hour (4AM EST)

Go Back   NamePros.Com > Design and Development > Programming > CODE
User Name
Password

Old 01-24-2007, 11:16 AM   · #1
lee101
NamePros Regular
 
Name: Lee
Location: United Kingdom
Trader Rating: (8)
Join Date: Mar 2006
Posts: 343
NP$: 2.90 (Donate)
lee101 is a jewel in the roughlee101 is a jewel in the roughlee101 is a jewel in the rough
Arrow [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
        
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);
    }
};
?>

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
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


Please register or log-in into NamePros to hide ads
__________________
http://bypasstopsite.com - Submit your proxy!
http://biggertwitter.com - Make twitter a bit bigger!
Currently Developing - Linux Screenshots
lee101 is offline   Reply With Quote
Old 01-24-2007, 11:19 AM   · #2
iNod
Eating Pie
 
iNod's Avatar
 
Name: Steve
Location: Canada
Trader Rating: (66)
Join Date: Nov 2004
Posts: 2,280
NP$: 87.30 (Donate)
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
__________________
RegisterDub.com - 200th Customer Milestone
ZuneParts.net - International Zune Parts and Accessories
FeaturedFont.com - One Top Free Font a Day!
iNod is offline   Reply With Quote
Old 01-27-2007, 03:39 PM   · #3
RegisterRants
DNOA Member
 
RegisterRants's Avatar
 
Name: Jason
Trader Rating: (11)
Join Date: Oct 2006
Posts: 1,143
NP$: 257.37 (Donate)
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  
  Reply With Quote
Old 01-27-2007, 03:52 PM   · #4
Dan
Buy my domains.
 
Dan's Avatar
 
Name: Dan
Trader Rating: (63)
Join Date: Feb 2006
Posts: 2,800
NP$: 54.00 (Donate)
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   Reply With Quote
Old 01-27-2007, 03:57 PM   · #5
RegisterRants
DNOA Member
 
RegisterRants's Avatar
 
Name: Jason
Trader Rating: (11)
Join Date: Oct 2006
Posts: 1,143
NP$: 257.37 (Donate)
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  
  Reply With Quote
Old 02-04-2007, 07:33 AM   · #6
DeViAnThans3
Spamzor.com
 
DeViAnThans3's Avatar
 
Name: Hans
Location: Belgium
Trader Rating: (35)
Join Date: Apr 2006
Posts: 442
NP$: 22.35 (Donate)
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
__________________
Useless is cool!
Work From Home Opportunities -
1 link ... 1 month ... 5 NP$ ] Real bargain! Limited to 1 month.
DeViAnThans3 is offline   Reply With Quote
Old 02-04-2007, 07:37 AM   · #7
lee101
NamePros Regular
 
Name: Lee
Location: United Kingdom
Trader Rating: (8)
Join Date: Mar 2006
Posts: 343
NP$: 2.90 (Donate)
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
__________________
http://bypasstopsite.com - Submit your proxy!
http://biggertwitter.com - Make twitter a bit bigger!
Currently Developing - Linux Screenshots
lee101 is offline   Reply With Quote
Old 02-04-2007, 06:55 PM   · #8
BillyConnite
 
BillyConnite's Avatar
 
Name: Rhett
Location: Coffs H, Australia
Trader Rating: (77)
Join Date: Jul 2005
Posts: 3,106
NP$: 47.00 (Donate)
BillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant future
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.
__________________
<?php if(1===1){ $computer="fine."; }else{ $computer="broken."; } echo "Your computer is ".$computer; ?>
BillyConnite is offline   Reply With Quote
Old 03-09-2007, 06:37 PM   · #9
c0demonger
NamePros Member
 
Trader Rating: (3)
Join Date: Nov 2005
Posts: 28
NP$: 0.00 (Donate)
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

/*
* 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.
c0demonger is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


Site Sponsors
Hunting Moon http://www.dnfinder.com Build your NameBrand
Advertise your business at NamePros
All times are GMT -7. The time now is 12:04 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0