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

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

以上實例的輸出類似于:

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

相關文章

PHP 圖像處理