Saturday, November 16, 2024
Google search engine
HomeLanguagesPHP | imagecolorresolvealpha() Function

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:

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments