Negates the colors in the reference image. The Grayscale option means that only grayscale values within the image are negated.
function negateImage($image_path, $grayOnly, $channel)
{
    $imagick = new \Imagick(realpath($image_path));
    $imagick->negateImage($grayOnly, $channel);
    header("Content-Type: image/jpg");
    echo $imagick->getImageBlob();
}