This function is quite slow and prone to time out. Large values for the cluster and smooth threshold appear to be faster, and so safer.


Image
Cluster threshold
Smooth threshold
Color space

This function is quite slow and prone to time out. Large values for the cluster and smooth threshold appear to be faster, and so safer.

function segmentImage($imagePath, $colorSpace, $clusterThreshold, $smoothThreshold)
{
    $imagick = new \Imagick(realpath($imagePath));
    $imagick->segmentImage($colorSpace, $clusterThreshold, $smoothThreshold);
    header("Content-Type: image/jpg");
    echo $imagick->getImageBlob();
}