Monday, October 6, 2025
HomeLanguagesPHP | Imagick linearStretchImage() Function

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.

Syntax:

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.




<?php
  
// Store the image into variable
$imagePath=
  
// 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();
  
?>


Output:

Reference: https://www.php.net/manual/en/imagick.linearstretchimage.php

RELATED ARTICLES

Most Popular

Dominic
32338 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6707 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6825 POSTS0 COMMENTS
Ted Musemwa
7089 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6780 POSTS0 COMMENTS