PHP imagecolorresolvealpha - Get the index of the specified color with transparency or the closest possible alternative
imagecolorresolvealpha — Get the index of the specified color with transparency or the closest possible alternative.
Syntax
int imagecolorresolvealpha ( resource $image , int $red , int $green , int $blue , int $alpha )
This function guarantees to return a color index for the requested color, either the exact value or the closest possible alternative.
Note: This function requires GD 2.0.1 or higher (recommended 2.0.28 and higher).
Parameters
image An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
red Value of the red component.
green Value of the green component.
blue Value of the blue component.
alpha A value between 0 and 127. 0 indicates completely opaque, and 127 indicates completely transparent.
The color parameters are integers between 0 and 255, or hexadecimal numbers between 0x00 and 0xFF.
Return Value
Returns a color index.
Example
Get colors from the tutorialpro.org logo.
<?php
// Create an image
$im = imagecreatefrompng('tutorialpro-logo.png');
// Get the closest colors from the image
$colors = array();
$colors[] = imagecolorresolvealpha($im, 255, 255, 255, 0);
$colors[] = imagecolorresolvealpha($im, 0, 0, 200, 127);
// Output
print_r($colors);
imagedestroy($im);
?>
The output of the above example is similar to:
Array
(
[0] => 16777215
[1] => 2130706632
)
Related Articles
- imagecolorclosestalpha() Get the closest color to the specified color with transparency.