lib/channel.js
function extractChannel (channel) {
  if (channel === 'red') {
    channel = 0;
  } else if (channel === 'green') {
    channel = 1;
  } else if (channel === 'blue') {
    channel = 2;
  }
  if (is.integer(channel) && is.inRange(channel, 0, 4)) {
    this.options.extractChannel = channel;
  } else {
    throw new Error('Cannot extract invalid channel ' + channel);
  }
  return this;
}
function extractChannel (channel) {
  if (channel === 'red') {
    channel = 0;
  } else if (channel === 'green') {
    channel = 1;
  } else if (channel === 'blue') {
    channel = 2;
  }
  if (is.integer(channel) && is.inRange(channel, 0, 4)) {
    this.options.extractChannel = channel;
  } else {
    throw new Error('Cannot extract invalid channel ' + channel);
  }
  return this;
}
function extractChannel ( channel ) { if ( channel === 'red' ) { channel = 0 ; } else if ( channel === 'green' ) { channel = 1 ; } else if ( channel === 'blue' ) { channel = 2 ; } if ( is . integer ( channel ) && is . inRange ( channel , 0 , 4 ) ) { this . options . extractChannel = channel ; } else { throw new Error ( 'Cannot extract invalid channel ' + channel ) ; } return this ; }
Extract a single channel from a multi-channel image.

@example
sharp(input)
.extractChannel('green')
.toFile('input_green.jpg', function(err, info) {
// info.channels === 1
// input_green.jpg contains the green channel of the input image
});

@param {Number|String} channel - zero-indexed band number to extract, or `red`, `green` or `blue` as alternative to `0`, `1` or `2` respectively.
@returns {Sharp}
@throws {Error} Invalid channel
Extract a single channel from a multi - channel image .