Imagick::floodFillPaintImage

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

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

Descrição

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

Parâmetros

fill

ImagickPixel object or a string containing the fill color

fuzz

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.

target

ImagickPixel object or a string containing the target color to paint

x

X start position of the floodfill

y

Y start position of the floodfill

invert

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

channel

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.

Exemplos

Exemplo #1 Imagick::floodfillPaintImage() example

<?php

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

/* create red, green and blue images */
$im->newImage(10050"red");
$im->newImage(10050"green");
$im->newImage(10050"blue");

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

/* Save the intermediate image for comparison */
$combined->writeImage("floodfillpaint_intermediate.png");

/* 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 */
$combined->floodfillPaintImage("black"1$target$x$yfalse);

/* Save the result */
$combined->writeImage("floodfillpaint_result.png");
?>

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

up
1
Anonymous
5 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:
https://php5.kiev.ua/php7/imagick.painttransparentimage.html
To Top