Open In App

PHP | imagecolorexactalpha() Function

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, $red, $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
  
// Setup an image
$image = imagecreatefrompng(
  
$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);
?>

Output:

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

Program 2:




<?php
   
// Setup an image
$image = imagecreatefrompng(
   
$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);
?>

Output:

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

Related Articles:

Reference: http://php.net/manual/en/function.imagecolorexactalpha.php


Article Tags :