當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP Imagick getImageAlphaChannel()用法及代碼示例


Imagick::getImageAphaChannel()函數是PHP中的一個內置函數,用於獲取圖像Alpha通道。返回的值是ALPHACHANNEL常數之一。

用法:

int Imagick::getImageAlphaChannel( void )

參數:該函數不接受任何參數。


Exceptions:該函數在錯誤時引發ImagickException。

返回值:成功時此函數返回整數值。

ALPHACHANNEL常數列表如下:

  • imagick::ALPHACHANNEL_ACTIVATE(0)
  • imagick::ALPHACHANNEL_DEACTIVATE(1)
  • imagick::ALPHACHANNEL_RESET(2)
  • imagick::ALPHACHANNEL_SET(3)
  • imagick::ALPHACHANNEL_UNDEFINED(4)
  • imagick::ALPHACHANNEL_COPY(5)
  • imagick::ALPHACHANNEL_EXTRACT(6)
  • imagick::ALPHACHANNEL_OPAQUE(7)
  • imagick::ALPHACHANNEL_SHAPE(8)
  • imagick::ALPHACHANNEL_TRANSPARENT(9)

以下示例程序旨在說明PHP中的Imagick::getImageAlphaChannel()函數:

程序1:

<?php 
  
// Create a new imagick object with a PNG image 
$imagick = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
// Get the Alpha Channel 
$alphaChannel = $imagick->getImageAlphaChannel(); 
  
echo $alphaChannel; 
?>

輸出:

1 ( which corresponds to imagick::ALPHACHANNEL_DEACTIVATE. )

程序2:

<?php 
   
// Create a new imagick object with a PNG image 
$imagick = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/20191112214917/geeksforgeeks8.jpg'); 
   
// Get the Alpha Channel 
$alphaChannel = $imagick->getImageAlphaChannel(); 
   
echo $alphaChannel . "<br>"; 
  
// Set the alpha channel 
$alphaChannel = $imagick->setImageAlphaChannel(imagick::ALPHACHANNEL_RESET ); 
// Get the Alpha Channel 
$alphaChannel = $imagick->getImageAlphaChannel(); 
   
echo $alphaChannel; 
?>

輸出:

0
1

參考: https://www.php.net/manual/en/imagick.getimagealphachannel.php



相關用法


注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | Imagick getImageAlphaChannel() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。