Latest web development tutorials

PHP imagecolorexactalpha - Get the index of the specified color + alpha

PHP Image Processing PHP Image Processing

imagecolorexactalpha - Get the index of the specified color + alpha.

grammar

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

Returns the image specified palette index color plus transparency.

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

parameter

  • image created by the image function (for example imagecreatetruecolor ()) image resource returned.
  • valuered red component.
  • green value for the green component.
  • blue blue component value.
  • alpha a value of between 0 and 127.0 means completely opaque, 127 means completely transparent.

Color parameter is an integer between 0 and 255, or between a hexadecimal number between 0x00 and 0xFF.

return value

Returns the image specified palette index color plus transparency. If the image is not in color palette, -1 is returned.

Examples

Get color from the logo in this tutorial.

<?php

// 创建图像
$im = imagecreatefrompng('w3big-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);
?>

Output similar to the above example:

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

related articles

PHP Image Processing PHP Image Processing