HomeImagickImagickDrawImagickPixelImagick Pixel IteratorImagick KernelDevelopmentTutorial Source codeReport an issue
Category
Example

Flood fill paint image

← flipImage   flopImage →
Changes the color value of any pixel that matches target and is an immediate neighbor. This method is a replacement for deprecated Imagick::paintFloodFillImage. This method is available if Imagick has been compiled against ImageMagick version 6.3.8 or newer.

Example

function floodFillPaintImage($fillColor, $fuzz, $targetColor, $x, $y, $inverse, $channel)
{
    $imagick = new \Imagick(realpath("images/BlueScreen.jpg"));
    // TODO - It should be possible to flood fill with a color that
    // is transparent, but currently it doesn't seem to work, presumably
    // because the image has no alpha channel;

    // $imagick->setImageAlphaChannel(Imagick::ALPHACHANNEL_ACTIVATE);
    $imagick->floodFillPaintImage(
        $fillColor,
        $fuzz * \Imagick::getQuantum(),
        $targetColor,
        $x, $y,
        $inverse,
        $channel
    );
    header("Content-Type: image/jpeg");
    echo $imagick->getImageBlob();
}