当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。