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。

實例

從IT研修 logo 中獲取顏色。

<?php

// 創建圖像
$im = imagecreatefrompng('zaixian-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 圖像處理