HomeImagickImagickDrawImagickPixelImagick Pixel IteratorImagick KernelTutorial Source codeReport an issue
Category
Example

Imagick::opaquePaintImage

← oilPaintImage   orderedDitherImage →
Changes any pixel that matches color with the color defined by fill. This method is available if Imagick has been compiled against ImageMagick version 6.3.8 or newer.
function opaquePaintImage($target_color, $replacement_color, $fuzz, $inverse)
{
    $imagick = new \Imagick(realpath("images/BlueScreen.jpg"));

    //Need to be in a format that supports transparency
    $imagick->setImageFormat('png');

    $imagick->opaquePaintImage(
        $target_color,
        $replacement_color,
        $fuzz * \Imagick::getQuantum(),
        $inverse
    );
    //Not required, but helps tidy up left over pixels
    $imagick->despeckleimage();

    header("Content-Type: image/png");
    echo $imagick->getImageBlob();
}