ScotlandPHP 2019


(No version information available, might only be in Git)

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


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(). Este método está disponível se o PHP foi compilado com o ImageMagick versão 6.3.8 ou superior.



ImagickPixel object or a string containing the fill color


A quantidade de variação (fuzz). Por exemplo no fuzz de 10 a cor vermelha nas intensidades 100 e 102 são interpretadas como a mesma cor.


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.


Informa qualquer constante de canal válida no modo do canal. Para mais de um canal, combine as constantes de canal utilizando operações bitwise. O padrão é Imagick::CHANNEL_DEFAULT. Veja nessa lista de constantes de canal

Valor Retornado

Retorna TRUE no sucesso.


Exemplo #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 */

O exemplo acima irá imprimir algo similar à:

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

add a note add a note

User Contributed Notes 1 note

3 months 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