Skip to content

Commit

Permalink
Docs: refresh for metadata example lovell#3127
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell authored and martinj committed Mar 31, 2022
1 parent 92b6133 commit 0803671
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions docs/api-input.md
Expand Up @@ -11,8 +11,8 @@ A `Promise` is returned when `callback` is not provided.

* `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
* `size`: Total size of image in bytes, for Stream and Buffer input only
* `width`: Number of pixels wide (EXIF orientation is not taken into consideration)
* `height`: Number of pixels high (EXIF orientation is not taken into consideration)
* `width`: Number of pixels wide (EXIF orientation is not taken into consideration, see example below)
* `height`: Number of pixels high (EXIF orientation is not taken into consideration, see example below)
* `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][1]
* `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
* `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...][2]
Expand Down Expand Up @@ -63,6 +63,18 @@ image
});
```

```javascript
// Based on EXIF rotation metadata, get the right-side-up width and height:

const size = getNormalSize(await sharp(input).metadata());

function getNormalSize({ width, height, orientation }) {
return orientation || 0 >= 5
? { width: height, height: width }
: { width, height };
}
```

Returns **([Promise][5]<[Object][6]> | Sharp)**

## stats
Expand Down

0 comments on commit 0803671

Please sign in to comment.