YouTip LogoYouTip

Php Imagecolorclosestalpha

# PHP imagecolorclosestalpha - Get the index of the color closest to a specified color with transparency [![Image 3: PHP Image Processing](#)PHP Image Processing](#) imagecolorclosestalpha β€” Get the index of the color closest to a specified color with transparency. ### Syntax int imagecolorclosestalpha ( resource $image , int $red , int $green , int $blue , int $alpha ) Returns the index of the color in the image palette that is "closest" to the specified RGB values and alpha depth. ### Parameters * **image** An 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 indicates completely opaque, 127 indicates completely transparent. The color parameters are integers between 0 and 255, or hexadecimal numbers between 0x00 and 0xFF. ### Return Value Returns the index of the closest color in the palette. ### Example Search for a set of colors in an image. $rgb){ $result = imagecolorclosestalpha($im, $rgb, $rgb, $rgb, $rgb); $result = imagecolorsforindex($im, $result); $result = "({$result['red']}, {$result['green']}, {$result['blue']}, {$result['alpha']})"; echo "#$id: Searched ($rgb, $rgb, $rgb, $rgb); Closest match: $result.n";} imagedestroy($im);?> The output of the above example is similar to: #0: Searched (254, 145, 154, 50); Closest match: (252, 150, 148, 0).#1: Searched (153, 145, 188, 127); Closest match: (148, 150, 196, 0).#2: Searched (153, 90, 145, 0); Closest match: (148, 90, 156, 0).#3: Searched (255, 137, 92, 84); Closest match: (252, 150, 92, 0). ### Related Articles Get the index value of a specified color with transparency. Get the index value of the color closest to a specified color. Get the index of the hue, black, and white closest to a given color. [![Image 4: PHP Image Processing](#)PHP Image Processing](#)
← Highcharts 3D PieHighcharts 3D Column Null β†’