Imagick::floodFillPaintImage

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

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

Descrierea

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.

Parametri

fill

ImagickPixel object or a string containing the fill color

fuzz

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.

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

Î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.

Exemple

Example #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");
?>

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

up
0
Anonymous
6 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