Imagick::floodFillPaintImage

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

Imagick::floodFillPaintImageCambia el valor del color de cualquier píxel que coincida con el objetivo

Descripción

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

Cambia el valor del color de cualquier píxel que coincida con el objetivo y esté en el área inmediata. Este método es un sustituto del método obsoleto Imagick::paintFloodFillImage(). Este método está disponible si Imagick ha sido compilado con la versión 6.3.8 o superior de ImageMagick.

Parámetros

fill

Objeto ImagickPixel o una cadena que contiene el color de relleno

fuzz

La cantidad de difusión. Por ejemplo, setee fuzz a 10 y el color rojo a intensidades de 100 y 102 respectivamente son ahora interpretados como el mismo color.

target

Objeto ImagickPixel o una cadena que contiene el color objetivo a dibujar

x

Posición X del inicio del relleno

y

Posición Y del inicio del relleno

invert

Si es true se pinta cualquier píxel que no coincida con el color objetivo.

channel

Proporciona cualquier contante de canal que sea válida para su modo de canal. Para aplicarlo a más de un canal, combine constantes de canal using bitwise operadores bit a bit. El valor por defecto para Imagick::CHANNEL_DEFAULT. Referirse a esta lista de constantes de canal

Valores devueltos

Devuelve true en caso de éxito.

Ejemplos

Ejemplo #1 Ejemplo de Imagick::floodfillPaintImage()

<?php

/* Crear un nuevo objeto imagick */
$im = new Imagick();

/* Crear imágenes de color rojo, verde y azul */
$im->newImage(100, 50, "red");
$im->newImage(100, 50, "green");
$im->newImage(100, 50, "blue");

/* Añadir las imágenes para que sean una */
$im->resetIterator();
$combinado = $im->appendImages(true);

/* Guardar la imagen intermedia para la comparación */
$combinado->writeImage("floodfillpaint_intermedia.png");

/* El píxel objetivo a pintar */
$x = 1;
$y = 1;

/* Obtener el color con el que vamos a pintar */
$objetivo = $combinado->getImagePixelColor($x, $y);

/* Pinta el píxel en la posición 1,1 negro y todos los píxeles
cercanos que coincidan con el color objetivo */
$combinado->floodfillPaintImage("black", 1, $objetivo, $x, $y, false);

/* Guardar el resultado */
$combinado->writeImage("floodfillpaint_resultado.png");
?>

El resultado del ejemplo sería algo similar a:

Salida del ejemplo : Imagick::floodfillPaintImage()
Salida del ejemplo : 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