PHP imagefill() Function: Area Fill in Images
This article explains PHP's imagefill() function, detailing its purpose for region filling in images, describing each parameter (image resource, x and y coordinates, and color), the return values, and provides a complete example script demonstrating its usage.
The imagefill() function fills an area of an image with a specified color, starting from the given x and y coordinates. The fill spreads to all adjacent pixels that share the same color as the starting point.
Parameters
image : The image resource created by functions such as imagecreatetruecolor() .
x : The x-coordinate of the start point.
y : The y-coordinate of the start point.
color : The color to use for filling, allocated with imagecolorallocate() .
Return Value
Returns the image resource on success, or FALSE on failure.
Example
<?php
$im = imagecreatetruecolor(100, 100);
// Set background to red
$red = imagecolorallocate($im, 255, 0, 0);
imagefill($im, 0, 0, $red);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.