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.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP imagefill() Function: Area Fill in Images

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);
?>
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendImage ProcessingPHPGDimagefill
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.