Stretches with saturation the image intensity.
Discards any pixels below the black point and above the white point and levels the remaining pixels. The calculation is done by number of pixels, rather than absolute color values.

In the code example below using a value of 0.10 for both the black and white threshold, would move the darkest 10% of pixels to black, the lightest 10% of pixels to white, and level the remaining pixels.

A value of zero for eithe black or white point means that that end of the histogram is not adjusted.
Touch/mouse over to see original View modified in new window.
Image
Black threshold
White threshold
Stretches with saturation the image intensity.
Discards any pixels below the black point and above the white point and levels the remaining pixels. The calculation is done by number of pixels, rather than absolute color values.

In the code example below using a value of 0.10 for both the black and white threshold, would move the darkest 10% of pixels to black, the lightest 10% of pixels to white, and level the remaining pixels.

A value of zero for eithe black or white point means that that end of the histogram is not adjusted.
Parameters
blackPointfloatThe image black point
whitePointfloatThe image white point
function linearStretchImage($imagePath, $blackThreshold, $whiteThreshold)
{
    $imagick = new \Imagick(realpath($imagePath));
    $pixels = $imagick->getImageWidth() * $imagick->getImageHeight();
    $imagick->linearStretchImage($blackThreshold * $pixels, $whiteThreshold * $pixels);

    header("Content-Type: image/jpg");
    echo $imagick->getImageBlob();
}