PHP imagecolorresolvealpha - Get the index value of the specified color with transparency or the closest possible alternative

PHP 图像处理PHP Image Processing

imagecolorresolvealpha — Get the index value of the specified color with transparency or the closest possible alternative.

Syntax

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

This function guarantees to return a color index for the requested color, either the exact value or the closest alternative available.

Note:This function requires GD 2.0.1 or later (recommended 2.0.28 or later).

Parameters

  • imageAn image resource returned by an image creation function (such as imagecreatetruecolor()).
  • redThe value of the red component.
  • greenThe value of the green component.
  • blueThe value of the blue component.
  • alphaA value between 0 and 127. 0 means fully opaque, 127 means fully transparent.

The color parameters are integers between 0 and 255, or hexadecimal numbers between 0x00 and 0xFF.

Return Values

Returns a color index.

Examples

Get colors from the Example logo.

<?php
// 创建图像
$im = imagecreatefrompng('example-logo.png');

// 从图像中获取最接近的颜色
$colors = array();
$colors[] = imagecolorresolvealpha($im, 255, 255, 255, 0);
$colors[] = imagecolorresolvealpha($im, 0, 0, 200, 127);

// 输出
print_r($colors);

imagedestroy($im);
?>

The output of the above example is similar to:

Array
(
    [0] => 16777215
    [1] => 2130706632
)

Related Articles

PHP 图像处理PHP Image Processing

Other Extensions