📜  PHP | Gmagick getimagechanneldepth()函数

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

PHP | Gmagick getimagechanneldepth()函数

Gmagick::getimagechanneldepth()函数是PHP中的一个内置函数,用于返回通道图像的深度。
句法:

int Gmagick::getimagechanneldepth( $channel_type )

参数:此函数接受单个参数$channel_type ,该参数保存对通道模式有效的通道常数。通道的默认值为Gmagick::CHANNEL_DEFAULT
返回值:该函数返回通道的深度。
下面的程序说明了PHP中的Gmagick::getimagechanneldepth()函数:
原图1:

https://media.geeksforgeeks.org/wp-content/uploads/geeks-21.png

方案一:

php
getimagechanneldepth(Gmagick::CHANNEL_RED) . "
"; echo $im->getimagechanneldepth(Gmagick::CHANNEL_GRAY) . "
"; echo $im->getimagechanneldepth(Gmagick::CHANNEL_CYAN) . "
"; echo $im->getimagechanneldepth(Gmagick::CHANNEL_GREEN) . "
"; echo $im->getimagechanneldepth(Gmagick::CHANNEL_BLUE) . "
";   ?>


php
setFillColor(new GmagickPixel('green'));
  
// Set the text font size
$draw->setFontSize(50);
  
$matrix = $im->queryFontMetrics($draw, $string);
$draw->annotation(0, 40, $string);
$im->newImage($matrix['textWidth'], $matrix['textHeight'],
        new GmagickPixel('white'));
 
// Draw the image        
$im->drawImage($draw);
$im->setImageFormat('jpeg');
  
// Using getImageChannelDepth function
// with different channel
echo $im->getimagechanneldepth(Gmagick::CHANNEL_RED) . "
"; echo $im->getimagechanneldepth(Gmagick::CHANNEL_GRAY) . "
"; echo $im->getimagechanneldepth(Gmagick::CHANNEL_CYAN) . "
"; echo $im->getimagechanneldepth(Gmagick::CHANNEL_GREEN) . "
"; echo $im->getimagechanneldepth(Gmagick::CHANNEL_BLUE) . "
"; ?>


输出:

8
8
8
8
8

原始图像 2:

https://media.geeksforgeeks.org/wp-content/uploads/Screenshot-from-2018-10-16-23-23-54.png

方案二:

PHP

setFillColor(new GmagickPixel('green'));
  
// Set the text font size
$draw->setFontSize(50);
  
$matrix = $im->queryFontMetrics($draw, $string);
$draw->annotation(0, 40, $string);
$im->newImage($matrix['textWidth'], $matrix['textHeight'],
        new GmagickPixel('white'));
 
// Draw the image        
$im->drawImage($draw);
$im->setImageFormat('jpeg');
  
// Using getImageChannelDepth function
// with different channel
echo $im->getimagechanneldepth(Gmagick::CHANNEL_RED) . "
"; echo $im->getimagechanneldepth(Gmagick::CHANNEL_GRAY) . "
"; echo $im->getimagechanneldepth(Gmagick::CHANNEL_CYAN) . "
"; echo $im->getimagechanneldepth(Gmagick::CHANNEL_GREEN) . "
"; echo $im->getimagechanneldepth(Gmagick::CHANNEL_BLUE) . "
"; ?>

输出:

8
8
8
16
8

参考: http: PHP。 PHP