PHP | Imagick setImageChannelDepth() Function
The Imagick::setImageChannelDepth() function is an inbuilt function in PHP which is used to set the depth of a particular channel image.
Syntax:
bool Imagick::setImageChannelDepth( $channel, $depth )
Parameters: This function accepts two parameters as mentioned above and described below:
- $channel: This parameter is used to specify the channel constant. Below is the list of constant 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: This parameter is used to specify the depth to be set for Imagick object.
Return Value: This function returns True on success.
Below programs illustrate the Imagick::setImageChannelDepth() function in PHP:
Original Image:
Program 1:
<?php
$im = new Imagick(
echo "Before Set Channel depth: " . "</br>" ;
echo $im ->getImageChannelDepth(imagick::CHANNEL_RED) . "</br>" ;
$im ->setImageChannelDepth(imagick::CHANNEL_RED, 4);
echo "After Set Channel depth: " . "</br>" ;
echo $im ->getImageChannelDepth(imagick::CHANNEL_RED) . "</br>" ;
?>
|
Output:
Before Set Channel depth:
8
After Set Channel depth:
4
Original Image:
Program 2:
<?php
$string = "Computer Science portal for Geeks!" ;
$im = new Imagick();
$draw = new ImagickDraw();
$draw ->setFillColor( new ImagickPixel( 'green' ));
$draw ->setFontSize(50);
$metrix = $im ->queryFontMetrics( $draw , $string );
$draw ->annotation(0, 40, $string );
$im ->newImage( $metrix [ 'textWidth' ], $metrix [ 'textHeight' ],
new ImagickPixel( 'white' ));
$im ->drawImage( $draw );
$im ->setImageFormat( 'jpeg' );
echo "Before Set Channel depth: " . "</br>" ;
echo $im ->getImageChannelDepth(imagick::CHANNEL_GREEN) . "</br>" ;
$im ->setImageChannelDepth(imagick::CHANNEL_GREEN, 8);
echo "After Set Channel depth: " . "</br>" ;
echo $im ->getImageChannelDepth(imagick::CHANNEL_GREEN) . "</br>" ;
?>
|
Output:
Before Set Channel depth:
16
After Set Channel depth:
8
Reference: http://php.net/manual/en/imagick.setimagechanneldepth.php
Last Updated :
26 Aug, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...