Separates a channel from the image and returns a grayscale image. A channel is a particular color component of each pixel in the image.
Image
Channel
Separates a channel from the image and returns a grayscale image. A channel is a particular color component of each pixel in the image.
Parameters
channelint
function separateImageChannel($imagePath, $channel)
{
    $imagick = new \Imagick(realpath($imagePath));
    $imagick->separateimagechannel($channel);
    header("Content-Type: image/jpg");
    echo $imagick->getImageBlob();
}