note 111346 deleted from function.imagefilledrectangle by danbrown
| From: | danbrown@php.net | Date: | Tue, 05 Mar 2013 16:09:02 +0000 |
| Subject: | note 111346 deleted from function.imagefilledrectangle by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193921@lists.php.net to get a copy of this message | ||
Note Submitter: gidsnet at YOLO dot gmail dot com
----
I stole this, and found that it still needed a couple of tweaks.
1st the img url for syntax.
2nd added $borderset = $_GET['border'] & removed imagerectangle putting a new
imagefilledrectangle at the top then plugged $borderset in where appropriate.
Now draws 3 filled rectangles 1 border, 1 back fill, and the actual rating bar.
Each of them sized according to the $_GET info.
<?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'];
$borderset = $_GET['border'];
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,0,0,0);
$border = ImageColorAllocate($image,255,255,255);
$red = ImageColorAllocate($image,255,60,75);
$fill = ImageColorAllocate($image,102, 204, 153);
ImageFilledRectangle($image,0,0,$width,$height,$border);
ImageFilledRectangle($image,$borderset,$borderset,$width-$borderset,$height-$borderset,$back);
ImageFilledRectangle($image,$borderset,$borderset,$ratingbar,$height-$borderset,$fill);
imagePNG($image);
imagedestroy($image);
}
Header("Content-type: image/png");
drawRating($rating);
?>
Hope this helps.
Thnx to both the original poster, and the earlier editor.
This function really is handy for what I needed on my site!