Reduces the image to a limited number of color level.
Touch/mouse over to see original View modified in new window.
Image
Number Levels
Dither
Reduces the image to a limited number of color level.
Parameters
levelsint
ditherbool
function posterizeImage($imagePath, $dither, $numberLevels)
{
    $imagick = new \Imagick(realpath($imagePath));
    $imagick->posterizeImage($numberLevels, $dither);
    $imagick->setImageFormat('png');
    header("Content-Type: image/png");
    echo $imagick->getImageBlob();
}