The Wayback Machine - https://web.archive.org/web/20231211192513/https://www.geeksforgeeks.org/php-imagefilledrectangle-function/
Open In App
Related Articles

PHP | imagefilledrectangle() Function

Improve Article
Improve
Save Article
Save
Like Article
Like

The imagefilledrectangle() function is an inbuilt function in PHP which is used to create a filled rectangle. This function creates a rectangle filled with a given color in the image. The top left corner of the image is (0, 0).

Syntax:

bool imagefilledrectangle( $image, $x1, $y1, $x2, $y2, $color )

Parameters: This function accepts six parameters as mentioned above and described below:

  • $image: It is returned by one of the image creation functions, such as imagecreatetruecolor(). It is used to create size of image.
  • $x1: This parameter is used to set the x-coordinate for point 1.
  • $y1: This parameter is used to set the y-coordinate for point 1.
  • $x2: This parameter is used to set the x-coordinate for point 2.
  • $y2: This parameter is used to set the y-coordinate for point 2.
  • $color: This parameter contains the filled color identifier. A color identifier created with imagecolorallocate() function.

Return Value: This function returns True on success or False on failure.

Below programs illustrate the imagefilledrectangle() function in PHP:

Program 1:




<?php
  
// Create an image of given size
$image = imagecreatetruecolor(500, 300);
$green = imagecolorallocate($image, 0, 153, 0);
  
// Draw the rectangle of green color
imagefilledrectangle($image, 20, 20, 480, 280, $green);
  
// Output image in png format
header("Content-type: image/png");
imagepng($image);
   
// Free memory
imagedestroy($image);
?>


Output:
imagerectanglefilled

Program 2:




<?php
  
// Create an image of given size
$image = imagecreatetruecolor(500, 300);
$white = imagecolorallocate($image, 255, 255, 255);
  
// Draw the rectangle of white color
imagefilledrectangle($image, 20, 20, 480, 280, $white);
  
// Output image
header("Content-type: image/png");
imagepng($image);
   
// Free memory
imagedestroy($image);
?>


Output:
imagerectanglefilled

Related Articles:

Reference: http://php.net/manual/en/function.imagefilledrectangle.php


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 23 Aug, 2019
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials