/    Sign up×
Community /Pin to ProfileBookmark

Rating bar error.

Not desplaying

[code=php]
<?php
$free = disk_free_space(“./”);
$total = disk_total_space(“./”);
$left = $total-$free;
$inBar = 100*$left/$total;
?>
<img src=”ratingbar.php?rating=<?php round($inBar);?>” border=”0″>
[/code]

ratingbar.php:

[code=php]
<?php
function rating($rating) {
$width = $_GET[‘width’];
$height = $_GET[‘height’];
if ($width == 0) {
$width = 300;
}
if ($height == 0) {
$height = 15;
}

$rating = $_GET[‘rating’];
$ratingbar = (($rating/100)*$width)-2;

$image = imagecreate($width,$height);

$fill = ImageColorAllocate($image,0,255,0);

$backgrd = ImageColorAllocate($image,255,255,255);
$border = ImageColorAllocate($image,0,0,0);

ImageFilledRectangle($image,0,0,$width-1,$height-1,$backgrd);
ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$fill);
ImageRectangle($image,0,0,$width-1,$height-1,$border);
imagePNG($image);
imagedestroy($image);
}

haeder(“Content-type: image/png”);
rating($rating);

?>
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 28.2007 — I played around with the image script a bit, and came up with this working version:
[code=php]
<?php
// no need for a function, since this is all the script does....
header("Content-type: image/png"); // header() was spelled wrong in original
// streamlined setting of default values
$width = (!empty($_GET['width'])) ? (int)$_GET['width'] : 300;
$height = (!empty($_GET['height'])) ? (int)$_GET['height'] : 15;
$rating = (!empty($_GET['rating'])) ? (int)$_GET['rating'] : 1;
// use max() so that we do not get a negative number
$ratingbar = max((($rating/100)*$width)-2, 0);
$image = imagecreate($width,$height);
$fill = ImageColorAllocate($image,0,255,0);
$backgrd = ImageColorAllocate($image,255,255,255);
$border = ImageColorAllocate($image,0,0,0);
ImageFilledRectangle($image,0,0,$width-1,$height-1,$backgrd);
ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$fill);
ImageRectangle($image,0,0,$width-1,$height-1,$border);
imagePNG($image);
imagedestroy($image);
/*
no closing PHP tag at end so stray spaces/newlines after it
do not get output
*/
[/code]
×

Success!

Help @bradmasterx spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...