note 42734 added to function.imagefilledrectangle
| From: | sdonie at lgc dot com | Date: | Thu, 27 May 2004 14:19:12 +0000 |
| Subject: | note 42734 added to function.imagefilledrectangle | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70188@lists.php.net to get a copy of this message | ||
I made some simple additions to the 'ratings bar' example above to allow for different
sizes. It also doesn't assume that global GET variables is turned on, and explicitly looks for
parameters it needs.
----
<?php
// copied from the PHP manual:
// http://us3.php.net/manual/en/function.imagefilledrectangle.php
//this needs to reside in its own php page
//you can include that php page in your html as you would an image:
//<IMG SRC="makebar.php?rating=25.2&width=200&height=20"
border="0">
// rating is a percentage from 0 to 100.
function drawRating($rating) {
$width = $_GET['width'];
$height = $_GET['height'];
if ($width == 0) {
$width = 102;
}
if ($height == 0) {
$height = 10;
}
$rating = $_GET['rating'];
$ratingbar = (($rating/100)*$width)-2;
$image = imagecreate($width,$height);
//colors
$back = ImageColorAllocate($image,255,255,255);
$border = ImageColorAllocate($image,0,0,0);
$red = ImageColorAllocate($image,255,60,75);
$fill = ImageColorAllocate($image,44,81,150);
ImageFilledRectangle($image,0,0,$width-1,$height-1,$back);
ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$fill);
ImageRectangle($image,0,0,$width-1,$height-1,$border);
imagePNG($image);
imagedestroy($image);
}
Header("Content-type: image/png");
drawRating($rating);
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagefilledrectangle.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42734
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42734&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42734&report=yes
Search -- http://master.php.net/manage/user-notes.php