Open In App

PHP | imagecolorresolvealpha() Function

The imagecolorresolvealpha() function is an inbuilt function in PHP which is used to get the index of the specified color and alpha value or its closest possible alternative value. This function returns the index for a requested color, either the exact color or the closest possible alternative color.

Syntax:



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

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

Return Value: This function returns the index value of colors.



Below programs illustrate the imagecolorresolvealpha() function in PHP:

Program 1:




<?php
   
// Load an image
$image = imagecreatefromgif(
   
// Get closest colors from the image
$colors = array();
$colors[] = imagecolorresolvealpha($image, 156, 0, 255, 0);
$colors[] = imagecolorresolvealpha($image, 0, 255, 200, 50);
$colors[] = imagecolorresolvealpha($image, 16, 134, 35, 70);
$colors[] = imagecolorresolvealpha($image, 143, 255, 254, 100);
   
// Output
print_r($colors);
   
imagedestroy($image);
?>

Output:

Array ( 
    [0] => 187 
    [1] => 188 
    [2] => 189 
    [3] => 190 
) 

Program 2:




<?php
   
// Load an image
$image = imagecreatefromgif(
   
// Get closest colors from the image
$colors = array(
    imagecolorresolvealpha($image, 156, 0, 255, 0),
    imagecolorresolvealpha($image, 0, 255, 200, 50),
    imagecolorresolvealpha($image, 16, 134, 35, 70),
    imagecolorresolvealpha($image, 143, 255, 254, 100)
);
   
// Output
print_r($colors);
   
imagedestroy($image);
?>

Output:

Array ( 
    [0] => 187 
    [1] => 188 
    [2] => 189 
    [3] => 190 
) 

Related Articles:

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


Article Tags :