PHP 8.1.0 Beta 2 available for testing


(PECL imagick 2 >= 2.3.0, PECL imagick 3)

Imagick::floodFillPaintImageChanges the color value of any pixel that matches target


public Imagick::floodFillPaintImage ( mixed $fill , float $fuzz , mixed $target , int $x , int $y , bool $invert , int $channel = Imagick::CHANNEL_DEFAULT ) : bool

Changes the color value of any pixel that matches target and is an immediate neighbor. This method is a replacement for deprecated Imagick::paintFloodFillImage(). Această metodă este disponibilă dacă Imagick a fost compilat cu ImageMagick de versiunea 6.3.8 sau ulterior.



ImagickPixel object or a string containing the fill color


Mărimea difuziei. Spre exemplu dacă stabiliți difuzia la 10, atunci culoarea roșie de intensitățile 100 și 102 respectiv sunt interpretate ca aceeași culoare.


ImagickPixel object or a string containing the target color to paint


X start position of the floodfill


Y start position of the floodfill


If true paints any pixel that does not match the target color.


Înscrieți orice constantă a canalului care este validă pentru modul de canal. Pentru a aplica operația asupra mai multor canale, combinați constante de canal utilizând operatori binari. Valoarea implicită este Imagick::CHANNEL_DEFAULT. Iată lista de referință a constantelor de canal

Valorile întoarse

Întoarce true în caz de succes.


Example #1 Imagick::floodfillPaintImage() example


/* Create new imagick object */
$im = new Imagick();

/* create red, green and blue images */

/* Append the images into one */
$combined $im->appendImages(true);

/* Save the intermediate image for comparison */

/* The target pixel to paint */
$x 1;
$y 1;

/* Get the color we are painting */
$target $combined->getImagePixelColor($x$y);

/* Paints pixel in position 1,1 black and all neighboring 
   pixels that match the target color */

/* Save the result */

Exemplul de mai sus va afișa ceva similar cu:

Output of example : Imagick::floodfillPaintImage()
Output of example : Imagick::floodfillPaintImage()

add a note add a note

User Contributed Notes 1 note

2 years ago
For fuzz, percentage or float values do not seem to work. The value is based on the intensity of the image colors.

The documentation states: "The amount of fuzz. For example, set fuzz to 10 and the color red at intensities of 100 and 102 respectively are now interpreted as the same color."

For those of us who are not graphics geeks, your color intensity might be something like 65535. In which case, to get just 10% fuzz, you need to set it to 6550.

You likely will not see any effect if you are using low numbers or floats, like 100, 20, or 0.8.

For example:
$im = new Imagick();
$transparentColor = new ImagickPixel('transparent');
$greenscreen = '#00FF08';    // Super bright green

$im->readImage("cartoon_dog.png");    // Cartoony dog with a black outline and a #00FF08 (super bright green) background.

// Replace the green background with transparent.

// Leaves significant green lines around the outline of the dog, which is unacceptable.
$im->floodFillPaintImage($transparentColor, 30, $greenscreen, 0, 0, false, Imagick::CHANNEL_ALPHA);

// Works as intended - removes all of the green background.
$im->floodFillPaintImage($transparentColor, 30000, $greenscreen, 0, 0, false, Imagick::CHANNEL_ALPHA);

Credit to the discussion here:
To Top