Show DevBest [PHP] [WITH SOURCE] Simple Progress Bar

Status
Not open for further replies.

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
This is just a simple progress bar script I made with in 30 minutes in PHP.

It gets the value of the percentage from the URL via $_GET and if it is empty, not numeric or it is more than 100, it will set its default value to 100.
The script also writes the value of percentage slap-bang in the centre of the image.

I will post the script below, but you will need to manually save the images yourself, alternatively, you can download the full package by .

progressbar.php
PHP:
<?php
//fix headers
ob_start();

//create the image
$progress = imagecreate( 208, 28 );

//start the image
$start = imagecreatefrompng( "start.png" );
imagecopy( $progress, $start, 0, 0, 0, 0, imagesx( $start ), imagesy( $start ) );

//get value of percentage
$percent = strip_tags( $_GET['p'] );
if( ( empty( $percent ) ) || ( $percent > 100 ) || ( !is_numeric( $percent ) ) ) $percent = "100";

//put the middle image in
$middle = imagecreatefrompng( "middle.png" );
for( $i = 6; $i <= ( $percent * 2 ); $i++ )
{
	imagecopy( $progress, $middle, $i, 0, 0, 0, imagesx( $middle ), imagesy( $middle ) );
}

//put the percentage value in text
$black = imagecolorallocate( $progress, 0, 0, 0 );
imagestring( $progress, 4, ( $i / 2 ) - 7, 6, $percent . "%", $black );

//end the image
$end = imagecreatefrompng( "end.png" );
imagecopy( $progress, $end, $i, 0, 0, 0, imagesx( $end ), imagesy( $end ) );

//output the image
header( "Content-Type: image/PNG" );
imagepng( $progress );
imagedestroy( $progress );

ob_flush();
?>

Save these images in the same directory as progessbar.php

start.png
start.png


middle.png
middle.png


end.png
end.png


I hope you enjoy this, if you use this please leave credits ;)

If you want to see a live demo to this, click

The Password to the .RAR file is (as always)
Code:
m0nstadot

Thanks,
- m0nsta.
 

NaziPhreak

Member
Mar 24, 2011
33
0
Looks very useful,Thank you M0nsta. for another useful script.

Going to use this on my image uploader website.I hope I know what I'm doing.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
Looks very useful,Thank you M0nsta. for another useful script.

Going to use this on my image uploader website.I hope I know what I'm doing.

You're welcome, glad you like it. And good luck with that ;P
 
Status
Not open for further replies.

Users who are viewing this thread

Top