note 111346 added to function.imagefilledrectangle
| From: | gidsnet at YOLO dot gmail dot com | Date: | Sat, 09 Feb 2013 21:44:03 +0000 |
| Subject: | note 111346 added to function.imagefilledrectangle | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-193569@lists.php.net to get a copy of this message | ||
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!
----
Server IP: 69.147.83.199
Probable Submitter: 74.132.166.220
----
Manual Page -- http://php.net/manual/en/function.imagefilledrectangle.php
Edit -- https://master.php.net/note/edit/111346
Del: integrated -- https://master.php.net/note/delete/111346/integrated
Del: useless -- https://master.php.net/note/delete/111346/useless
Del: bad code -- https://master.php.net/note/delete/111346/bad+code
Del: spam -- https://master.php.net/note/delete/111346/spam
Del: non-english -- https://master.php.net/note/delete/111346/non-english
Del: in docs -- https://master.php.net/note/delete/111346/in+docs
Del: other reasons-- https://master.php.net/note/delete/111346
Reject -- https://master.php.net/note/reject/111346
Search -- https://master.php.net/manage/user-notes.php