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


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


Imagick::getImageChannelDepth()函數是PHP中的內置函數,用於獲取通道圖像的深度。

用法:

int Imagick::getImageChannelDepth( $channel )

參數:該函數接受單個參數$channel,該參數指定對通道模式有效的通道常數。頻道的默認值為Imagick::CHANNEL_DEFAULT。


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

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

程序1:
原始圖片:
https://media.geeksforgeeks.org/wp-content/uploads/geeks-21.png

<?php 
  
// Create new imagick object 
$im = new Imagick( 
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-15.png'); 
  
// Using getImageChannelDepth function 
// with different channel 
echo $im->getImageChannelDepth(imagick::CHANNEL_RED) . "</br>"; 
echo $im->getImageChannelDepth(imagick::CHANNEL_GRAY) . "</br>"; 
echo $im->getImageChannelDepth(imagick::CHANNEL_CYAN) . "</br>"; 
echo $im->getImageChannelDepth(imagick::CHANNEL_GREEN) . "</br>"; 
echo $im->getImageChannelDepth(imagick::CHANNEL_BLUE) . "</br>"; 
?>

輸出:

8
8
8
8
8

程序2:
原始圖片:
https://media.geeksforgeeks.org/wp-content/uploads/Screenshot-from-2018-10-16-23-23-54.png

<?php  
  
$string = "Computer Science portal for Geeks!";  
  
// Creating new image of above String  
// and add color 
$im = new Imagick();  
$draw = new ImagickDraw();  
  
// Fill the color in image  
$draw->setFillColor(new ImagickPixel('green'));  
  
// Set the text font size  
$draw->setFontSize(50);  
  
$metrix = $im->queryFontMetrics($draw, $string);  
$draw->annotation(0, 40, $string);  
$im->newImage($metrix['textWidth'], $metrix['textHeight'],  
        new ImagickPixel('white'));  
// Draw the image          
$im->drawImage($draw);  
$im->setImageFormat('jpeg');  
  
// Using getImageChannelDepth function 
// with different channel 
echo $im->getImageChannelDepth(imagick::CHANNEL_RED) . "</br>"; 
echo $im->getImageChannelDepth(imagick::CHANNEL_GRAY) . "</br>"; 
echo $im->getImageChannelDepth(imagick::CHANNEL_CYAN) . "</br>"; 
echo $im->getImageChannelDepth(imagick::CHANNEL_GREEN) . "</br>"; 
echo $im->getImageChannelDepth(imagick::CHANNEL_BLUE) . "</br>"; 
?>

輸出:

8
8
8
16
8

參考: http://php.net/manual/en/imagick.getimagechanneldepth.php



相關用法


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