Skip to content
Related Articles

Related Articles

PHP | imagecolorresolvealpha() Function
  • Last Updated : 23 Aug, 2019

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:

  • $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 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

My Personal Notes arrow_drop_up
Recommended Articles
Page :