📜  PHP | Gmagick setimagechanneldepth()函数

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

PHP | Gmagick setimagechanneldepth()函数

Gmagick::setimagechanneldepth()函数是PHP中的一个内置函数,用于设置特定通道图像的深度。

句法:

Gmagick Gmagick::setimagechanneldepth( $channel , $depth )

参数:该函数接受上面提到的两个参数,如下所述:

  • $channel:此参数用于指定通道常数。下面是常量通道列表:
    通道常数:
    • Gmagick::CHANNEL_UNDEFINED
    • Gmagick::CHANNEL_RED
    • Gmagick::CHANNEL_GRAY
    • Gmagick::CHANNEL_CYAN
    • Gmagick::CHANNEL_GREEN
    • Gmagick::CHANNEL_MAGENTA
    • Gmagick::CHANNEL_BLUE
    • Gmagick::CHANNEL_YELLOW
    • Gmagick::CHANNEL_ALPHA
    • Gmagick::CHANNEL_OPACITY
    • Gmagick::CHANNEL_MATTE
    • Gmagick::CHANNEL_BLACK
    • Gmagick::CHANNEL_INDEX
    • Gmagick::CHANNEL_ALL
    • Gmagick::CHANNEL_DEFAULT
  • $depth:此参数用于指定要为 Gmagick 对象设置的深度。

返回值:此函数在成功时返回 Gmagick 对象。

下面的程序说明了PHP中的Gmagick::setimagechanneldepth()函数:

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

";
echo $im->getImageChannelDepth(Gmagick::CHANNEL_RED) . "
";     // Set channel Depth of CYAN and GREEN Channel $im->setimagechanneldepth(Gmagick::CHANNEL_RED, 4);     echo "After Set Channel depth: " . "
"; echo $im->getImageChannelDepth(Gmagick::CHANNEL_RED) . "
";    ?>

输出:

Before Set Channel depth:
8
After Set Channel depth:
4

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

setFillColor(new GmagickPixel('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 GmagickPixel('white')); 
   
// Draw the image         
$im->drawImage($draw); 
$im->setImageFormat('jpeg'); 
   
// Using getImageChannelDepth function
// with red channel
echo "Before Set Channel depth: " . "
"; echo $im->getImageChannelDepth(Gmagick::CHANNEL_GREEN) . "
";     // Set channel Depth of Green Channel $im->setimagechanneldepth(Gmagick::CHANNEL_GREEN, 8);     echo "After Set Channel depth: " . "
"; echo $im->getImageChannelDepth(Gmagick::CHANNEL_GREEN) . "
";    ?>

输出:

Before Set Channel depth:
16
After Set Channel depth:
8

参考: http: PHP。 PHP