search for in the  
<imagefilledpolygonimagefilltoborder>
Last updated: Thu, 19 May 2005

imagefilledrectangle

(PHP 3, PHP 4, PHP 5)

imagefilledrectangle -- Draw a filled rectangle

Description

int 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) {
// 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);
}

?>
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

// 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);

?>
booga
17-Jan-2004 07:48
a simple way of using imagerectangle to create a percentage bar

<?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="ratingpng.php?rating=25.2" border="0">

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.

<imagefilledpolygonimagefilltoborder>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT