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

PHP image processing

Imagecolorexactalpha - Get the index value of the specified color plus transparency.

Grammar

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

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

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

Parameters

  • Image resources returned by image creation functions such as imagecreatetruecolor().
  • The value of the red red ingredient.
  • The value of the green ingredient.
  • The value of the blue blue ingredient.
  • alpha A value between 0 and 127. 0 means completely opaque and 127 is completely transparent.

The color parameters are integers between 0 and 255, or heteens between 0x00 and 0xFF and between them.

Returns a value

Returns the index value of the specified color transparency in the image palette. Returns -1 if the color is not in the color palette of the image.

Instance

Get the colors from the Ukip tutorial logo.

<?php

// 创建图像
$im = imagecreatefrompng('youj-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 examples is similar to:

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

Related articles

PHP image processing