lib/operation.js
function rotate (angle, options) {
  if (!is.defined(angle)) {
    this.options.useExifOrientation = true;
  } else if (is.integer(angle) && !(angle % 90)) {
    this.options.angle = angle;
  } else if (is.number(angle)) {
    this.options.rotationAngle = angle;
    if (is.object(options) && options.background) {
      const backgroundColour = color(options.background);
      this.options.rotationBackground = [
        backgroundColour.red(),
        backgroundColour.green(),
        backgroundColour.blue(),
        Math.round(backgroundColour.alpha() * 255)
      ];
    }
  } else {
    throw new Error('Unsupported angle: must be a number.');
  }
  return this;
}
function rotate (angle, options) {
  if (!is.defined(angle)) {
    this.options.useExifOrientation = true;
  } else if (is.integer(angle) && !(angle % 90)) {
    this.options.angle = angle;
  } else if (is.number(angle)) {
    this.options.rotationAngle = angle;
    if (is.object(options) && options.background) {
      const backgroundColour = color(options.background);
      this.options.rotationBackground = [
        backgroundColour.red(),
        backgroundColour.green(),
        backgroundColour.blue(),
        Math.round(backgroundColour.alpha() * 255)
      ];
    }
  } else {
    throw new Error('Unsupported angle: must be a number.');
  }
  return this;
}
function rotate ( angle , options ) { if ( ! is . defined ( angle ) ) { this . options . useExifOrientation = true ; } else if ( is . integer ( angle ) && ! ( angle % 90 ) ) { this . options . angle = angle ; } else if ( is . number ( angle ) ) { this . options . rotationAngle = angle ; if ( is . object ( options ) && options . background ) { const backgroundColour = color ( options . background ) ; this . options . rotationBackground = [ backgroundColour . red ( ) , backgroundColour . green ( ) , backgroundColour . blue ( ) , Math . round ( backgroundColour . alpha ( ) * 255 ) ] ; } } else { throw new Error ( 'Unsupported angle: must be a number.' ) ; } return this ; }
Rotate the output image by either an explicit angle
or auto-orient based on the EXIF `Orientation` tag.

If an angle is provided, it is converted to a valid positive degree rotation.
For example, `-450` will produce a 270deg rotation.

When rotating by an angle other than a multiple of 90,
the background colour can be provided with the `background` option.

If no angle is provided, it is determined from the EXIF data.
Mirroring is supported and may infer the use of a flip operation.

The use of `rotate` implies the removal of the EXIF `Orientation` tag, if any.

Method order is important when both rotating and extracting regions,
for example `rotate(x).extract(y)` will produce a different result to `extract(y).rotate(x)`.

@example
const pipeline = sharp()
.rotate()
.resize(null, 200)
.toBuffer(function (err, outputBuffer, info) {
// outputBuffer contains 200px high JPEG image data,
// auto-rotated using EXIF Orientation tag
// info.width and info.height contain the dimensions of the resized image
});
readableStream.pipe(pipeline);

@param {Number} [angle=auto] angle of rotation.
@param {Object} [options] - if present, is an Object with optional attributes.
@param {String|Object} [options.background="#000000"] parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
@returns {Sharp}
@throws {Error} Invalid parameters
Rotate the output image by either an explicit angle or auto - orient based on the EXIF Orientation tag .