PHP | ImagickPixel isPixelSimilarQuantum() function
The ImagickPixel::isPixelSimilarQuantum() function is an inbuilt function in PHP which is used to check if the distance between two colors is less than the specified distance. The fuzz value should be in the range 0-65535. This function is different from isPixelSimilar() because it accepts the fuzz in quantum range and actually compares a pixel with a color, not with another pixel.
Syntax:
bool ImagickPixel::isPixelSimilarQuantum( string $color, string $fuzz )
Parameters: This function accepts two parameters as mentioned above and described below:
- $color: It specifies the color to compare to.
- $fuzz: It specifies the fuzz value.
Return Value: This function returns an bool value which tells whether it is similar (true) or not (false).
Exceptions: This function throws ImagickException on error.
Below given programs illustrate the ImagickPixel::isPixelSimilarQuantum() function in PHP:
Program 1:
<?php
$imagickPixel = new ImagickPixel( 'green' );
$isSimilar = $imagickPixel ->isPixelSimilarQuantum( 'green' , 10);
if ( $isSimilar ) {
echo 'Similar' ;
} else {
echo 'Not Similar' ;
}
?>
|
Output:
Similar
Program 2:
<?php
$imagick = new Imagick(
$histogramElements = $imagick ->getImageHistogram();
$imagickPixel1 = $histogramElements [500];
$isSimilar = $imagickPixel1 ->isPixelSimilarQuantum( 'red' , 10);
if ( $isSimilar ) {
echo 'Similar' ;
} else {
echo 'Not Similar' ;
}
?>
|
Output:
Not Similar
Reference: https://www.php.net/manual/en/imagickpixel.ispixelsimilarquantum.php
Last Updated :
16 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...