The GmagickPixel::getcolor() function is an inbuilt function in PHP which is used to get the color described by the GmagickPixel object, as a string or an array. If the color has an opacity channel set, this is provided as a fourth value in the list.
Syntax:
mixed GmagickPixel::getcolor( bool $as_array, bool $normalized_array )
Parameters: This function accepts two parameters as mentioned above and described below:
- $as_array (Optional): It specifies whether to get value as array. Its default value is FALSE.
- $normalized_array (Optional): It specifies whether to get normalized array. Its default value is FALSE.
Return Value: This function returns a string or an array of color values.
Exceptions: This function throws GmagickPixelException on error.
Below given programs illustrate the GmagickPixel::getcolor() function in PHP:
Program 1 (Getting color as string):
<?php // Create a new GmagickPixel object // using __construct $gmagickPixel = new GmagickPixel( '#ccb062' ); // Get the color $color = $gmagickPixel ->getcolor(); print ( "<pre>" .print_r( $color , true). "</pre>" ); ?> |
Output:
rgb(52428, 45232, 25186)
Program 2 (Getting color as array with normalization):
<?php // Create a new GmagickPixel object // using __construct $gmagickPixel = new GmagickPixel( '#ccb062' ); // Get the color $color = $gmagickPixel ->getcolor(true, true); print ( "<pre>" .print_r( $color , true). "</pre>" ); ?> |
Output:
Array ( [r] => 0.8 [g] => 0.69019607843137 [b] => 0.3843137254902 )
Program 3 (Getting color as array without normalization):
<?php // Create a new GmagickPixel object // using __construct $gmagickPixel = new GmagickPixel( '#ccb062' ); // Get the color $color = $gmagickPixel ->getcolor(true, false); print ( "<pre>" .print_r( $color , true). "</pre>" ); ?> |
Output:
Array ( [r] => 204 [g] => 176 [b] => 98 )
Reference: https://www.php.net/manual/en/gmagickpixel.getcolor.php