note 64468 added to function.imagefilledrectangle
| From: | spam at junk dot dk | Date: | Fri, 14 Apr 2006 22:42:49 +0000 |
| Subject: | note 64468 added to function.imagefilledrectangle | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-108120@lists.php.net to get a copy of this message | ||
A different kind of rating bar, using michal's rounded corners function :) I saw this type of
rating bar somewhere and thought it looked cool, so the 'design' is a complete ripoff.
Also, note that it scales quite well, from tiny 3x3 pixel dots to huge 300x300 pixel blocks. (Man am
I proud of this thing.. well, enjoy!)
/Scarpia
<?php
Header("Content-type: image/png");
drawRatingBlocks($rating);
function drawRatingBlocks($rating) {
$rating = $_GET['rating'];
$width = $_GET['width'];
$height = $_GET['height'];
$blocks = $_GET['blocks'];
if ($width == 0) $width = 130;
if ($height == 0) $height = 13;
$spacing = max(1, floor($height/6) );
if ($blocks == 0) $blocks = floor( $width / ($height-2 + $spacing) );
$blockwidth = floor( $width / $blocks ) - $spacing;
$short_side = min($height-2, $blockwidth);
$blockvalue = 100 / $blocks;
$image = ImageCreate($width,$height);
$img2 = ImageCreate($width,$height);
// Define base colors
$back = ImageColorAllocate($image,255,255,255);
$blur = ImageColorAllocate($image,230,223,188);
$fill = ImageColorAllocate($image,188,182,133);
$lightblur = ImageColorAllocate($image,238,235,216); // Would be nice to calculate these
dynamically instead
$lightfill = ImageColorAllocate($image,221,217,193); // Would be nice to calculate these
dynamically instead
ImagePaletteCopy($img2,$image);
ImageFilledRectangle($image,0,0,$width-1,$height-1,$back);
ImageFilledRectangle($img2,0,0,$width-1,$height-1,$back);
if ($short_side < 25)
$radius = 1;
else if ($short_side < 40)
$radius = 3;
else if ($short_side < 50)
$radius = 5;
else
$radius = floor($height/10);
for($i=0;$i<$blocks;$i++) {
$startX = ($blockwidth+$spacing)*$i + 1;
if ((9 <= $short_side) && ($short_side <= 16))
{
ImageFilledRectangle($image, $startX, 1, $startX+$blockwidth-1, $height-2, $lightblur);
ImageFilledRectangle($img2, $startX, 1, $startX+$blockwidth-1, $height-2, $lightfill);
}
ImageRectangleWithRoundedCorners($image, $startX, 1, $startX+$blockwidth-1, $height-2,
$radius, $blur);
ImageRectangleWithRoundedCorners($img2, $startX, 1, $startX+$blockwidth-1, $height-2,
$radius, $fill);
}
$barwidth = ($rating/100)*$blocks*$blockwidth;
$barwidth += floor($barwidth/$blockwidth)*$spacing+1;
ImageCopy( $image, $img2, 0, 0, 0, 0, $barwidth, $height );
ImageDestroy($img2);
ImagePNG($image);
ImageDestroy($image);
}
function ImageRectangleWithRoundedCorners(&$im, $x1, $y1, $x2, $y2, $radius, $color)
{
// Draw rectangle without corners
ImageFilledRectangle($im, $x1+$radius, $y1, $x2-$radius, $y2, $color);
ImageFilledRectangle($im, $x1, $y1+$radius, $x2, $y2-$radius, $color);
// Draw circled corners
ImageFilledEllipse($im, $x1+$radius, $y1+$radius, $radius*2, $radius*2, $color);
ImageFilledEllipse($im, $x2-$radius, $y1+$radius, $radius*2, $radius*2, $color);
ImageFilledEllipse($im, $x1+$radius, $y2-$radius, $radius*2, $radius*2, $color);
ImageFilledEllipse($im, $x2-$radius, $y2-$radius, $radius*2, $radius*2, $color);
}
?>
----
Server IP: 195.184.96.15
Probable Submitter: 212.242.155.159
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.imagefilledrectangle.php
Edit -- http://master.php.net/note/edit/64468
Del: integrated -- http://master.php.net/note/delete/64468/integrated
Del: useless -- http://master.php.net/note/delete/64468/useless
Del: bad code -- http://master.php.net/note/delete/64468/bad+code
Del: spam -- http://master.php.net/note/delete/64468/spam
Del: non-english -- http://master.php.net/note/delete/64468/non-english
Del: in docs -- http://master.php.net/note/delete/64468/in+docs
Del: other reasons-- http://master.php.net/note/delete/64468
Reject -- http://master.php.net/note/reject/64468
Search -- http://master.php.net/manage/user-notes.php