Changes any pixel that matches color with the color defined by fill. Available since 6.3.8
Touch/mouse over to see original View modified in new window.
Color
 
Replace color
 
Fuzz
Inverse
Changes any pixel that matches color with the color defined by fill. Available since 6.3.8
Parameters
targetmixedImagickPixel object or a string containing the color to change
fillmixedThe replacement color
fuzzfloat;
invertboolIf True; paints any pixel that does not match the target color.
channelintImagick channel constant;
function opaquePaintImage($color, $replacementColor, $fuzz, $inverse)
{
    $imagick = new \Imagick(realpath("images/BlueScreen.jpg"));

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

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

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