function paintOpaqueImage($target_color, $replacement_color, $fuzz, $channel) { $imagick = new \Imagick(realpath("images/BlueScreen.jpg")); //Need to be in a format that supports transparency $imagick->setImageFormat('png'); @$imagick->paintOpaqueImage( $target_color, $replacement_color, $fuzz * \Imagick::getQuantum(), $channel ); //Not required, but helps tidy up left over pixels $imagick->despeckleimage(); header("Content-Type: image/png"); echo $imagick->getImageBlob(); }