📜  PHP |想象一下 getImageChannelDepth()函数

📅  最后修改于: 2022-05-13 01:56:20.911000             🧑  作者: Mango

PHP |想象一下 getImageChannelDepth()函数

Imagick::getImageChannelDepth()函数是PHP中的一个内置函数,用于获取通道图像的深度。

句法:

int Imagick::getImageChannelDepth( $channel )

参数:此函数接受单个参数$channel ,它指定对通道模式有效的通道常数。通道的默认值为Imagick::CHANNEL_DEFAULT

返回值:此函数在成功时返回 True。

下面的程序说明了PHP中的Imagick::getImageChannelDepth()函数:

方案一:
原图:
https://media.geeksforgeeks.org/wp-content/uploads/geeks-21.png

getImageChannelDepth(imagick::CHANNEL_RED) . "
"; echo $im->getImageChannelDepth(imagick::CHANNEL_GRAY) . "
"; echo $im->getImageChannelDepth(imagick::CHANNEL_CYAN) . "
"; echo $im->getImageChannelDepth(imagick::CHANNEL_GREEN) . "
"; echo $im->getImageChannelDepth(imagick::CHANNEL_BLUE) . "
"; ?>

输出:

8
8
8
8
8

方案二:
原图:
https://media.geeksforgeeks.org/wp-content/uploads/Screenshot-from-2018-10-16-23-23-54.png

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) . "
"; echo $im->getImageChannelDepth(imagick::CHANNEL_GRAY) . "
"; echo $im->getImageChannelDepth(imagick::CHANNEL_CYAN) . "
"; echo $im->getImageChannelDepth(imagick::CHANNEL_GREEN) . "
"; echo $im->getImageChannelDepth(imagick::CHANNEL_BLUE) . "
"; ?>

输出:

8
8
8
16
8

参考: http: PHP。 PHP