Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP imagecolorclosestalpha - Get the Index of the Color Closest to the Specified Color Plus Transparency

PHP imagecolorclosestalpha - Get the Index of the Color Closest to the Specified Color Plus Transparency

PHP Image ProcessingPHP Image Processing

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

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

PHP Image ProcessingPHP Image Processing