PHP imagecolorexactalpha - Get the index value of the specified color with transparency

PHP 图像处理PHP Image Processing

imagecolorexactalpha — Get the index value of the specified color with transparency.

Syntax

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

Returns the index value of the specified color with transparency in the image's palette.

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

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 completely opaque, 127 means completely transparent.

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

Return Value

Returns the index value of the specified color with transparency in the image's palette. If the color is not in the image's palette, -1 is returned.

Examples

Get colors from the Example tutorial logo.

<?php

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

$colors   = Array();
$colors[] = imagecolorexactalpha($im, 255, 0, 0, 0);
$colors[] = imagecolorexactalpha($im, 0, 0, 0, 127);
$colors[] = imagecolorexactalpha($im, 255, 255, 255, 55);
$colors[] = imagecolorexactalpha($im, 100, 255, 52, 20);

print_r($colors);

// 从内存中释放
imagedestroy($im);
?>

The output of the above example is similar to:

Array
(
    [0] => 16711680
    [1] => 2130706432
    [2] => 939524095
    [3] => 342163252
)

Related Articles

PHP 图像处理PHP Image Processing

Other Extensions