The imagecolorclosestalpha() function is an inbuilt function in PHP which is used to get the index of closet color with alpha value in given image. This function returns the index of the color in the palette of the image which is closest to the specified RGB value and alpha level. Alpha value represents the transparency of the image.
int imagecolorclosestalpha ( $image, $red, $green, $blue, $alpha )
Parameters: This function accepts five parameters as mentioned above and described below:
- $image: It is returned by one of the image creation functions, such as imagecreatetruecolor(). It is used to create size of image.
- $red: This parameter is used to set value of red color component.
- $green: This parameter is used to set value of green color component.
- $blue: This parameter is used to set value of blue color component.
- $alpha: This parameter is used to set the transparency of image. The value of $alpha lies between 0 to 127 where 0 represents completely opaque while 127 represents completely transparent.
Return Value: This function returns the index of the closest color in the palette.
Below programs illustrate the imagecolorclosestalpha() function in PHP:
Closest match: (100, 58, 108, 0)
Given color: (155, 40, 200, 50) => Closest match: (100, 58, 108, 0) Given color: (235, 205, 188, 127) => Closest match: (100, 58, 108, 0) Given color: (135, 0, 132, 0) => Closest match: (100, 58, 108, 0)
This article is attributed to GeeksforGeeks.org