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:
php
Output:
php
Output:
int imagecolorexactalpha ( $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.
<?php
// Setup an image
$image = imagecreatefrompng(
'https://media.geeksforgeeks.org/wp-content/uploads/col1.png');
$colors = Array();
$colors[] = imagecolorexactalpha($image, 255, 0, 255, 0);
$colors[] = imagecolorexactalpha($image, 0, 225, 146, 127);
$colors[] = imagecolorexactalpha($image, 255, 56, 255, 55);
$colors[] = imagecolorexactalpha($image, 100, 55, 252, 20);
print_r($colors);
// Free from memory
imagedestroy($image);
?>
Array (
[0] => 16711935
[1] => 2130764178
[2] => 939473151
[3] => 342112252
)
Program 2:
<?php
// Setup an image
$image = imagecreatefrompng(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-9.png');
$colors = Array(
imagecolorexactalpha($image, 255, 120, 255, 45),
imagecolorexactalpha($image, 160, 25, 146, 127),
imagecolorexactalpha($image, 255, 56, 55, 155),
imagecolorexactalpha($image, 190, 155, 252, 200)
);
print_r($colors);
// Free from memory
imagedestroy($image);
?>
Array (
[0] => 771717375
[1] => 2141198738
[2] => -1677772745
[3] => -927032324
)
Related Articles:
- PHP | imagecolorstotal() Function
- PHP | imagecolorset() Function
- PHP | imagecolorresolvealpha() Function