mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Docs: add example of using metadata and resize to scale
This commit is contained in:
parent
e230ce41d7
commit
703d90e663
@ -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**
|
||||
|
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user