function stats (callback) {
  const stack = Error();
  if (is.fn(callback)) {
    if (this._isStreamInput()) {
      this.on('finish', () => {
        this._flattenBufferIn();
        sharp.stats(this.options, (err, stats) => {
          if (err) {
            callback(is.nativeError(err, stack));
          } else {
            callback(null, stats);
          }
        });
      });
    } else {
      sharp.stats(this.options, (err, stats) => {
        if (err) {
          callback(is.nativeError(err, stack));
        } else {
          callback(null, stats);
        }
      });
    }
    return this;
  } else {
    if (this._isStreamInput()) {
      return new Promise((resolve, reject) => {
        this.on('finish', function () {
          this._flattenBufferIn();
          sharp.stats(this.options, (err, stats) => {
            if (err) {
              reject(is.nativeError(err, stack));
            } else {
              resolve(stats);
            }
          });
        });
      });
    } else {
      return new Promise((resolve, reject) => {
        sharp.stats(this.options, (err, stats) => {
          if (err) {
            reject(is.nativeError(err, stack));
          } 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`: Is the image fully opaque? Will be `true` if the image has no alpha channel or if every pixel is fully opaque.
- `entropy`: Histogram-based estimation of greyscale entropy, discarding alpha channel if any.
- `sharpness`: Estimation of greyscale sharpness based on the standard deviation of a Laplacian convolution, discarding alpha channel if any.
- `dominant`: Object containing most dominant sRGB colour based on a 4096-bin 3D histogram.

**Note**: Statistics are derived from the original input image. Any operations performed on the image must first be
written to a buffer in order to run `stats` on the result (see third example).

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

@example
const { entropy, sharpness, dominant } = await sharp(input).stats();
const { r, g, b } = dominant;

@example
const image = sharp(input);
// store intermediate result
const part = await image.extract(region).toBuffer();
// create new instance to obtain statistics of extracted region
const stats = await sharp(part).stats();

@param {Function} [callback] - called with the arguments `(err, stats)`
@returns {Promise<Object>}