function kmeansImage(
    $image_path,
    int $number_colors,
    int $max_iterations,
    float $tolerance
) {
    $imagick = new \Imagick(realpath($image_path));
    $imagick->kmeansImage($number_colors, $max_iterations, $tolerance);
    header("Content-Type: image/jpeg");
    echo $imagick->getImageBlob();
}