PHP | Imagick linearStretchImage() Function

The Imagick::linearStretchImage() function is an inbuilt function in PHP which is used to stretch with saturation the image intensity. The calculation of Imagick::linearStretchImage() function is carry by pixels multiples with blackPoint and whitePoint simultaneously.


bool Imagick::linearStretchImage( $blackPoint, $whitePoint )

Parameters: This function accepts two parameters as mentioned above and described below:

  • $blackPoint: This parameter holds the image black point.
  • $whitePoint: This parameter holds the image white point.

Return Value: This function returns TRUE on success FALSE on failure.

Below example illustrates the Imagick::linearStretchImage() function in PHP:

Program: This program uses Imagick::linearStretchImage() function to stretch with saturation the image intensity.





// Store the image into variable
// Store the value of variables
$blackThreshold = 23;
$whiteThreshold = 45;
// Declare new Imagick object
$imagick = new \Imagick($imagePath);
// Calculate the pixels of image
$pixels = $imagick->getImageWidth() * $imagick->getImageHeight();
// Use linearStretchImage() function to stretches with
// saturation the image intensity
$imagick->linearStretchImage($blackThreshold * $pixels, $whiteThreshold * $pixels);
header("Content-Type: image/jpeg");
// Display the image
echo $imagick->getImageBlob();




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.