PHP | Imagick getImageDistortion() Function
Last Updated :
21 Nov, 2019
The Imagick::getImageDistortion() function is an inbuilt function in PHP which is used to compare an image with reconstructed image and returns the specified distortion metric.
Syntax:
float Imagick::getImageDistortion(Imagick $reference, int $metric)
Parameters: This function accepts two parameters as mentioned above and described below:
- $reference: It specifies the Imagick object which need to compare.
- $metric: It specifies one of the metric type constants.
List of METRIC constants are given below:
- imagick::METRIC_UNDEFINED (0)
- imagick::METRIC_MEANABSOLUTEERROR (1)
- imagick::METRIC_MEANSQUAREERROR (2)
- imagick::METRIC_PEAKABSOLUTEERROR (3)
- imagick::METRIC_PEAKSIGNALTONOISERATIO (4)
- imagick::METRIC_ROOTMEANSQUAREDERROR (5)
Exceptions: This function throws ImagickException on error.
Return Value: This function returns the distortion metric used on the image.
Below programs illustrate the Imagick::getImageDistortion() function in PHP:
Program 1:
<?php
$imagick1 = new Imagick(
$imagick2 = new Imagick(
$distortion = $imagick1 ->getImageDistortion( $imagick2 , 5);
echo $distortion ;
?>
|
Output:
0.97254902124405
Program 2:
<?php
$imagick1 = new Imagick(
$imagick2 = new Imagick(
$distortion = $imagick1 ->getImageDistortion( $imagick2 , 4);
echo $distortion ;
?>
|
Output:
0.020707619325613
Program 3:
<?php
$imagick1 = new Imagick(
$imagick2 = new Imagick(
$distortion = $imagick1 ->getImageDistortion( $imagick2 , 4);
echo $distortion ;
?>
|
Output:
0 because both images are same.
Reference: https://www.php.net/manual/en/imagick.getimagedistortion.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...