Skip to content

Commit 4ac6505

Browse files
authored
Docs: add example of how to get the right-side-up width/height (#3127)
See #3124
1 parent 23033e2 commit 4ac6505

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

lib/input.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ function _isStreamInput () {
299299
*
300300
* - `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
301301
* - `size`: Total size of image in bytes, for Stream and Buffer input only
302-
* - `width`: Number of pixels wide (EXIF orientation is not taken into consideration)
303-
* - `height`: Number of pixels high (EXIF orientation is not taken into consideration)
302+
* - `width`: Number of pixels wide (EXIF orientation is not taken into consideration, see example below)
303+
* - `height`: Number of pixels high (EXIF orientation is not taken into consideration, see example below)
304304
* - `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://libvips.github.io/libvips/API/current/VipsImage.html#VipsInterpretation)
305305
* - `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
306306
* - `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...](https://libvips.github.io/libvips/API/current/VipsImage.html#VipsBandFormat)
@@ -343,6 +343,17 @@ function _isStreamInput () {
343343
* // data contains a WebP image half the width and height of the original JPEG
344344
* });
345345
*
346+
* @example
347+
* // Based on EXIF rotation metadata, get the right-side-up width and height:
348+
*
349+
* const size = getNormalSize(await sharp(input).metadata());
350+
*
351+
* function getNormalSize({ width, height, orientation }) {
352+
* return orientation || 0 >= 5
353+
* ? { width: height, height: width }
354+
* : { width, height };
355+
* }
356+
*
346357
* @param {Function} [callback] - called with the arguments `(err, metadata)`
347358
* @returns {Promise<Object>|Sharp}
348359
*/

0 commit comments

Comments
 (0)