PHP | imagefilledrectangle() Function (original) (raw)

Last Updated : 11 Jul, 2025

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,image, image,x1, y1,y1, y1,x2, y2,y2, y2,color )

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

Return Value: This function returns True on success or False on failure. Below programs illustrate the imagefilledrectangle() function in PHP:Program 1:

php `

green=imagecolorallocate(green = imagecolorallocate(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 `

white=imagecolorallocate(white = imagecolorallocate(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: https://www.php.net/manual/en/function.imagefilledrectangle.php