MagickContrastStretchImage() enhances the contrast of a color image by adjusting the pixels color to span the entire range of colors available. You can also reduce the influence of a particular channel with a gamma value of 0.
¯\_(ツ)_/¯
function contrastStretchImage($image_path, $black_point, $white_point, $channel) { $imagick = new \Imagick(realpath($image_path)); list ($width, $height) = array_values ($imagick->getImageGeometry ()); $imagick->contrastStretchImage( $width * $height * $black_point / 100, $width * $height * $white_point / 100, $channel ); header("Content-Type: image/jpeg"); echo $imagick->getImageBlob(); }