HomeImagickImagickDrawImagickPixelImagick Pixel IteratorImagick KernelDevelopmentTutorial Source codeReport an issue
Category
Example

Imagick::contrastStretchImage

← contrastImage   convolveImage →
Enhances the contrast of a color image by adjusting the pixels color to span the entire range of colors available. This method is available if Imagick has been compiled against ImageMagick version 6.2.9 or newer.

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.

¯\_(ツ)_/¯


Example

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();
}