The imagefilltoborder() function is an inbuilt function in PHP which is used to performs a flood fill with a specific color and add a border with a border color.
Syntax:
bool imagefilltoborder( resource $image, int $x, int $y, int $border, int $color )
Parameters: This function accept five parameters as mentioned above and described below:
- $image: It specifies the image to be worked upon.
- $x: It specifies the x-coordinate of start.
- $y: It specifies the y-coordinate of start.
- $border: It specifies the border color.
- $color: It specifies the fill color.
Return Value: This function returns TRUE on success or FALSE on failure.
Exceptions: This function throws Exception on error.
Below given programs illustrate the imagefilltoborder() function in PHP:
Program 1 (Adding fill color to a image):
<?php // Load the png image $im = imagecreatefrompng( // Create colors $borderColor = imagecolorallocate( $im , 0, 200, 0); $fillColor = imagecolorallocate( $im , 0, 0, 200); // Add fill to border imagefilltoborder( $im , 0, 0, $borderColor , $fillColor ); // Show the output header( 'Content-type: image/png' ); imagepng( $im ); ?> |
Output:
Program 2 (Adding fill color to a drawing):
<?php // Create the image handle, set the background to white $im = imagecreatetruecolor(800, 250); imagefilledrectangle( $im , 0, 0, 800, 250, imagecolorallocate( $im , 0, 255, 0)); // Draw an ellipse to fill with a black border imageellipse( $im , 250, 150, 250, 150, imagecolorallocate( $im , 0, 0, 0)); // Fill the selection imagefilltoborder( $im , 50, 50, imagecolorallocate( $im , 0, 0, 0), imagecolorallocate( $im , 255, 0, 0)); // Output the image header( 'Content-type: image/png' ); imagepng( $im ); ?> |
Output:
Reference: https://www.php.net/manual/en/function.imagefilltoborder.php