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:
php
Output:
php
Output:
php
Output:
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.
<?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>");
?>
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>");
?>
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>");
?>
Array
(
[r] => 204
[g] => 176
[b] => 98
)
Reference: https://www.php.net/manual/en/gmagickpixel.getcolor.php