imagecolorclosestalpha() function in PHP


The imagecolorclosestalpha() function gets the index of closet color with alpha value.

Syntax

imagecolorclosestalpha ( img, red, green, blue, alpha )

Parameters

  • img: Image resource created with imagecreatetruecolor().

  • red: Red color component

  • green: Green color component

  • blue: Blue color component

  • alpha: The transparency of image, with 0 indicating completely opaque, whereas 127 indicating completely transparent.

Return

The imagecolorclosestalpha() function returns the index of the closest color in the palette.

Example

The following is an example:

 Live Demo

<?php
   $img = imagecreatefrompng('http://www.tutorialspoint.com/images/tp-logo-diamond.png');
   imagetruecolortopalette($img, false, 255);
   $match = imagecolorclosestalpha($img, 180, 100, 150, 110);
   $match = imagecolorsforindex($img, $match);
   $match = "({$match['red']}, {$match['green']},
   {$match['blue']}, {$match['alpha']})";
   echo $match;
   imagedestroy($img);
?>

Output

The following is the output:

(140, 130, 140, 0)

Updated on: 31-Dec-2019

37 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements