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

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

PHP |想象一下 setImageChannelDepth()函数

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

句法:

bool Imagick::setImageChannelDepth( $channel, $depth )

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

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

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

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

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

方案一:

";
echo $im->getImageChannelDepth(imagick::CHANNEL_RED) . "
";    // Set channel Depth of CYAN and GREEN Channel $im->setImageChannelDepth(imagick::CHANNEL_RED, 4);    echo "After Set Channel depth: " . "
"; echo $im->getImageChannelDepth(imagick::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 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 red channel
echo "Before Set Channel depth: " . "
"; echo $im->getImageChannelDepth(imagick::CHANNEL_GREEN) . "
";    // Set channel Depth of Green Channel $im->setImageChannelDepth(imagick::CHANNEL_GREEN, 8);    echo "After Set Channel depth: " . "
"; echo $im->getImageChannelDepth(imagick::CHANNEL_GREEN) . "
"; ?>

输出:

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

参考: http: PHP。 PHP