PHP | Gmagick getimagecolors() Function
Last Updated :
17 Jan, 2020
The Gmagick::getimagecolors() function is an inbuilt function in PHP which is used to get the number of unique colors in the image.
Syntax:
int Gmagick::getimagecolors( void )
Parameters:This function doesn’t accept any parameter.
Return Value: This function returns an integer value.
Exceptions: This function throws GmagickException on error.
Used Image: To capture the canvas area
Below given programs illustrate the Gmagick::getimagecolors() function in PHP:
Program 1: For an image with multiple colors.
<?php
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$color = $gmagick ->getimagecolors();
echo $color ;
?>
|
Output:
2955
Program 2: For an image with single color.
<?php
$gmagick = new Gmagick( 'singlecolor.png' );
$color = $gmagick ->getimagecolors();
echo $color ;
?>
|
Output:
1
Program 3: For a drawing
<?php
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$draw = new GmagickDraw();
$draw ->setFillColor( 'white' );
$draw ->rectangle(0, 0, 800, 400);
$draw ->setFillColor( 'red' );
$draw ->setfontsize(50);
$draw ->annotate(30, 100, 'GeeksforGeeks' );
$gmagick ->drawImage( $draw );
$colors = $gmagick ->getimagecolors();
echo $colors ;
?>
|
Output:
238
Reference: https://www.php.net/manual/en/gmagick.getimagecolors.php
Share your thoughts in the comments
Please Login to comment...