PHP | Gmagick getimagehistogram() Function
The Gmagick::getimagehistogram() function is an inbuilt function in PHP which is used to get the image histogram. This function returns all the pixels from the picture in the form of an array of Gmagick pixels. We can use this function to analyze the color of any picture pixel by pixel.
Syntax:
array Gmagick::getimagehistogram( void )
Parameters: This function doesn’t accept any parameters.
Return Value: This function returns an array value containing the histogram.
Exceptions: This function throws GmagickException on error.
Below given programs illustrate the Gmagick::getimagehistogram() function in PHP:
Program 1:
<?php
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$histogram = $gmagick ->getimagehistogram();
print ( "<pre>" .print_r( $histogram , true). "</pre>" );
?>
|
Output:
Returns an array with 2955 Gmagick objects as members.
Program 2:
<?php
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$histogram = $gmagick ->getimagehistogram();
echo "Color of first five pixels are <br>" ;
for ( $i = 0; $i < 5; $i ++) {
$color = $histogram [ $i ]->getcolor();
echo $color . "<br>" ;
}
?>
|
Output:
Color of first five pixels are
rgb(0, 5654, 8995)
rgb(0, 6168, 9509)
rgb(0, 6425, 9509)
rgb(0, 7967, 11051)
rgb(0, 8224, 11308)
Reference: https://www.php.net/manual/en/gmagick.getimagehistogram.php
Last Updated :
21 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...