Reduces the image to a limited number of color level.

function posterizeImage($image_path, $dither, $numberLevels)
{
    $imagick = new \Imagick(realpath($image_path));
    $imagick->posterizeImage($numberLevels, $dither);
    $imagick->setImageFormat('png');
    header("Content-Type: image/png");
    echo $imagick->getImageBlob();
}