PHP | ImagickPixel getColorCount() function
The ImagickPixel::getColorCount() function is an inbuilt function in PHP which is used to get the color count associated with the pixel color. A color count is the number of pixels in the image that have the same color as this ImagickPixel. getColorCount() appears to only work for ImagickPixel objects created through getImageHistogram().
Syntax:
int ImagickPixel::getColorCount( void ) : int
Parameters: This function doesn’t accepts any parameter.
Return Value: This function returns an integer containing the color count.
Exceptions: This function throws ImagickException on error.
Below given programs illustrate the ImagickPixel::getColorCount() function in PHP:
Program 1:
<?php
$imagick = new Imagick(
$histogramElements = $imagick ->getImageHistogram();
$lastIndex = count ( $histogramElements ) - 1;
$lastColor = $histogramElements [ $lastIndex ];
echo $lastColor ->getColorCount();
?>
|
Output:
18
Program 2:
<?php
$imagick = new Imagick(
$histogramElements = $imagick ->getImageHistogram();
$lastColor = $histogramElements [0];
echo $lastColor ->getColorCount();
?>
|
Output:
1
Program 3:
<?php
$imagick = new Imagick(
$histogramElements = $imagick ->getImageHistogram();
$firstColor = $histogramElements [0];
$firstColor ->setColorCount(20);
echo $firstColor ->getColorCount();
?>
|
Output:
20
Program 3:
<?php
$imagick = new Imagick(
$histogramElements = $imagick ->getImageHistogram();
echo "R G B Hue :Count<br>" ;
foreach ( $histogramElements as $pixel ) {
$colors = $pixel ->getColor();
foreach ( $colors as $color ) {
print ( $color . " " );
}
print ( ":" . $pixel ->getColorCount() . "<br>" );
}
?>
|
Output:
R G B Hue :Count
0 22 35 1 :1
0 25 37 1 :1
0 24 37 1 :1
0 31 43 1 :1
0 32 44 1 :1
0 33 45 1 :1
0 37 49 1 :3
.
.
.
Reference: https://www.php.net/manual/en/imagickpixel.getcolorcount.php
Last Updated :
31 Dec, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...