PHP | imagefill() Function (original) (raw)

Last Updated : 11 Jul, 2025

The imagefill() function is an inbuilt function in PHP which is used to fill the image with the given color. This function performs a flood fill starting at the given coordinate (top left is 0, 0) with the given color in the image. Syntax:

bool imagefill( image,image, image,x, y,y, y,color )

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

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

php `

green=imagecolorallocate(green = imagecolorallocate(green=imagecolorallocate(image, 0, 153, 0); imagefill($image, 0, 0, $green); header('Content-type: image/png'); imagepng($image); imagedestroy($image); ?>

`

Output: image filled Program 2:

php `

bg=imagecolorallocate(bg = imagecolorallocate(bg=imagecolorallocate(image, 205, 220, 200); // Fill background with above selected color. imagefill($image, 0, 0, $bg); // Set the color of an ellipse. colellipse=imagecolorallocate(col_ellipse = imagecolorallocate(colellipse=imagecolorallocate(image, 0, 102, 0); // Function to draw the filled ellipse. imagefilledellipse($image, 250, 150, 400, 250, $col_ellipse); // Output of the image. header("Content-type: image/png"); imagepng($image); ?>

`

Output: image filled Related Articles:

Reference: https://www.php.net/manual/en/function.imagefill.php