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, $x, $y, $color )
Parameters:This function accepts four 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.
- $x: This parameter is used to set x-coordinate of starting point.
- $y: This parameter is used to set y-coordinate of starting point.
- $color: It sets the color of image. A color identifier created by imagecolorallocate() function.
Return Value: This function returns True on success of False on failure.
Below programs illustrate the imagefill() function in PHP:
Program 1:
<?php
$image = imagecreatetruecolor(500, 400);
$green = imagecolorallocate( $image , 0, 153, 0);
imagefill( $image , 0, 0, $green );
header( 'Content-type: image/png' );
imagepng( $image );
imagedestroy( $image );
?>
|
Output:

Program 2:
<?php
$image = imagecreatetruecolor(500, 300);
$bg = imagecolorallocate( $image , 205, 220, 200);
imagefill( $image , 0, 0, $bg );
$col_ellipse = imagecolorallocate( $image , 0, 102, 0);
imagefilledellipse( $image , 250, 150, 400, 250, $col_ellipse );
header( "Content-type: image/png" );
imagepng( $image );
?>
|
Output:

Related Articles:
Reference: http://php.net/manual/en/function.imagefill.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