Gmagick::setimagechanneldepth()函数是PHP中的内置函数,用于设置特定通道图像的深度。
用法:
Gmagick Gmagick::setimagechanneldepth( $channel , $depth )
参数:该函数接受上述和以下描述的两个参数:
- $channel:此参数用于指定通道常数。以下是固定频道列表:
CHANNEL constants:- 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()函数:
示例1:
原始图片:
<?php
// Create new Gmagick object
$im = new Gmagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-15.png');
// Using getImageChannelDepth function
// with red channel
echo "Before Set Channel depth: " . "</br>";
echo $im->getImageChannelDepth(Gmagick::CHANNEL_RED) . "</br>";
// Set channel Depth of CYAN and GREEN Channel
$im->setimagechanneldepth(Gmagick::CHANNEL_RED, 4);
echo "After Set Channel depth: " . "</br>";
echo $im->getImageChannelDepth(Gmagick::CHANNEL_RED) . "</br>";
?>
输出:
Before Set Channel depth: 8 After Set Channel depth: 4
示例2:
原始图片:
<?php
$string = "Computer Science portal for Geeks!";
// Creating new image of above String
// and add color
$im = new Gmagick();
$draw = new GmagickDraw();
// Fill the color in image
$draw->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: " . "</br>";
echo $im->getImageChannelDepth(Gmagick::CHANNEL_GREEN) . "</br>";
// Set channel Depth of Green Channel
$im->setimagechanneldepth(Gmagick::CHANNEL_GREEN, 8);
echo "After Set Channel depth: " . "</br>";
echo $im->getImageChannelDepth(Gmagick::CHANNEL_GREEN) . "</br>";
?>
输出:
Before Set Channel depth: 16 After Set Channel depth: 8
参考: http://php.net/manual/en/gmagick.setimagechanneldepth.php
相关用法
- PHP Imagick setImageChannelDepth()用法及代码示例
- PHP Gmagick blurimage()用法及代码示例
- PHP Gmagick medianfilterimage()用法及代码示例
- PHP Gmagick setimagecolorspace()用法及代码示例
- PHP Gmagick borderImage()用法及代码示例
- PHP Gmagick charcoalimage()用法及代码示例
- PHP Gmagick getImageDispose()用法及代码示例
- PHP Gmagick commentImage()用法及代码示例
- PHP Gmagick setImageDispose()用法及代码示例
- PHP Gmagick getImageMatte()用法及代码示例
- PHP Gmagick write()用法及代码示例
- PHP Gmagick embossimage()用法及代码示例
- PHP Gmagick implodeimage()用法及代码示例
- PHP Gmagick flipimage()用法及代码示例
- PHP Gmagick getimageformat()用法及代码示例
注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | Gmagick setimagechanneldepth() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。