Docs: add example of using metadata and resize to scale

This commit is contained in:
Lovell Fuller 2019-12-16 21:15:49 +00:00
parent e230ce41d7
commit 703d90e663
2 changed files with 17 additions and 0 deletions

View File

@ -114,6 +114,15 @@ sharp(input)
});
```
```javascript
const scaleByHalf = await sharp(input)
.metadata()
.then(({ width }) => sharp(input)
.resize(Math.round(width * 0.5))
.toBuffer()
);
```
- Throws **[Error][13]** Invalid parameters
Returns **Sharp**

View File

@ -173,6 +173,14 @@ const mapFitToCanvas = {
* // and no larger than the input image
* });
*
* @example
* const scaleByHalf = await sharp(input)
* .metadata()
* .then(({ width }) => sharp(input)
* .resize(Math.round(width * 0.5))
* .toBuffer()
* );
*
* @param {Number} [width] - pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.
* @param {Number} [height] - pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
* @param {Object} [options]