
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
Flood fill to specific color in PHP using imagefilltoborder() (GD) function.
imagefilltoborder() is an inbuilt function in PHP that is used to perform flood fill with a specific color, whose border color is defined by the border. The starting point for the fill is (x,y) or top left is (0, 0) and the region is filled with the color.
Syntax
bool imagefilltoborder(resource $image, int $x, int $y, int $border, int $color)
Parameters
imagefilltoborder() takes five different parameters: $image, $x, $y, $border, and $color.
$image − It is the image resource.
$x − Specifies the x-coordinate of start.
$y − Specifies the y- coordinate of start.
$border − Specifies the border color.
$color − Specifies the color.
Return Values
It returns True on success and False on failure.
Example 1
<?php // Load the GIF image from local drive folder. $img = imagecreatefromgif('C:\xampp\htdocs\Images\img39.gif'); // Create the image colors $borderColor = imagecolorallocate($img, 0, 200, 0); $fillColor = imagecolorallocate($img, 122, 122, 122); // Add fill to border imagefilltoborder($img, 0, 0, $borderColor, $fillColor); // Show the output image header('Content-type: image/gif'); imagepng($img); ?>
Output
Gif image before using the imagefilltoborder() function in PHP.
Gif image after using the imagefilltoborder() function in PHP.
Example 2: Fill an ellipse with a color
<?php // Created the image, set the background to gray color $img = imagecreatetruecolor(700, 500); imagefilledrectangle($img, 0, 0, 500, 500,imagecolorallocate($img, 122, 122, 122)); // Draw an ellipse to fill with a black border. imageellipse($img, 300, 300, 300, 300, imagecolorallocate($img, 0, 0, 0)); // Set the border and fill using the blue colors $border = imagecolorallocate($img, 0, 0, 0); $fill = imagecolorallocate($img, 0, 0, 255); // Fill the selection imagefilltoborder($img, 300, 300, $border, $fill); // show the output image and free memory header('Content-type: image/gif'); imagepng($img); imagedestroy($img); ?>
Output
- Related Articles
- Flood fill algorithm using C graphics
- Flood fill Algorithm
- Flood fill Algorithm – how to implement fill() in paint in C++
- Difference Between Flood-fill and Boundary-fill Algorithm
- How to draw a partial arc and fill it using imagefilledarc() function in PHP?
- Program to fill with color using floodfill operation in Python
- How to apply a gamma correction to a Graphics Draw (GD) image in PHP?
- How to set the fill color of Ellipse using FabricJS?
- How to set the fill color of a Circle using FabricJS?
- How to create a new true-color image in PHP using imagecreatetruecolor()?
- How to fill color below a curve in Matplotlib?
- How to get resource ID using get_resource_id() function in PHP and PHP 8?
- How to fill color above the curve in Matplotlib Program?
- How to destroy an image in PHP using imagedestroy() function?
- How to draw an ellipse using imageellipse() function in PHP?

Advertisements