Welcome and have a nice stay !       login   register   need help?  

 Page Info

Page Title: GD Based PHP Statusbar
Description: PHP Status Bar Indicator based on GD
Author: brian420
Submission Date: 17-09-2005 03:49

 Rating & Comments

View or add comments: (0)
Average members rating: 0



Here is a simple way to create a PHP based progress/status bar, which can also be used for ratings.

This uses the GD Graphical Library, so it must be installed on your webserver for it to function properly.

This PHP script draws a progress/status/ratings bar to the screen using an tag in your HTML, which will be described below.

First, open your favorite PHP editor, create a file called "statusbar.php" and insert the following code.

Code :
// hide source code
// hide line numbers

 1  <?php
 2  
function drawRating($rating) {
 3     
$width = isset($_GET['width']) ? $_GET['width'] : 50;
 4     
$height = isset($_GET['height']) ? $_GET['height'] : 10;
 5     
$ratingbar = (($rating/100)*$width)-2;
 6     
$image imagecreate($width,$height);
 7     
 8     
 9     
//Change the colors here using RGB
10     
$back ImageColorAllocate($image,50,50,50);
11     
$border ImageColorAllocate($image,150,150,150);
12     
$red ImageColorAllocate($image,255,0,0);
13     
$darkred ImageColorAllocate($image,170,0,0);
14     
$black ImageColorAllocate($image,0,0,0);
15     
$pipcolor ImageColorAllocate($image,100,100,100);
16  
17  
18     
$darkGreen ImageColorAllocate($image,0,170,0);
19     
$green ImageColorAllocate($image,0,255,0);
20  
21     
ImageFilledRectangle($image,0,0,$width-1,$height-1,$back);
22     if(
$rating >= 50)
23     {
24      
ImageFilledRectangle($image,1,1,$ratingbar,10,$darkGreen);
25      
ImageFilledRectangle($image,1,1,$ratingbar,$height-4,$green);
26     }
27     else
28     {
29      
ImageFilledRectangle($image,1,1,$ratingbar,10,$darkRed);
30      
ImageFilledRectangle($image,1,1,$ratingbar,$height-4,$red);
31     }
32  
33  
//Sets PIP marks
34     
for($i 0$i <= 5$i++)
35     {
36      
$pip $i 10;
37      
ImageLine($image,$pip,1,$pip,10,$pipcolor);
38     }
39  
40     
ImageRectangle($image,0,0,$width-1,$height-1,$border);
41     
imagePNG($image);
42     
imagedestroy($image);
43  
44  
45  }
46  
Header("Content-type: image/png");
47  
drawRating($_REQUEST['rating']);
48  
?>



Create an html page, something like statusbar.html and place the example tag below, into the HTML.

Code :
// hide source code
// hide line numbers

1  <img src="/statusbar.php?rating=50" alt="Rated 50/100" />



This will display the progress/status/ratings bar at 50/100.

You can modify the colors using RGB in the PHP code to change the colors of the progress bar.

Donation:

If you like our free quality work, make a donation by using Paypal and tell us what you would like to see improved on our site for the next few months.

Comments


No comments yet

 Site Activity
Currently online: 0 member(s), 40 guest(s) : All members offline.


 Quick Menu
sitemap
search
galleries
main
forums


 Our Services

Main Projects
Designers For Hire
Unique LDU Skins
LDU Skins For Sale
Seditio Skins For Sale
Templates For Sale


 Statistics
18582 registered members,
1870 topics in forums,
21586 posts in forums,
13589708 pages served since 2004-05-09.
more


 7th Version Design

+++
top