function transformImageColorspace($image_path, $colorSpace, $channel_number) { $imagick = new \Imagick(realpath($image_path)); $imagick->transformimagecolorspace($colorSpace); $imagick->separateImageChannel($channel_number); header("Content-Type: image/jpeg"); echo $imagick->getImageBlob(); }