Imagick::setImageChannelDepth()函数是PHP中的内置函数,用于设置特定通道图像的深度。
用法:
bool Imagick::setImageChannelDepth( $channel, $depth )
参数:该函数接受上述和以下描述的两个参数:
- $channel:此参数用于指定通道常数。以下是固定频道列表:
CHANNEL constants:- imagick::CHANNEL_UNDEFINED
- imagick::CHANNEL_RED
- imagick::CHANNEL_GRAY
- imagick::CHANNEL_CYAN
- imagick::CHANNEL_GREEN
- imagick::CHANNEL_MAGENTA
- imagick::CHANNEL_BLUE
- imagick::CHANNEL_YELLOW
- imagick::CHANNEL_ALPHA
- imagick::CHANNEL_OPACITY
- imagick::CHANNEL_MATTE
- imagick::CHANNEL_BLACK
- imagick::CHANNEL_INDEX
- imagick::CHANNEL_ALL
- imagick::CHANNEL_DEFAULT
- $depth:此参数用于指定要为Imagick对象设置的深度。
返回值:成功时此函数返回True。
以下示例程序旨在说明PHP中的Imagick::setImageChannelDepth()函数:
原始图片:
程序1:
<?php
// Create new Imagick object
$im = new Imagick(
'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(imagick::CHANNEL_RED) . "</br>";
// Set channel Depth of CYAN and GREEN Channel
$im->setImageChannelDepth(imagick::CHANNEL_RED, 4);
echo "After Set Channel depth: " . "</br>";
echo $im->getImageChannelDepth(imagick::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 Imagick();
$draw = new ImagickDraw();
// Fill the color in image
$draw->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: " . "</br>";
echo $im->getImageChannelDepth(imagick::CHANNEL_GREEN) . "</br>";
// Set channel Depth of Green Channel
$im->setImageChannelDepth(imagick::CHANNEL_GREEN, 8);
echo "After Set Channel depth: " . "</br>";
echo $im->getImageChannelDepth(imagick::CHANNEL_GREEN) . "</br>";
?>
输出:
Before Set Channel depth: 16 After Set Channel depth: 8
参考: http://php.net/manual/en/imagick.setimagechanneldepth.php
相关用法
- PHP Gmagick setimagechanneldepth()用法及代码示例
- PHP Imagick getImageDistortion()用法及代码示例
- PHP Imagick getImageCompression()用法及代码示例
- PHP Imagick getImageChannelDistortions()用法及代码示例
- PHP Imagick getImageExtrema()用法及代码示例
- PHP Imagick setImageCompressionQuality()用法及代码示例
- PHP Imagick getImageClipMask()用法及代码示例
- PHP Imagick getImageChannelStatistics()用法及代码示例
- PHP Imagick getImageCompose()用法及代码示例
- PHP Imagick setImageClipMask()用法及代码示例
- PHP Imagick getImageChannelExtrema()用法及代码示例
- PHP Imagick getImageChannelMean()用法及代码示例
- PHP Imagick setImageCompose()用法及代码示例
- PHP Imagick morphImages()用法及代码示例
- PHP Imagick readImageBlob()用法及代码示例
注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | Imagick setImageChannelDepth() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。