PHP | imagefilltoborder() Function
Last Updated :
31 Jan, 2020
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
$im = imagecreatefrompng(
$borderColor = imagecolorallocate( $im , 0, 200, 0);
$fillColor = imagecolorallocate( $im , 0, 0, 200);
imagefilltoborder( $im , 0, 0, $borderColor , $fillColor );
header( 'Content-type: image/png' );
imagepng( $im );
?>
|
Output:
Program 2 (Adding fill color to a drawing):
<?php
$im = imagecreatetruecolor(800, 250);
imagefilledrectangle( $im , 0, 0, 800,
250, imagecolorallocate( $im , 0, 255, 0));
imageellipse( $im , 250, 150, 250, 150,
imagecolorallocate( $im , 0, 0, 0));
imagefilltoborder( $im , 50, 50, imagecolorallocate( $im ,
0, 0, 0), imagecolorallocate( $im , 255, 0, 0));
header( 'Content-type: image/png' );
imagepng( $im );
?>
|
Output:
Reference: https://www.php.net/manual/en/function.imagefilltoborder.php
Share your thoughts in the comments
Please Login to comment...