PHP | imagefill() Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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 <?php // Create an image of given size $image = imagecreatetruecolor(500, 400); // Sets background to green $green = imagecolorallocate($image, 0, 153, 0); imagefill($image, 0, 0, $green); header('Content-type: image/png'); imagepng($image); imagedestroy($image); ?> Output: Program 2: php <?php // It create the size of image or blank image. $image = imagecreatetruecolor(500, 300); // Set the background color of image. $bg = imagecolorallocate($image, 205, 220, 200); // Fill background with above selected color. imagefill($image, 0, 0, $bg); // Set the color of an ellipse. $col_ellipse = 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: Related Articles: PHP | imagecolorallocatealpha() Function PHP | imagearc() Function PHP | imageellipse() Function Reference: https://www.php.net/manual/en/function.imagefill.php Create Quiz Comment V vijay_raj Follow 0 Improve V vijay_raj Follow 0 Improve Article Tags : Misc Web Technologies PHP Image-Processing PHP-function +1 More Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like