Latest web development tutorials

PHP imagecolorexactalpha – 取得指定的顏色加透明度的索引值

PHP 圖像處理 PHP圖像處理

imagecolorexactalpha — 取得指定的顏色加透明度的索引值。

語法

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

返回圖像調色板中指定顏色加透明度的索引值。

注意:此函數需要GD 2.0.1或更高版本(推薦2.0.28及更高版本)。

參數

  • image由圖像創建函數(例如imagecreatetruecolor())返回的圖像資源。
  • red紅色成分的值。
  • green綠色成分的值。
  • blue藍色成分的值。
  • alpha一個介於0和127之間的值。0 表示完全不透明,127 表示完全透明。

顏色參數是介於0 和255 之間的整數,或者是介於0x00 和0xFF 之間的十六進制數。

返回值

返回圖像調色板中指定顏色加透明度的索引值。 如果顏色不在圖像的調色板中,返回-1。

實例

從本教程logo 中獲取顏色。

<?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);
?>

以上實例的輸出類似於:

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

相關文章

PHP 圖像處理 PHP圖像處理