|
|
 |
imagefilledrectangle (PHP 3, PHP 4, PHP 5) imagefilledrectangle -- Draw a filled rectangle Descriptionint imagefilledrectangle ( resource image, int x1, int y1, int x2, int y2, int color )
imagefilledrectangle() creates a filled
rectangle of color color in image
image starting at upper left coordinates
x1, y1 and ending
at bottom right coordinates x2,
y2. 0, 0 is the top left corner of the
image.
User Contributed Notes
imagefilledrectangle
michal dot kocarek at seznam dot cz
30-May-2004 03:18
If you want to draw a rectangle with rounded corners, you can use this simple function...
Rectangle starts at x1y1 and ends at x2y2. $radius defines radius of circled corner.
<?
function ImageRectangleWithRoundedCorners(&$im, $x1, $y1, $x2, $y2, $radius, $color) {
imagefilledrectangle($im, $x1+$radius, $y1, $x2-$radius, $y2, $color);
imagefilledrectangle($im, $x1, $y1+$radius, $x2, $y2-$radius, $color);
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);
}
?>
sdonie at lgc dot com
27-May-2004 12:19
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
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);
$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);
?>
booga
17-Jan-2004 07:48
a simple way of using imagerectangle to create a percentage bar
<?php
function drawRating($rating) {
$image = imagecreate(102,10);
$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,101,9,$back);
ImageFilledRectangle($image,1,1,$rating,9,$fill);
ImageRectangle($image,0,0,101,9,$border);
imagePNG($image);
imagedestroy($image);
}
Header("Content-type: image/png");
drawRating($rating);
?>
ivank at 2xtreme dot net
30-Mar-2002 06:34
As stated above, it needs to go from the top left corner to the bottom right corner. Just use this to flip it if neccessary:
// flip them if neccessary (x3, y3 are temp vars)
if($x1 > $x2) { $x3 = $x2; $x2 = $x1; $x1 = $x3; }
if($y1 > $y2) { $y3 = $y2; $y2 = $y1; $y1 = $y3; }
ImageFilledRectangle($im, $x1, $y1, $x2, $y2, $color);
saramg at uclink dot berkeley dot edu
29-Nov-2001 09:42
Important quirk to note:
While imagerectangle will allow you to use a different order of your coordinates (such as bottom-left to upper-right), imagefilledrectangle will only work correctly if you use top-left to bottom-right as indicated in the docs.
| |