imagefilledrectangle 


gd apg

DRAW filled regular quads, (rectangles or squares), in an image.





Square is a special kind of rectangle, it is one where all the sides have the same length.

Thus every square is a rectangle because it is a quadrilateral with all four angles right angles.

However not every rectangle is a square, to be a square its sides must have the same length.

From: Math Central.

This function returns TRUE on success or FALSE on failure.



<?php

bool imagefilledrectangle 
GdImage $image,
                                                     
int $x1int $y1
                                                     
int $x2int $y2
                                                                  
int $color )

where,

$image The image identifier

$x1 
The upper left x-coordinate the start point 

$y1 
The upper left y-coordinate the start point 

$x2 
The botton right x-coordinate the end point 

$y2 
The botton right y-coordinate the end point 

$color 
The fill color as returned by imagecolorallocate

?>
 

  $image   


The image identifier.



  $x1   


The upper left x-coordinate for point 1.



  $y1   


The upper left y-coordinate for point 1.



  $x2   


The botton right x-coordinate for point 2.



  $y2   


The botton right y-coordinate for point 2.



  $color   


The fill color, a color identifier created by imagecolorallocate.



  1 EXERCISE   

 <?php

$base_img 
"png/baseXx.png";

$dest_img 'png/PNG 059 01-imagefilledrectangle.png';

$id_retsq imagecreatefrompng($base_img);

$bg =    imagecolorallocate($id_retsq221,238,255);
$red =   imagecolorallocate($id_retsq25500);
$green imagecolorallocate($id_retsq02550);
$blue =  imagecolorallocate($id_retsq00255);
$magenta imagecolorallocate($id_retsq1960238);
$black =   imagecolorallocate($id_retsq000);

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
  parameters of a square, (blue outline), 
  WITHOUT STYLE
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 
  
$x0_blue 30;
$y0_blue 30;
$xN_blue 80;
$yN_blue 80;

imagefilledrectangle($id_retsq$x0_blue$y0_blue
                                                 
$xN_blue$yN_blue
                                                                 
$blue); 

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   parameters of a rectangle, (magenta outline), 
   WITHOUT STYLE
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 

$x0_magenta 50;
$y0_magenta 50;
$xN_magenta 325;
$yN_magenta 250;

imagefilledrectangle($id_retsq$x0_magenta
                                                  
$y0_magenta
                                                  
$xN_magenta
                                                  
$yN_magenta
                                                  
$magenta); 

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  parameters of a square, (red outline), 
  WITH STYLE
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 
$x0_red 120;
$y0_red 120;
$xN_red 260;
$yN_red 260

$style_red_bg = array ( $red$red$red$bg$bg$bg );
imagesetstyle($id_retsq$style_red_bg);
imagefilledrectangle($id_retsq$x0_red$y0_red
                                                 
$xN_red$yN_red
                                                 
IMG_COLOR_STYLED ); 

imagepng($id_retsq$dest_img);
?>

<?php echo $dest_img?>
<br><br><img src="<?php echo 
$dest_img?>" alt="<?php echo $dest_img?>"> 


 RESULT   

PNG 059 01-imagefilledrectangle.png

PNG 059 01-imagefilledrectangle.png apr