Skip to content

Commit 30296cf

Browse files
Refactor: autoOrient() is primary, rotate() is alias
1 parent c3e9be3 commit 30296cf

File tree

4 files changed

+46
-53
lines changed

4 files changed

+46
-53
lines changed

docs/api-operation.md

+19-23
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
## rotate
22
> rotate([angle], [options]) ⇒ <code>Sharp</code>
33
4-
Rotate the output image by either an explicit angle
5-
or auto-orient based on the EXIF `Orientation` tag.
4+
Rotate the output image.
65

7-
If an angle is provided, it is converted to a valid positive degree rotation.
6+
The provided angle is converted to a valid positive degree rotation.
87
For example, `-450` will produce a 270 degree rotation.
98

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

13-
If no angle is provided, it is determined from the EXIF data.
14-
Mirroring is supported and may infer the use of a flip operation.
15-
16-
The use of `rotate` without an angle will remove the EXIF `Orientation` tag, if any.
12+
For backwards compatibility, if no angle is provided, `.autoOrient()` will be called.
1713

1814
Only one rotation can occur per pipeline (aside from an initial call without
1915
arguments to orient via EXIF data). Previous calls to `rotate` in the same
@@ -36,18 +32,6 @@ for example `.rotate(x).extract(y)` will produce a different result to `.extract
3632
| [options] | <code>Object</code> | | if present, is an Object with optional attributes. |
3733
| [options.background] | <code>string</code> \| <code>Object</code> | <code>&quot;\&quot;#000000\&quot;&quot;</code> | parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. |
3834

39-
**Example**
40-
```js
41-
const pipeline = sharp()
42-
.rotate()
43-
.resize(null, 200)
44-
.toBuffer(function (err, outputBuffer, info) {
45-
// outputBuffer contains 200px high JPEG image data,
46-
// auto-rotated using EXIF Orientation tag
47-
// info.width and info.height contain the dimensions of the resized image
48-
});
49-
readableStream.pipe(pipeline);
50-
```
5135
**Example**
5236
```js
5337
const rotateThenResize = await sharp(input)
@@ -64,17 +48,29 @@ const resizeThenRotate = await sharp(input)
6448
## autoOrient
6549
> autoOrient() ⇒ <code>Sharp</code>
6650
67-
Alias for calling `rotate()` with no arguments, which orients the image based
68-
on EXIF orientsion.
51+
Auto-orient based on the EXIF `Orientation` tag, then remove the tag.
52+
Mirroring is supported and may infer the use of a flip operation.
6953

70-
This operation is aliased to emphasize its purpose, helping to remove any
71-
confusion between rotation and orientation.
54+
Previous or subsequent use of `rotate(angle)` and either `flip()` or `flop()`
55+
will logically occur after auto-orientation, regardless of call order.
7256

7357

7458
**Example**
7559
```js
7660
const output = await sharp(input).autoOrient().toBuffer();
7761
```
62+
**Example**
63+
```js
64+
const pipeline = sharp()
65+
.autoOrient()
66+
.resize(null, 200)
67+
.toBuffer(function (err, outputBuffer, info) {
68+
// outputBuffer contains 200px high JPEG image data,
69+
// auto-oriented using EXIF Orientation tag
70+
// info.width and info.height contain the dimensions of the resized image
71+
});
72+
readableStream.pipe(pipeline);
73+
```
7874

7975

8076
## flip

0 commit comments

Comments
 (0)