PHP | imagecolorexactalpha() Function (original) (raw)

Last Updated : 11 Jul, 2025

The imagecolorexactalpha() function is an inbuilt function in PHP which is used to get the index of the specified color with alpha value. This function returns the index of the specified color and alpha value (RGBA value) in the palette of the image.Syntax:

int imagecolorexactalpha ( image,image, image,red, green,green, green,blue, $alpha )

Parameters: This function accepts five parameters as mentioned above and described below:

Return Value: This function returns the index of the specified color and alpha in the palette of the image on success, or -1 if the color does not exist in the image's palette. Below programs illustrate the imagecolorexactalpha() function in PHP:Program 1:

php `

colors[]=imagecolorexactalpha(colors[] = imagecolorexactalpha(colors[]=imagecolorexactalpha(image, 255, 0, 255, 0); colors[]=imagecolorexactalpha(colors[] = imagecolorexactalpha(colors[]=imagecolorexactalpha(image, 0, 225, 146, 127); colors[]=imagecolorexactalpha(colors[] = imagecolorexactalpha(colors[]=imagecolorexactalpha(image, 255, 56, 255, 55); colors[]=imagecolorexactalpha(colors[] = imagecolorexactalpha(colors[]=imagecolorexactalpha(image, 100, 55, 252, 20); print_r($colors); // Free from memory imagedestroy($image); ?>

`

Output:

Array ( [0] => 16711935 [1] => 2130764178 [2] => 939473151 [3] => 342112252 )

Program 2:

php `

`

Output:

Array ( [0] => 771717375 [1] => 2141198738 [2] => -1677772745 [3] => -927032324 )

Related Articles:

Reference: https://www.php.net/manual/en/function.imagecolorexactalpha.php