PHP Imagick setImageChannelDepth () Function

PHP

Syntax:
bool Imagick::setImageChannelDepth ($channel, $depth)
Parameters:this function takes two parameters as above and described below:
  • $channel:this parameter is used to specify a channel constant. Below is a list of persistent channels:
    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 the Imagick.
Return Value:This function returns True if success.The following programs illustrate the Imagick::setImageChannelDepth()function in PHP:Original Image:
Program 1:  
// Create a new Imagick object $im = new Imagick ( ' https://media.engineerforengineer.org/wp-content/uploads/engineerforengineer-15.png ' );  
// Using the getImageChannelDepth function
// with red channel echo "Before Set Channel depth: " . "< / br >" ; echo $im -> getImageChannelDepth (imagick::CHANNEL_RED). "< / br >" ;  
// Set CYAN channel depth and GREEN channel $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: $string = "Computer Science portal for Geeks!" ;  
// Create a new image of the above line // and add color $im = new Imagick(); $draw = new ImagickDraw();  
// Fill the color in the 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 image $im -> drawImage ( $draw ); $im -> setImageFormat ( 'jpeg' );  
// Using the getImageChannelDepth function
// with red channel echo "Before Set Channel depth: " . "< / br >" ; echo $im -> getImageChannelDepth (imagick::CHANNEL_GREEN). "< / br >" ;  
// Set channel Green channel depth $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
Link: http://php.net/manual/en/imagick.setimagechanneldepth.php



Get Solution for free from DataCamp guru