lib/input.js
function stats (callback) {
  const that = this;
  if (is.fn(callback)) {
    if (this._isStreamInput()) {
      this.on('finish', function () {
        that._flattenBufferIn();
        sharp.stats(that.options, callback);
      });
    } else {
      sharp.stats(this.options, callback);
    }
    return this;
  } else {
    if (this._isStreamInput()) {
      return new Promise(function (resolve, reject) {
        that.on('finish', function () {
          that._flattenBufferIn();
          sharp.stats(that.options, function (err, stats) {
            if (err) {
              reject(err);
            } else {
              resolve(stats);
            }
          });
        });
      });
    } else {
      return new Promise(function (resolve, reject) {
        sharp.stats(that.options, function (err, stats) {
          if (err) {
            reject(err);
          } else {
            resolve(stats);
          }
        });
      });
    }
  }
}
function stats (callback) {
  const that = this;
  if (is.fn(callback)) {
    if (this._isStreamInput()) {
      this.on('finish', function () {
        that._flattenBufferIn();
        sharp.stats(that.options, callback);
      });
    } else {
      sharp.stats(this.options, callback);
    }
    return this;
  } else {
    if (this._isStreamInput()) {
      return new Promise(function (resolve, reject) {
        that.on('finish', function () {
          that._flattenBufferIn();
          sharp.stats(that.options, function (err, stats) {
            if (err) {
              reject(err);
            } else {
              resolve(stats);
            }
          });
        });
      });
    } else {
      return new Promise(function (resolve, reject) {
        sharp.stats(that.options, function (err, stats) {
          if (err) {
            reject(err);
          } else {
            resolve(stats);
          }
        });
      });
    }
  }
}
function stats ( callback ) { const that = this ; if ( is . fn ( callback ) ) { if ( this . _isStreamInput ( ) ) { this . on ( 'finish' , function ( ) { that . _flattenBufferIn ( ) ; sharp . stats ( that . options , callback ) ; } ) ; } else { sharp . stats ( this . options , callback ) ; } return this ; } else { if ( this . _isStreamInput ( ) ) { return new Promise ( function ( resolve , reject ) { that . on ( 'finish' , function ( ) { that . _flattenBufferIn ( ) ; sharp . stats ( that . options , function ( err , stats ) { if ( err ) { reject ( err ) ; } else { resolve ( stats ) ; } } ) ; } ) ; } ) ; } else { return new Promise ( function ( resolve , reject ) { sharp . stats ( that . options , function ( err , stats ) { if ( err ) { reject ( err ) ; } else { resolve ( stats ) ; } } ) ; } ) ; } } }
Access to pixel-derived image statistics for every channel in the image.
A `Promise` is returned when `callback` is not provided.

- `channels`: Array of channel statistics for each channel in the image. Each channel statistic contains
- `min` (minimum value in the channel)
- `max` (maximum value in the channel)
- `sum` (sum of all values in a channel)
- `squaresSum` (sum of squared values in a channel)
- `mean` (mean of the values in a channel)
- `stdev` (standard deviation for the values in a channel)
- `minX` (x-coordinate of one of the pixel where the minimum lies)
- `minY` (y-coordinate of one of the pixel where the minimum lies)
- `maxX` (x-coordinate of one of the pixel where the maximum lies)
- `maxY` (y-coordinate of one of the pixel where the maximum lies)
- `isOpaque`: Value to identify if the image is opaque or transparent, based on the presence and use of alpha channel
- `entropy`: Histogram-based estimation of greyscale entropy, discarding alpha channel if any (experimental)

@example
const image = sharp(inputJpg);
image
.stats()
.then(function(stats) {
// stats contains the channel-wise statistics array and the isOpaque value
});

@param {Function} [callback] - called with the arguments `(err, stats)`
@returns {Promise<Object>}
Access to pixel - derived image statistics for every channel in the image . A Promise is returned when callback is not provided .