PHP imagecolorclosestalpha - Get the Index of the Color Closest to the Specified Color Plus Transparency
imagecolorclosestalpha — Gets the index of the color closest to the specified color plus transparency.
Syntax
int imagecolorclosestalpha ( resource $image , int $red , int $green , int $blue , int $alpha )
Returns the color in the image palette that is closest to the specified RGB value and alpha depth.
Parameters
- image The image resource returned by an image creation function (e.g., imagecreatetruecolor()).
- red The value of the red component.
- green The value of the green component.
- blue The value of the blue component.
- alpha A value between 0 and 127. 0 means fully opaque, 127 means fully transparent.
The color parameter is an integer between 0 and 255, or a hexadecimal number between 0x00 and 0xFF.
Return Value
Returns the index of the closest color in the palette.
Example
Search for a set of colors in the image.
$rgb)
{
$result = imagecolorclosestalpha($im, $rgb[0], $rgb[1], $rgb[2], $rgb[3]);
$result = imagecolorsforindex($im, $result);
$result = "({$result['red']}, {$result['green']}, {$result['blue']}, {$result['alpha']})";
echo "#$id: 搜索 ($rgb[0], $rgb[1], $rgb[2], $rgb[3]); 最接近的匹配: $result。\n";
}
imagedestroy($im);
?>
The output of the example above is similar to:
#0: Search (254, 145, 154, 50); Closest match: (252, 150, 148, 0).
#1: Search (153, 145, 188, 127); Closest match: (148, 150, 196, 0).
#2: Search (153, 90, 145, 0); Closest match: (148, 90, 156, 0).
#3: Search (255, 137, 92, 84); Closest match: (252, 150, 92, 0).
Related Articles
- imagecolorexactalpha() Get the index value of the specified color plus transparency.
- imagecolorclosest() Get the index value of the color closest to the specified color.
- imagecolorclosesthwb() Get the index of the grayscale (black and white) shade closest to the given color.
PHP Image Processing