mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Docs: switch to well-maintained jsdoc2md for JSDoc parsing
This commit is contained in:
parent
a42a975c46
commit
ef849fd639
@ -1,14 +1,11 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
||||||
|
|
||||||
## removeAlpha
|
## removeAlpha
|
||||||
|
|
||||||
Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
|
Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
|
||||||
|
|
||||||
See also [flatten][1].
|
See also [flatten](/api-operation#flatten).
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
**Example**
|
||||||
|
```js
|
||||||
sharp('rgba.png')
|
sharp('rgba.png')
|
||||||
.removeAlpha()
|
.removeAlpha()
|
||||||
.toFile('rgb.png', function(err, info) {
|
.toFile('rgb.png', function(err, info) {
|
||||||
@ -16,61 +13,62 @@ sharp('rgba.png')
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## ensureAlpha
|
## ensureAlpha
|
||||||
|
|
||||||
Ensure the output image has an alpha transparency channel.
|
Ensure the output image has an alpha transparency channel.
|
||||||
If missing, the added alpha channel will have the specified
|
If missing, the added alpha channel will have the specified
|
||||||
transparency level, defaulting to fully-opaque (1).
|
transparency level, defaulting to fully-opaque (1).
|
||||||
This is a no-op if the image already has an alpha channel.
|
This is a no-op if the image already has an alpha channel.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `alpha` **[number][2]** alpha transparency level (0=fully-transparent, 1=fully-opaque) (optional, default `1`)
|
**Throws**:
|
||||||
|
|
||||||
### Examples
|
- <code>Error</code> Invalid alpha transparency level
|
||||||
|
|
||||||
```javascript
|
**Since**: 0.21.2
|
||||||
|
|
||||||
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [alpha] | <code>number</code> | <code>1</code> | alpha transparency level (0=fully-transparent, 1=fully-opaque) |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
// rgba.png will be a 4 channel image with a fully-opaque alpha channel
|
// rgba.png will be a 4 channel image with a fully-opaque alpha channel
|
||||||
await sharp('rgb.jpg')
|
await sharp('rgb.jpg')
|
||||||
.ensureAlpha()
|
.ensureAlpha()
|
||||||
.toFile('rgba.png')
|
.toFile('rgba.png')
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// rgba is a 4 channel image with a fully-transparent alpha channel
|
// rgba is a 4 channel image with a fully-transparent alpha channel
|
||||||
const rgba = await sharp(rgb)
|
const rgba = await sharp(rgb)
|
||||||
.ensureAlpha(0)
|
.ensureAlpha(0)
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][3]** Invalid alpha transparency level
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
**Meta**
|
|
||||||
|
|
||||||
* **since**: 0.21.2
|
|
||||||
|
|
||||||
## extractChannel
|
## extractChannel
|
||||||
|
|
||||||
Extract a single channel from a multi-channel image.
|
Extract a single channel from a multi-channel image.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `channel` **([number][2] | [string][4])** zero-indexed channel/band number to extract, or `red`, `green`, `blue` or `alpha`.
|
**Throws**:
|
||||||
|
|
||||||
### Examples
|
- <code>Error</code> Invalid channel
|
||||||
|
|
||||||
```javascript
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| channel | <code>number</code> \| <code>string</code> | zero-indexed channel/band number to extract, or `red`, `green`, `blue` or `alpha`. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
// green.jpg is a greyscale image containing the green channel of the input
|
// green.jpg is a greyscale image containing the green channel of the input
|
||||||
await sharp(input)
|
await sharp(input)
|
||||||
.extractChannel('green')
|
.extractChannel('green')
|
||||||
.toFile('green.jpg');
|
.toFile('green.jpg');
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// red1 is the red value of the first pixel, red2 the second pixel etc.
|
// red1 is the red value of the first pixel, red2 the second pixel etc.
|
||||||
const [red1, red2, ...] = await sharp(input)
|
const [red1, red2, ...] = await sharp(input)
|
||||||
.extractChannel(0)
|
.extractChannel(0)
|
||||||
@ -78,45 +76,46 @@ const [red1, red2, ...] = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][3]** Invalid channel
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## joinChannel
|
## joinChannel
|
||||||
|
|
||||||
Join one or more channels to the image.
|
Join one or more channels to the image.
|
||||||
The meaning of the added channels depends on the output colourspace, set with `toColourspace()`.
|
The meaning of the added channels depends on the output colourspace, set with `toColourspace()`.
|
||||||
By default the output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
|
By default the output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
|
||||||
Channel ordering follows vips convention:
|
Channel ordering follows vips convention:
|
||||||
|
- sRGB: 0: Red, 1: Green, 2: Blue, 3: Alpha.
|
||||||
* sRGB: 0: Red, 1: Green, 2: Blue, 3: Alpha.
|
- CMYK: 0: Magenta, 1: Cyan, 2: Yellow, 3: Black, 4: Alpha.
|
||||||
* CMYK: 0: Magenta, 1: Cyan, 2: Yellow, 3: Black, 4: Alpha.
|
|
||||||
|
|
||||||
Buffers may be any of the image formats supported by sharp.
|
Buffers may be any of the image formats supported by sharp.
|
||||||
For raw pixel input, the `options` object should contain a `raw` attribute, which follows the format of the attribute of the same name in the `sharp()` constructor.
|
For raw pixel input, the `options` object should contain a `raw` attribute, which follows the format of the attribute of the same name in the `sharp()` constructor.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `images` **([Array][5]<([string][4] | [Buffer][6])> | [string][4] | [Buffer][6])** one or more images (file paths, Buffers).
|
**Throws**:
|
||||||
* `options` **[Object][7]** image options, see `sharp()` constructor.
|
|
||||||
|
|
||||||
<!---->
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| images | <code>Array.<(string\|Buffer)></code> \| <code>string</code> \| <code>Buffer</code> | one or more images (file paths, Buffers). |
|
||||||
|
| options | <code>Object</code> | image options, see `sharp()` constructor. |
|
||||||
|
|
||||||
* Throws **[Error][3]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## bandbool
|
## bandbool
|
||||||
|
|
||||||
Perform a bitwise boolean operation on all input image channels (bands) to produce a single channel output image.
|
Perform a bitwise boolean operation on all input image channels (bands) to produce a single channel output image.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `boolOp` **[string][4]** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
**Throws**:
|
||||||
|
|
||||||
### Examples
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
```javascript
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| boolOp | <code>string</code> | one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
sharp('3-channel-rgb-input.png')
|
sharp('3-channel-rgb-input.png')
|
||||||
.bandbool(sharp.bool.and)
|
.bandbool(sharp.bool.and)
|
||||||
.toFile('1-channel-output.png', function (err, info) {
|
.toFile('1-channel-output.png', function (err, info) {
|
||||||
@ -125,21 +124,3 @@ sharp('3-channel-rgb-input.png')
|
|||||||
// then `O(1,1) = 0b11110111 & 0b10101010 & 0b00001111 = 0b00000010 = 2`.
|
// then `O(1,1) = 0b11110111 & 0b10101010 & 0b00001111 = 0b00000010 = 2`.
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][3]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
[1]: /api-operation#flatten
|
|
||||||
|
|
||||||
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
||||||
|
|
||||||
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
||||||
|
|
||||||
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
||||||
|
|
||||||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
||||||
|
|
||||||
[6]: https://nodejs.org/api/buffer.html
|
|
||||||
|
|
||||||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
@ -1,28 +1,26 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
||||||
|
|
||||||
## tint
|
## tint
|
||||||
|
|
||||||
Tint the image using the provided chroma while preserving the image luminance.
|
Tint the image using the provided chroma while preserving the image luminance.
|
||||||
An alpha channel may be present and will be unchanged by the operation.
|
An alpha channel may be present and will be unchanged by the operation.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `rgb` **([string][1] | [Object][2])** parsed by the [color][3] module to extract chroma values.
|
**Throws**:
|
||||||
|
|
||||||
### Examples
|
- <code>Error</code> Invalid parameter
|
||||||
|
|
||||||
```javascript
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| rgb | <code>string</code> \| <code>Object</code> | parsed by the [color](https://www.npmjs.org/package/color) module to extract chroma values. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
const output = await sharp(input)
|
const output = await sharp(input)
|
||||||
.tint({ r: 255, g: 240, b: 16 })
|
.tint({ r: 255, g: 240, b: 16 })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid parameter
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## greyscale
|
## greyscale
|
||||||
|
|
||||||
Convert to 8-bit greyscale; 256 shades of grey.
|
Convert to 8-bit greyscale; 256 shades of grey.
|
||||||
This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
|
This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
|
||||||
By default the output image will be web-friendly sRGB and contain three (identical) color channels.
|
By default the output image will be web-friendly sRGB and contain three (identical) color channels.
|
||||||
@ -30,44 +28,50 @@ This may be overridden by other sharp operations such as `toColourspace('b-w')`,
|
|||||||
which will produce an output image containing one color channel.
|
which will produce an output image containing one color channel.
|
||||||
An alpha channel may be present, and will be unchanged by the operation.
|
An alpha channel may be present, and will be unchanged by the operation.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `greyscale` **[Boolean][5]** (optional, default `true`)
|
|
||||||
|
|
||||||
### Examples
|
| Param | Type | Default |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| [greyscale] | <code>Boolean</code> | <code>true</code> |
|
||||||
|
|
||||||
```javascript
|
**Example**
|
||||||
|
```js
|
||||||
const output = await sharp(input).greyscale().toBuffer();
|
const output = await sharp(input).greyscale().toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## grayscale
|
## grayscale
|
||||||
|
|
||||||
Alternative spelling of `greyscale`.
|
Alternative spelling of `greyscale`.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `grayscale` **[Boolean][5]** (optional, default `true`)
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
| Param | Type | Default |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| [grayscale] | <code>Boolean</code> | <code>true</code> |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## pipelineColourspace
|
## pipelineColourspace
|
||||||
|
|
||||||
Set the pipeline colourspace.
|
Set the pipeline colourspace.
|
||||||
|
|
||||||
The input image will be converted to the provided colourspace at the start of the pipeline.
|
The input image will be converted to the provided colourspace at the start of the pipeline.
|
||||||
All operations will use this colourspace before converting to the output colourspace, as defined by [toColourspace][6].
|
All operations will use this colourspace before converting to the output colourspace, as defined by [toColourspace](#toColourspace).
|
||||||
|
|
||||||
This feature is experimental and has not yet been fully-tested with all operations.
|
This feature is experimental and has not yet been fully-tested with all operations.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `colourspace` **[string][1]?** pipeline colourspace e.g. `rgb16`, `scrgb`, `lab`, `grey16` [...][7]
|
**Throws**:
|
||||||
|
|
||||||
### Examples
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
```javascript
|
**Since**: 0.29.0
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| [colourspace] | <code>string</code> | pipeline colourspace e.g. `rgb16`, `scrgb`, `lab`, `grey16` [...](https://github.com/libvips/libvips/blob/41cff4e9d0838498487a00623462204eb10ee5b8/libvips/iofuncs/enumtypes.c#L774) |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
// Run pipeline in 16 bits per channel RGB while converting final result to 8 bits per channel sRGB.
|
// Run pipeline in 16 bits per channel RGB while converting final result to 8 bits per channel sRGB.
|
||||||
await sharp(input)
|
await sharp(input)
|
||||||
.pipelineColourspace('rgb16')
|
.pipelineColourspace('rgb16')
|
||||||
@ -75,76 +79,54 @@ await sharp(input)
|
|||||||
.toFile('16bpc-pipeline-to-8bpc-output.png')
|
.toFile('16bpc-pipeline-to-8bpc-output.png')
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
**Meta**
|
|
||||||
|
|
||||||
* **since**: 0.29.0
|
|
||||||
|
|
||||||
## pipelineColorspace
|
## pipelineColorspace
|
||||||
|
|
||||||
Alternative spelling of `pipelineColourspace`.
|
Alternative spelling of `pipelineColourspace`.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `colorspace` **[string][1]?** pipeline colorspace.
|
**Throws**:
|
||||||
|
|
||||||
<!---->
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| [colorspace] | <code>string</code> | pipeline colorspace. |
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## toColourspace
|
## toColourspace
|
||||||
|
|
||||||
Set the output colourspace.
|
Set the output colourspace.
|
||||||
By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
|
By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `colourspace` **[string][1]?** output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][8]
|
**Throws**:
|
||||||
|
|
||||||
### Examples
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
```javascript
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| [colourspace] | <code>string</code> | output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://github.com/libvips/libvips/blob/3c0bfdf74ce1dc37a6429bed47fa76f16e2cd70a/libvips/iofuncs/enumtypes.c#L777-L794) |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
// Output 16 bits per pixel RGB
|
// Output 16 bits per pixel RGB
|
||||||
await sharp(input)
|
await sharp(input)
|
||||||
.toColourspace('rgb16')
|
.toColourspace('rgb16')
|
||||||
.toFile('16-bpp.png')
|
.toFile('16-bpp.png')
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## toColorspace
|
## toColorspace
|
||||||
|
|
||||||
Alternative spelling of `toColourspace`.
|
Alternative spelling of `toColourspace`.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `colorspace` **[string][1]?** output colorspace.
|
**Throws**:
|
||||||
|
|
||||||
<!---->
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
| [colorspace] | <code>string</code> | output colorspace. |
|
||||||
|
|
||||||
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
|
||||||
[3]: https://www.npmjs.org/package/color
|
|
||||||
|
|
||||||
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
||||||
|
|
||||||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
||||||
|
|
||||||
[6]: #tocolourspace
|
|
||||||
|
|
||||||
[7]: https://github.com/libvips/libvips/blob/41cff4e9d0838498487a00623462204eb10ee5b8/libvips/iofuncs/enumtypes.c#L774
|
|
||||||
|
|
||||||
[8]: https://github.com/libvips/libvips/blob/3c0bfdf74ce1dc37a6429bed47fa76f16e2cd70a/libvips/iofuncs/enumtypes.c#L777-L794
|
|
@ -1,7 +1,4 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
||||||
|
|
||||||
## composite
|
## composite
|
||||||
|
|
||||||
Composite image(s) over the processed (resized, extracted etc.) image.
|
Composite image(s) over the processed (resized, extracted etc.) image.
|
||||||
|
|
||||||
The images to composite must be the same size or smaller than the processed image.
|
The images to composite must be the same size or smaller than the processed image.
|
||||||
@ -17,52 +14,53 @@ The `blend` option can be one of `clear`, `source`, `over`, `in`, `out`, `atop`,
|
|||||||
`hard-light`, `soft-light`, `difference`, `exclusion`.
|
`hard-light`, `soft-light`, `difference`, `exclusion`.
|
||||||
|
|
||||||
More information about blend modes can be found at
|
More information about blend modes can be found at
|
||||||
[https://www.libvips.org/API/current/libvips-conversion.html#VipsBlendMode][1]
|
https://www.libvips.org/API/current/libvips-conversion.html#VipsBlendMode
|
||||||
and [https://www.cairographics.org/operators/][2]
|
and https://www.cairographics.org/operators/
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `images` **[Array][3]<[Object][4]>** Ordered list of images to composite
|
**Throws**:
|
||||||
|
|
||||||
* `images[].input` **([Buffer][5] | [String][6])?** Buffer containing image data, String containing the path to an image file, or Create object (see below)
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
* `images[].input.create` **[Object][4]?** describes a blank overlay to be created.
|
**Since**: 0.22.0
|
||||||
|
|
||||||
* `images[].input.create.width` **[Number][7]?** 
|
| Param | Type | Default | Description |
|
||||||
* `images[].input.create.height` **[Number][7]?** 
|
| --- | --- | --- | --- |
|
||||||
* `images[].input.create.channels` **[Number][7]?** 3-4
|
| images | <code>Array.<Object></code> | | Ordered list of images to composite |
|
||||||
* `images[].input.create.background` **([String][6] | [Object][4])?** parsed by the [color][8] module to extract values for red, green, blue and alpha.
|
| [images[].input] | <code>Buffer</code> \| <code>String</code> | | Buffer containing image data, String containing the path to an image file, or Create object (see below) |
|
||||||
* `images[].input.text` **[Object][4]?** describes a new text image to be created.
|
| [images[].input.create] | <code>Object</code> | | describes a blank overlay to be created. |
|
||||||
|
| [images[].input.create.width] | <code>Number</code> | | |
|
||||||
|
| [images[].input.create.height] | <code>Number</code> | | |
|
||||||
|
| [images[].input.create.channels] | <code>Number</code> | | 3-4 |
|
||||||
|
| [images[].input.create.background] | <code>String</code> \| <code>Object</code> | | parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. |
|
||||||
|
| [images[].input.text] | <code>Object</code> | | describes a new text image to be created. |
|
||||||
|
| [images[].input.text.text] | <code>string</code> | | text to render as a UTF-8 string. It can contain Pango markup, for example `<i>Le</i>Monde`. |
|
||||||
|
| [images[].input.text.font] | <code>string</code> | | font name to render with. |
|
||||||
|
| [images[].input.text.fontfile] | <code>string</code> | | absolute filesystem path to a font file that can be used by `font`. |
|
||||||
|
| [images[].input.text.width] | <code>number</code> | <code>0</code> | integral number of pixels to word-wrap at. Lines of text wider than this will be broken at word boundaries. |
|
||||||
|
| [images[].input.text.height] | <code>number</code> | <code>0</code> | integral number of pixels high. When defined, `dpi` will be ignored and the text will automatically fit the pixel resolution defined by `width` and `height`. Will be ignored if `width` is not specified or set to 0. |
|
||||||
|
| [images[].input.text.align] | <code>string</code> | <code>"'left'"</code> | text alignment (`'left'`, `'centre'`, `'center'`, `'right'`). |
|
||||||
|
| [images[].input.text.justify] | <code>boolean</code> | <code>false</code> | set this to true to apply justification to the text. |
|
||||||
|
| [images[].input.text.dpi] | <code>number</code> | <code>72</code> | the resolution (size) at which to render the text. Does not take effect if `height` is specified. |
|
||||||
|
| [images[].input.text.rgba] | <code>boolean</code> | <code>false</code> | set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `<span foreground="red">Red!</span>`. |
|
||||||
|
| [images[].input.text.spacing] | <code>number</code> | <code>0</code> | text line height in points. Will use the font line height if none is specified. |
|
||||||
|
| [images[].blend] | <code>String</code> | <code>'over'</code> | how to blend this image with the image below. |
|
||||||
|
| [images[].gravity] | <code>String</code> | <code>'centre'</code> | gravity at which to place the overlay. |
|
||||||
|
| [images[].top] | <code>Number</code> | | the pixel offset from the top edge. |
|
||||||
|
| [images[].left] | <code>Number</code> | | the pixel offset from the left edge. |
|
||||||
|
| [images[].tile] | <code>Boolean</code> | <code>false</code> | set to true to repeat the overlay image across the entire image with the given `gravity`. |
|
||||||
|
| [images[].premultiplied] | <code>Boolean</code> | <code>false</code> | set to true to avoid premultipling the image below. Equivalent to the `--premultiplied` vips option. |
|
||||||
|
| [images[].density] | <code>Number</code> | <code>72</code> | number representing the DPI for vector overlay image. |
|
||||||
|
| [images[].raw] | <code>Object</code> | | describes overlay when using raw pixel data. |
|
||||||
|
| [images[].raw.width] | <code>Number</code> | | |
|
||||||
|
| [images[].raw.height] | <code>Number</code> | | |
|
||||||
|
| [images[].raw.channels] | <code>Number</code> | | |
|
||||||
|
| [images[].animated] | <code>boolean</code> | <code>false</code> | Set to `true` to read all frames/pages of an animated image. |
|
||||||
|
| [images[].failOn] | <code>string</code> | <code>"'warning'"</code> | @see [constructor parameters](/api-constructor#parameters) |
|
||||||
|
| [images[].limitInputPixels] | <code>number</code> \| <code>boolean</code> | <code>268402689</code> | @see [constructor parameters](/api-constructor#parameters) |
|
||||||
|
|
||||||
* `images[].input.text.text` **[string][6]?** text to render as a UTF-8 string. It can contain Pango markup, for example `<i>Le</i>Monde`.
|
**Example**
|
||||||
* `images[].input.text.font` **[string][6]?** font name to render with.
|
```js
|
||||||
* `images[].input.text.fontfile` **[string][6]?** absolute filesystem path to a font file that can be used by `font`.
|
|
||||||
* `images[].input.text.width` **[number][7]** integral number of pixels to word-wrap at. Lines of text wider than this will be broken at word boundaries. (optional, default `0`)
|
|
||||||
* `images[].input.text.height` **[number][7]** integral number of pixels high. When defined, `dpi` will be ignored and the text will automatically fit the pixel resolution defined by `width` and `height`. Will be ignored if `width` is not specified or set to 0. (optional, default `0`)
|
|
||||||
* `images[].input.text.align` **[string][6]** text alignment (`'left'`, `'centre'`, `'center'`, `'right'`). (optional, default `'left'`)
|
|
||||||
* `images[].input.text.justify` **[boolean][9]** set this to true to apply justification to the text. (optional, default `false`)
|
|
||||||
* `images[].input.text.dpi` **[number][7]** the resolution (size) at which to render the text. Does not take effect if `height` is specified. (optional, default `72`)
|
|
||||||
* `images[].input.text.rgba` **[boolean][9]** set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `<span foreground="red">Red!</span>`. (optional, default `false`)
|
|
||||||
* `images[].input.text.spacing` **[number][7]** text line height in points. Will use the font line height if none is specified. (optional, default `0`)
|
|
||||||
* `images[].blend` **[String][6]** how to blend this image with the image below. (optional, default `'over'`)
|
|
||||||
* `images[].gravity` **[String][6]** gravity at which to place the overlay. (optional, default `'centre'`)
|
|
||||||
* `images[].top` **[Number][7]?** the pixel offset from the top edge.
|
|
||||||
* `images[].left` **[Number][7]?** the pixel offset from the left edge.
|
|
||||||
* `images[].tile` **[Boolean][9]** set to true to repeat the overlay image across the entire image with the given `gravity`. (optional, default `false`)
|
|
||||||
* `images[].premultiplied` **[Boolean][9]** set to true to avoid premultipling the image below. Equivalent to the `--premultiplied` vips option. (optional, default `false`)
|
|
||||||
* `images[].density` **[Number][7]** number representing the DPI for vector overlay image. (optional, default `72`)
|
|
||||||
* `images[].raw` **[Object][4]?** describes overlay when using raw pixel data.
|
|
||||||
|
|
||||||
* `images[].raw.width` **[Number][7]?** 
|
|
||||||
* `images[].raw.height` **[Number][7]?** 
|
|
||||||
* `images[].raw.channels` **[Number][7]?** 
|
|
||||||
* `images[].animated` **[boolean][9]** Set to `true` to read all frames/pages of an animated image. (optional, default `false`)
|
|
||||||
* `images[].failOn` **[string][6]** @see [constructor parameters][10] (optional, default `'warning'`)
|
|
||||||
* `images[].limitInputPixels` **([number][7] | [boolean][9])** @see [constructor parameters][10] (optional, default `268402689`)
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
await sharp(background)
|
await sharp(background)
|
||||||
.composite([
|
.composite([
|
||||||
{ input: layer1, gravity: 'northwest' },
|
{ input: layer1, gravity: 'northwest' },
|
||||||
@ -70,16 +68,16 @@ await sharp(background)
|
|||||||
])
|
])
|
||||||
.toFile('combined.png');
|
.toFile('combined.png');
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const output = await sharp('input.gif', { animated: true })
|
const output = await sharp('input.gif', { animated: true })
|
||||||
.composite([
|
.composite([
|
||||||
{ input: 'overlay.png', tile: true, blend: 'saturate' }
|
{ input: 'overlay.png', tile: true, blend: 'saturate' }
|
||||||
])
|
])
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
sharp('input.png')
|
sharp('input.png')
|
||||||
.rotate(180)
|
.rotate(180)
|
||||||
.resize(300)
|
.resize(300)
|
||||||
@ -95,33 +93,3 @@ sharp('input.png')
|
|||||||
// sharpened, with metadata, 90% quality WebP image data. Phew!
|
// sharpened, with metadata, 90% quality WebP image data. Phew!
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][11]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
**Meta**
|
|
||||||
|
|
||||||
* **since**: 0.22.0
|
|
||||||
|
|
||||||
[1]: https://www.libvips.org/API/current/libvips-conversion.html#VipsBlendMode
|
|
||||||
|
|
||||||
[2]: https://www.cairographics.org/operators/
|
|
||||||
|
|
||||||
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
||||||
|
|
||||||
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
|
||||||
[5]: https://nodejs.org/api/buffer.html
|
|
||||||
|
|
||||||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
||||||
|
|
||||||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
||||||
|
|
||||||
[8]: https://www.npmjs.org/package/color
|
|
||||||
|
|
||||||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
||||||
|
|
||||||
[10]: /api-constructor#parameters
|
|
||||||
|
|
||||||
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
||||||
|
|
||||||
## Sharp
|
## Sharp
|
||||||
|
|
||||||
|
**Emits**: <code>Sharp#event:info</code>, <code>Sharp#event:warning</code>
|
||||||
|
<a name="new_Sharp_new"></a>
|
||||||
|
|
||||||
|
### new
|
||||||
Constructor factory to create an instance of `sharp`, to which further methods are chained.
|
Constructor factory to create an instance of `sharp`, to which further methods are chained.
|
||||||
|
|
||||||
JPEG, PNG, WebP, GIF, AVIF or TIFF format image data can be streamed out from this object.
|
JPEG, PNG, WebP, GIF, AVIF or TIFF format image data can be streamed out from this object.
|
||||||
@ -9,65 +11,56 @@ When using Stream based output, derived attributes are available from the `info`
|
|||||||
|
|
||||||
Non-critical problems encountered during processing are emitted as `warning` events.
|
Non-critical problems encountered during processing are emitted as `warning` events.
|
||||||
|
|
||||||
Implements the [stream.Duplex][1] class.
|
Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_stream_duplex) class.
|
||||||
|
|
||||||
### Parameters
|
**Throws**:
|
||||||
|
|
||||||
* `input` **([Buffer][2] | [Uint8Array][3] | [Uint8ClampedArray][4] | [Int8Array][5] | [Uint16Array][6] | [Int16Array][7] | [Uint32Array][8] | [Int32Array][9] | [Float32Array][10] | [Float64Array][11] | [string][12])?** if present, can be
|
- <code>Error</code> Invalid parameters
|
||||||
a Buffer / Uint8Array / Uint8ClampedArray containing JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image data, or
|
|
||||||
a TypedArray containing raw pixel image data, or
|
|
||||||
a String containing the filesystem path to an JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image file.
|
|
||||||
JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
|
||||||
* `options` **[Object][13]?** if present, is an Object with optional attributes.
|
|
||||||
|
|
||||||
* `options.failOn` **[string][12]** when to abort processing of invalid pixel data, one of (in order of sensitivity): 'none' (least), 'truncated', 'error' or 'warning' (most), highers level imply lower levels, invalid metadata will always abort. (optional, default `'warning'`)
|
|
||||||
* `options.limitInputPixels` **([number][14] | [boolean][15])** Do not process input images where the number of pixels
|
|
||||||
(width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted.
|
|
||||||
An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). (optional, default `268402689`)
|
|
||||||
* `options.unlimited` **[boolean][15]** Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF). (optional, default `false`)
|
|
||||||
* `options.sequentialRead` **[boolean][15]** Set this to `true` to use sequential rather than random access where possible.
|
|
||||||
This can reduce memory usage and might improve performance on some systems. (optional, default `false`)
|
|
||||||
* `options.density` **[number][14]** number representing the DPI for vector images in the range 1 to 100000. (optional, default `72`)
|
|
||||||
* `options.pages` **[number][14]** number of pages to extract for multi-page input (GIF, WebP, AVIF, TIFF, PDF), use -1 for all pages. (optional, default `1`)
|
|
||||||
* `options.page` **[number][14]** page number to start extracting from for multi-page input (GIF, WebP, AVIF, TIFF, PDF), zero based. (optional, default `0`)
|
|
||||||
* `options.subifd` **[number][14]** subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image. (optional, default `-1`)
|
|
||||||
* `options.level` **[number][14]** level to extract from a multi-level input (OpenSlide), zero based. (optional, default `0`)
|
|
||||||
* `options.animated` **[boolean][15]** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default `false`)
|
|
||||||
* `options.raw` **[Object][13]?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
|
||||||
|
|
||||||
* `options.raw.width` **[number][14]?** integral number of pixels wide.
|
| Param | Type | Default | Description |
|
||||||
* `options.raw.height` **[number][14]?** integral number of pixels high.
|
| --- | --- | --- | --- |
|
||||||
* `options.raw.channels` **[number][14]?** integral number of channels, between 1 and 4.
|
| [input] | <code>Buffer</code> \| <code>Uint8Array</code> \| <code>Uint8ClampedArray</code> \| <code>Int8Array</code> \| <code>Uint16Array</code> \| <code>Int16Array</code> \| <code>Uint32Array</code> \| <code>Int32Array</code> \| <code>Float32Array</code> \| <code>Float64Array</code> \| <code>string</code> | | if present, can be a Buffer / Uint8Array / Uint8ClampedArray containing JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image data, or a TypedArray containing raw pixel image data, or a String containing the filesystem path to an JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image file. JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present. |
|
||||||
* `options.raw.premultiplied` **[boolean][15]?** specifies that the raw input has already been premultiplied, set to `true`
|
| [options] | <code>Object</code> | | if present, is an Object with optional attributes. |
|
||||||
to avoid sharp premultiplying the image. (optional, default `false`)
|
| [options.failOn] | <code>string</code> | <code>"'warning'"</code> | when to abort processing of invalid pixel data, one of (in order of sensitivity): 'none' (least), 'truncated', 'error' or 'warning' (most), highers level imply lower levels, invalid metadata will always abort. |
|
||||||
* `options.create` **[Object][13]?** describes a new image to be created.
|
| [options.limitInputPixels] | <code>number</code> \| <code>boolean</code> | <code>268402689</code> | Do not process input images where the number of pixels (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted. An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). |
|
||||||
|
| [options.unlimited] | <code>boolean</code> | <code>false</code> | Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF). |
|
||||||
|
| [options.sequentialRead] | <code>boolean</code> | <code>false</code> | Set this to `true` to use sequential rather than random access where possible. This can reduce memory usage and might improve performance on some systems. |
|
||||||
|
| [options.density] | <code>number</code> | <code>72</code> | number representing the DPI for vector images in the range 1 to 100000. |
|
||||||
|
| [options.pages] | <code>number</code> | <code>1</code> | number of pages to extract for multi-page input (GIF, WebP, AVIF, TIFF, PDF), use -1 for all pages. |
|
||||||
|
| [options.page] | <code>number</code> | <code>0</code> | page number to start extracting from for multi-page input (GIF, WebP, AVIF, TIFF, PDF), zero based. |
|
||||||
|
| [options.subifd] | <code>number</code> | <code>-1</code> | subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image. |
|
||||||
|
| [options.level] | <code>number</code> | <code>0</code> | level to extract from a multi-level input (OpenSlide), zero based. |
|
||||||
|
| [options.animated] | <code>boolean</code> | <code>false</code> | Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). |
|
||||||
|
| [options.raw] | <code>Object</code> | | describes raw pixel input image data. See `raw()` for pixel ordering. |
|
||||||
|
| [options.raw.width] | <code>number</code> | | integral number of pixels wide. |
|
||||||
|
| [options.raw.height] | <code>number</code> | | integral number of pixels high. |
|
||||||
|
| [options.raw.channels] | <code>number</code> | | integral number of channels, between 1 and 4. |
|
||||||
|
| [options.raw.premultiplied] | <code>boolean</code> | | specifies that the raw input has already been premultiplied, set to `true` to avoid sharp premultiplying the image. (optional, default `false`) |
|
||||||
|
| [options.create] | <code>Object</code> | | describes a new image to be created. |
|
||||||
|
| [options.create.width] | <code>number</code> | | integral number of pixels wide. |
|
||||||
|
| [options.create.height] | <code>number</code> | | integral number of pixels high. |
|
||||||
|
| [options.create.channels] | <code>number</code> | | integral number of channels, either 3 (RGB) or 4 (RGBA). |
|
||||||
|
| [options.create.background] | <code>string</code> \| <code>Object</code> | | parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. |
|
||||||
|
| [options.create.noise] | <code>Object</code> | | describes a noise to be created. |
|
||||||
|
| [options.create.noise.type] | <code>string</code> | | type of generated noise, currently only `gaussian` is supported. |
|
||||||
|
| [options.create.noise.mean] | <code>number</code> | | mean of pixels in generated noise. |
|
||||||
|
| [options.create.noise.sigma] | <code>number</code> | | standard deviation of pixels in generated noise. |
|
||||||
|
| [options.text] | <code>Object</code> | | describes a new text image to be created. |
|
||||||
|
| [options.text.text] | <code>string</code> | | text to render as a UTF-8 string. It can contain Pango markup, for example `<i>Le</i>Monde`. |
|
||||||
|
| [options.text.font] | <code>string</code> | | font name to render with. |
|
||||||
|
| [options.text.fontfile] | <code>string</code> | | absolute filesystem path to a font file that can be used by `font`. |
|
||||||
|
| [options.text.width] | <code>number</code> | <code>0</code> | integral number of pixels to word-wrap at. Lines of text wider than this will be broken at word boundaries. |
|
||||||
|
| [options.text.height] | <code>number</code> | <code>0</code> | integral number of pixels high. When defined, `dpi` will be ignored and the text will automatically fit the pixel resolution defined by `width` and `height`. Will be ignored if `width` is not specified or set to 0. |
|
||||||
|
| [options.text.align] | <code>string</code> | <code>"'left'"</code> | text alignment (`'left'`, `'centre'`, `'center'`, `'right'`). |
|
||||||
|
| [options.text.justify] | <code>boolean</code> | <code>false</code> | set this to true to apply justification to the text. |
|
||||||
|
| [options.text.dpi] | <code>number</code> | <code>72</code> | the resolution (size) at which to render the text. Does not take effect if `height` is specified. |
|
||||||
|
| [options.text.rgba] | <code>boolean</code> | <code>false</code> | set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `<span foreground="red">Red!</span>`. |
|
||||||
|
| [options.text.spacing] | <code>number</code> | <code>0</code> | text line height in points. Will use the font line height if none is specified. |
|
||||||
|
| [options.text.wrap] | <code>number</code> | <code>'word'</code> | word wrapping style when width is provided, one of: 'word', 'char', 'charWord' (prefer char, fallback to word) or 'none'. |
|
||||||
|
|
||||||
* `options.create.width` **[number][14]?** integral number of pixels wide.
|
**Example**
|
||||||
* `options.create.height` **[number][14]?** integral number of pixels high.
|
```js
|
||||||
* `options.create.channels` **[number][14]?** integral number of channels, either 3 (RGB) or 4 (RGBA).
|
|
||||||
* `options.create.background` **([string][12] | [Object][13])?** parsed by the [color][16] module to extract values for red, green, blue and alpha.
|
|
||||||
* `options.create.noise` **[Object][13]?** describes a noise to be created.
|
|
||||||
|
|
||||||
* `options.create.noise.type` **[string][12]?** type of generated noise, currently only `gaussian` is supported.
|
|
||||||
* `options.create.noise.mean` **[number][14]?** mean of pixels in generated noise.
|
|
||||||
* `options.create.noise.sigma` **[number][14]?** standard deviation of pixels in generated noise.
|
|
||||||
* `options.text` **[Object][13]?** describes a new text image to be created.
|
|
||||||
|
|
||||||
* `options.text.text` **[string][12]?** text to render as a UTF-8 string. It can contain Pango markup, for example `<i>Le</i>Monde`.
|
|
||||||
* `options.text.font` **[string][12]?** font name to render with.
|
|
||||||
* `options.text.fontfile` **[string][12]?** absolute filesystem path to a font file that can be used by `font`.
|
|
||||||
* `options.text.width` **[number][14]** integral number of pixels to word-wrap at. Lines of text wider than this will be broken at word boundaries. (optional, default `0`)
|
|
||||||
* `options.text.height` **[number][14]** integral number of pixels high. When defined, `dpi` will be ignored and the text will automatically fit the pixel resolution defined by `width` and `height`. Will be ignored if `width` is not specified or set to 0. (optional, default `0`)
|
|
||||||
* `options.text.align` **[string][12]** text alignment (`'left'`, `'centre'`, `'center'`, `'right'`). (optional, default `'left'`)
|
|
||||||
* `options.text.justify` **[boolean][15]** set this to true to apply justification to the text. (optional, default `false`)
|
|
||||||
* `options.text.dpi` **[number][14]** the resolution (size) at which to render the text. Does not take effect if `height` is specified. (optional, default `72`)
|
|
||||||
* `options.text.rgba` **[boolean][15]** set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `<span foreground="red">Red!</span>`. (optional, default `false`)
|
|
||||||
* `options.text.spacing` **[number][14]** text line height in points. Will use the font line height if none is specified. (optional, default `0`)
|
|
||||||
* `options.text.wrap` **[number][14]** word wrapping style when width is provided, one of: 'word', 'char', 'charWord' (prefer char, fallback to word) or 'none'. (optional, default `'word'`)
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
sharp('input.jpg')
|
sharp('input.jpg')
|
||||||
.resize(300, 200)
|
.resize(300, 200)
|
||||||
.toFile('output.jpg', function(err) {
|
.toFile('output.jpg', function(err) {
|
||||||
@ -75,8 +68,8 @@ sharp('input.jpg')
|
|||||||
// containing a scaled and cropped version of input.jpg
|
// containing a scaled and cropped version of input.jpg
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Read image data from readableStream,
|
// Read image data from readableStream,
|
||||||
// resize to 300 pixels wide,
|
// resize to 300 pixels wide,
|
||||||
// emit an 'info' event with calculated dimensions
|
// emit an 'info' event with calculated dimensions
|
||||||
@ -88,8 +81,8 @@ var transformer = sharp()
|
|||||||
});
|
});
|
||||||
readableStream.pipe(transformer).pipe(writableStream);
|
readableStream.pipe(transformer).pipe(writableStream);
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Create a blank 300x200 PNG image of semi-transluent red pixels
|
// Create a blank 300x200 PNG image of semi-transluent red pixels
|
||||||
sharp({
|
sharp({
|
||||||
create: {
|
create: {
|
||||||
@ -103,13 +96,13 @@ sharp({
|
|||||||
.toBuffer()
|
.toBuffer()
|
||||||
.then( ... );
|
.then( ... );
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Convert an animated GIF to an animated WebP
|
// Convert an animated GIF to an animated WebP
|
||||||
await sharp('in.gif', { animated: true }).toFile('out.webp');
|
await sharp('in.gif', { animated: true }).toFile('out.webp');
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Read a raw array of pixels and save it to a png
|
// Read a raw array of pixels and save it to a png
|
||||||
const input = Uint8Array.from([255, 255, 255, 0, 0, 0]); // or Uint8ClampedArray
|
const input = Uint8Array.from([255, 255, 255, 0, 0, 0]); // or Uint8ClampedArray
|
||||||
const image = sharp(input, {
|
const image = sharp(input, {
|
||||||
@ -123,8 +116,8 @@ const image = sharp(input, {
|
|||||||
});
|
});
|
||||||
await image.toFile('my-two-pixels.png');
|
await image.toFile('my-two-pixels.png');
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Generate RGB Gaussian noise
|
// Generate RGB Gaussian noise
|
||||||
await sharp({
|
await sharp({
|
||||||
create: {
|
create: {
|
||||||
@ -139,8 +132,8 @@ await sharp({
|
|||||||
}
|
}
|
||||||
}).toFile('noise.png');
|
}).toFile('noise.png');
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Generate an image from text
|
// Generate an image from text
|
||||||
await sharp({
|
await sharp({
|
||||||
text: {
|
text: {
|
||||||
@ -150,8 +143,8 @@ await sharp({
|
|||||||
}
|
}
|
||||||
}).toFile('text_bw.png');
|
}).toFile('text_bw.png');
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Generate an rgba image from text using pango markup and font
|
// Generate an rgba image from text using pango markup and font
|
||||||
await sharp({
|
await sharp({
|
||||||
text: {
|
text: {
|
||||||
@ -163,19 +156,15 @@ await sharp({
|
|||||||
}).toFile('text_rgba.png');
|
}).toFile('text_rgba.png');
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][17]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **[Sharp][18]** 
|
|
||||||
|
|
||||||
## clone
|
## clone
|
||||||
|
|
||||||
Take a "snapshot" of the Sharp instance, returning a new instance.
|
Take a "snapshot" of the Sharp instance, returning a new instance.
|
||||||
Cloned instances inherit the input of their parent instance.
|
Cloned instances inherit the input of their parent instance.
|
||||||
This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream.
|
This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream.
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
**Example**
|
||||||
|
```js
|
||||||
const pipeline = sharp().rotate();
|
const pipeline = sharp().rotate();
|
||||||
pipeline.clone().resize(800, 600).pipe(firstWritableStream);
|
pipeline.clone().resize(800, 600).pipe(firstWritableStream);
|
||||||
pipeline.clone().extract({ left: 20, top: 20, width: 100, height: 100 }).pipe(secondWritableStream);
|
pipeline.clone().extract({ left: 20, top: 20, width: 100, height: 100 }).pipe(secondWritableStream);
|
||||||
@ -183,8 +172,8 @@ readableStream.pipe(pipeline);
|
|||||||
// firstWritableStream receives auto-rotated, resized readableStream
|
// firstWritableStream receives auto-rotated, resized readableStream
|
||||||
// secondWritableStream receives auto-rotated, extracted region of readableStream
|
// secondWritableStream receives auto-rotated, extracted region of readableStream
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Create a pipeline that will download an image, resize it and format it to different files
|
// Create a pipeline that will download an image, resize it and format it to different files
|
||||||
// Using Promises to know when the pipeline is complete
|
// Using Promises to know when the pipeline is complete
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
@ -230,41 +219,3 @@ Promise.all(promises)
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Sharp][18]** 
|
|
||||||
|
|
||||||
[1]: http://nodejs.org/api/stream.html#stream_class_stream_duplex
|
|
||||||
|
|
||||||
[2]: https://nodejs.org/api/buffer.html
|
|
||||||
|
|
||||||
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
|
|
||||||
|
|
||||||
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
|
|
||||||
|
|
||||||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
|
|
||||||
|
|
||||||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
|
|
||||||
|
|
||||||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
|
|
||||||
|
|
||||||
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
|
|
||||||
|
|
||||||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
|
|
||||||
|
|
||||||
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
|
|
||||||
|
|
||||||
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
|
|
||||||
|
|
||||||
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
||||||
|
|
||||||
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
|
||||||
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
||||||
|
|
||||||
[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
||||||
|
|
||||||
[16]: https://www.npmjs.org/package/color
|
|
||||||
|
|
||||||
[17]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
||||||
|
|
||||||
[18]: #sharp
|
|
||||||
|
@ -1,57 +1,55 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
||||||
|
|
||||||
## metadata
|
## metadata
|
||||||
|
|
||||||
Fast access to (uncached) image metadata without decoding any compressed pixel data.
|
Fast access to (uncached) image metadata without decoding any compressed pixel data.
|
||||||
|
|
||||||
This is taken from the header of the input image.
|
This is taken from the header of the input image.
|
||||||
It does not include operations, such as resize, to be applied to the output image.
|
It does not include operations, such as resize, to be applied to the output image.
|
||||||
|
|
||||||
Dimensions in the response will respect the `page` and `pages` properties of the
|
Dimensions in the response will respect the `page` and `pages` properties of the
|
||||||
[constructor parameters][1].
|
[constructor parameters](/api-constructor#parameters).
|
||||||
|
|
||||||
A `Promise` is returned when `callback` is not provided.
|
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`
|
- `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
|
- `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, see example below)
|
- `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)
|
- `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` [...][2]
|
- `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...](https://www.libvips.org/API/current/VipsImage.html#VipsInterpretation)
|
||||||
* `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
|
- `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
|
||||||
* `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...][3]
|
- `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...](https://www.libvips.org/API/current/VipsImage.html#VipsBandFormat)
|
||||||
* `density`: Number of pixels per inch (DPI), if present
|
- `density`: Number of pixels per inch (DPI), if present
|
||||||
* `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
- `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
||||||
* `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
- `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
||||||
* `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
- `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
||||||
* `pageHeight`: Number of pixels high each page in a multi-page image will be.
|
- `pageHeight`: Number of pixels high each page in a multi-page image will be.
|
||||||
* `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
|
- `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
|
||||||
* `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
|
- `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
|
||||||
* `pagePrimary`: Number of the primary page in a HEIF image
|
- `pagePrimary`: Number of the primary page in a HEIF image
|
||||||
* `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide
|
- `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide
|
||||||
* `subifds`: Number of Sub Image File Directories in an OME-TIFF image
|
- `subifds`: Number of Sub Image File Directories in an OME-TIFF image
|
||||||
* `background`: Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value
|
- `background`: Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value
|
||||||
* `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
|
- `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
|
||||||
* `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present
|
- `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present
|
||||||
* `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
- `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
||||||
* `hasAlpha`: Boolean indicating the presence of an alpha transparency channel
|
- `hasAlpha`: Boolean indicating the presence of an alpha transparency channel
|
||||||
* `orientation`: Number value of the EXIF Orientation header, if present
|
- `orientation`: Number value of the EXIF Orientation header, if present
|
||||||
* `exif`: Buffer containing raw EXIF data, if present
|
- `exif`: Buffer containing raw EXIF data, if present
|
||||||
* `icc`: Buffer containing raw [ICC][4] profile data, if present
|
- `icc`: Buffer containing raw [ICC](https://www.npmjs.com/package/icc) profile data, if present
|
||||||
* `iptc`: Buffer containing raw IPTC data, if present
|
- `iptc`: Buffer containing raw IPTC data, if present
|
||||||
* `xmp`: Buffer containing raw XMP data, if present
|
- `xmp`: Buffer containing raw XMP data, if present
|
||||||
* `tifftagPhotoshop`: Buffer containing raw TIFFTAG\_PHOTOSHOP data, if present
|
- `tifftagPhotoshop`: Buffer containing raw TIFFTAG_PHOTOSHOP data, if present
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `callback` **[Function][5]?** called with the arguments `(err, metadata)`
|
|
||||||
|
|
||||||
### Examples
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| [callback] | <code>function</code> | called with the arguments `(err, metadata)` |
|
||||||
|
|
||||||
```javascript
|
**Example**
|
||||||
|
```js
|
||||||
const metadata = await sharp(input).metadata();
|
const metadata = await sharp(input).metadata();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const image = sharp(inputJpg);
|
const image = sharp(inputJpg);
|
||||||
image
|
image
|
||||||
.metadata()
|
.metadata()
|
||||||
@ -65,8 +63,8 @@ image
|
|||||||
// data contains a WebP image half the width and height of the original JPEG
|
// data contains a WebP image half the width and height of the original JPEG
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Based on EXIF rotation metadata, get the right-side-up width and height:
|
// Based on EXIF rotation metadata, get the right-side-up width and height:
|
||||||
|
|
||||||
const size = getNormalSize(await sharp(input).metadata());
|
const size = getNormalSize(await sharp(input).metadata());
|
||||||
@ -78,39 +76,38 @@ function getNormalSize({ width, height, orientation }) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **([Promise][6]<[Object][7]> | Sharp)** 
|
|
||||||
|
|
||||||
## stats
|
## stats
|
||||||
|
|
||||||
Access to pixel-derived image statistics for every channel in the image.
|
Access to pixel-derived image statistics for every channel in the image.
|
||||||
A `Promise` is returned when `callback` is not provided.
|
A `Promise` is returned when `callback` is not provided.
|
||||||
|
|
||||||
* `channels`: Array of channel statistics for each channel in the image. Each channel statistic contains
|
- `channels`: Array of channel statistics for each channel in the image. Each channel statistic contains
|
||||||
* `min` (minimum value in the channel)
|
- `min` (minimum value in the channel)
|
||||||
* `max` (maximum value in the channel)
|
- `max` (maximum value in the channel)
|
||||||
* `sum` (sum of all values in a channel)
|
- `sum` (sum of all values in a channel)
|
||||||
* `squaresSum` (sum of squared values in a channel)
|
- `squaresSum` (sum of squared values in a channel)
|
||||||
* `mean` (mean of the values in a channel)
|
- `mean` (mean of the values in a channel)
|
||||||
* `stdev` (standard deviation for the values in a channel)
|
- `stdev` (standard deviation for the values in a channel)
|
||||||
* `minX` (x-coordinate of one of the pixel where the minimum lies)
|
- `minX` (x-coordinate of one of the pixel where the minimum lies)
|
||||||
* `minY` (y-coordinate of one of the pixel where the minimum lies)
|
- `minY` (y-coordinate of one of the pixel where the minimum lies)
|
||||||
* `maxX` (x-coordinate of one of the pixel where the maximum lies)
|
- `maxX` (x-coordinate of one of the pixel where the maximum lies)
|
||||||
* `maxY` (y-coordinate of one of the pixel where the maximum lies)
|
- `maxY` (y-coordinate of one of the pixel where the maximum lies)
|
||||||
* `isOpaque`: Is the image fully opaque? Will be `true` if the image has no alpha channel or if every pixel is fully opaque.
|
- `isOpaque`: Is the image fully opaque? Will be `true` if the image has no alpha channel or if every pixel is fully opaque.
|
||||||
* `entropy`: Histogram-based estimation of greyscale entropy, discarding alpha channel if any.
|
- `entropy`: Histogram-based estimation of greyscale entropy, discarding alpha channel if any.
|
||||||
* `sharpness`: Estimation of greyscale sharpness based on the standard deviation of a Laplacian convolution, discarding alpha channel if any.
|
- `sharpness`: Estimation of greyscale sharpness based on the standard deviation of a Laplacian convolution, discarding alpha channel if any.
|
||||||
* `dominant`: Object containing most dominant sRGB colour based on a 4096-bin 3D histogram.
|
- `dominant`: Object containing most dominant sRGB colour based on a 4096-bin 3D histogram.
|
||||||
|
|
||||||
**Note**: Statistics are derived from the original input image. Any operations performed on the image must first be
|
**Note**: Statistics are derived from the original input image. Any operations performed on the image must first be
|
||||||
written to a buffer in order to run `stats` on the result (see third example).
|
written to a buffer in order to run `stats` on the result (see third example).
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `callback` **[Function][5]?** called with the arguments `(err, stats)`
|
|
||||||
|
|
||||||
### Examples
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| [callback] | <code>function</code> | called with the arguments `(err, stats)` |
|
||||||
|
|
||||||
```javascript
|
**Example**
|
||||||
|
```js
|
||||||
const image = sharp(inputJpg);
|
const image = sharp(inputJpg);
|
||||||
image
|
image
|
||||||
.stats()
|
.stats()
|
||||||
@ -118,32 +115,16 @@ image
|
|||||||
// stats contains the channel-wise statistics array and the isOpaque value
|
// stats contains the channel-wise statistics array and the isOpaque value
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const { entropy, sharpness, dominant } = await sharp(input).stats();
|
const { entropy, sharpness, dominant } = await sharp(input).stats();
|
||||||
const { r, g, b } = dominant;
|
const { r, g, b } = dominant;
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const image = sharp(input);
|
const image = sharp(input);
|
||||||
// store intermediate result
|
// store intermediate result
|
||||||
const part = await image.extract(region).toBuffer();
|
const part = await image.extract(region).toBuffer();
|
||||||
// create new instance to obtain statistics of extracted region
|
// create new instance to obtain statistics of extracted region
|
||||||
const stats = await sharp(part).stats();
|
const stats = await sharp(part).stats();
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Promise][6]<[Object][7]>** 
|
|
||||||
|
|
||||||
[1]: /api-constructor#parameters
|
|
||||||
|
|
||||||
[2]: https://www.libvips.org/API/current/VipsImage.html#VipsInterpretation
|
|
||||||
|
|
||||||
[3]: https://www.libvips.org/API/current/VipsImage.html#VipsBandFormat
|
|
||||||
|
|
||||||
[4]: https://www.npmjs.com/package/icc
|
|
||||||
|
|
||||||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
|
|
||||||
|
|
||||||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
|
||||||
|
|
||||||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
||||||
|
|
||||||
## rotate
|
## rotate
|
||||||
|
|
||||||
Rotate the output image by either an explicit angle
|
Rotate the output image by either an explicit angle
|
||||||
or auto-orient based on the EXIF `Orientation` tag.
|
or auto-orient based on the EXIF `Orientation` tag.
|
||||||
|
|
||||||
@ -22,16 +19,20 @@ Previous calls to `rotate` in the same pipeline will be ignored.
|
|||||||
Method order is important when rotating, resizing and/or extracting regions,
|
Method order is important when rotating, resizing and/or extracting regions,
|
||||||
for example `.rotate(x).extract(y)` will produce a different result to `.extract(y).rotate(x)`.
|
for example `.rotate(x).extract(y)` will produce a different result to `.extract(y).rotate(x)`.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `angle` **[number][1]** angle of rotation. (optional, default `auto`)
|
**Throws**:
|
||||||
* `options` **[Object][2]?** if present, is an Object with optional attributes.
|
|
||||||
|
|
||||||
* `options.background` **([string][3] | [Object][2])** parsed by the [color][4] module to extract values for red, green, blue and alpha. (optional, default `"#000000"`)
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [angle] | <code>number</code> | <code>auto</code> | angle of rotation. |
|
||||||
|
| [options] | <code>Object</code> | | if present, is an Object with optional attributes. |
|
||||||
|
| [options.background] | <code>string</code> \| <code>Object</code> | <code>"\"#000000\""</code> | parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
const pipeline = sharp()
|
const pipeline = sharp()
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(null, 200)
|
.resize(null, 200)
|
||||||
@ -42,8 +43,8 @@ const pipeline = sharp()
|
|||||||
});
|
});
|
||||||
readableStream.pipe(pipeline);
|
readableStream.pipe(pipeline);
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const rotateThenResize = await sharp(input)
|
const rotateThenResize = await sharp(input)
|
||||||
.rotate(90)
|
.rotate(90)
|
||||||
.resize({ width: 16, height: 8, fit: 'fill' })
|
.resize({ width: 16, height: 8, fit: 'fill' })
|
||||||
@ -54,46 +55,40 @@ const resizeThenRotate = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][5]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## flip
|
## flip
|
||||||
|
|
||||||
Flip the image about the vertical Y axis. This always occurs before rotation, if any.
|
Flip the image about the vertical Y axis. This always occurs before rotation, if any.
|
||||||
The use of `flip` implies the removal of the EXIF `Orientation` tag, if any.
|
The use of `flip` implies the removal of the EXIF `Orientation` tag, if any.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `flip` **[Boolean][6]** (optional, default `true`)
|
|
||||||
|
|
||||||
### Examples
|
| Param | Type | Default |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| [flip] | <code>Boolean</code> | <code>true</code> |
|
||||||
|
|
||||||
```javascript
|
**Example**
|
||||||
|
```js
|
||||||
const output = await sharp(input).flip().toBuffer();
|
const output = await sharp(input).flip().toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## flop
|
## flop
|
||||||
|
|
||||||
Flop the image about the horizontal X axis. This always occurs before rotation, if any.
|
Flop the image about the horizontal X axis. This always occurs before rotation, if any.
|
||||||
The use of `flop` implies the removal of the EXIF `Orientation` tag, if any.
|
The use of `flop` implies the removal of the EXIF `Orientation` tag, if any.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `flop` **[Boolean][6]** (optional, default `true`)
|
|
||||||
|
|
||||||
### Examples
|
| Param | Type | Default |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| [flop] | <code>Boolean</code> | <code>true</code> |
|
||||||
|
|
||||||
```javascript
|
**Example**
|
||||||
|
```js
|
||||||
const output = await sharp(input).flop().toBuffer();
|
const output = await sharp(input).flop().toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## affine
|
## affine
|
||||||
|
|
||||||
Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
|
Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
|
||||||
|
|
||||||
You must provide an array of length 4 or a 2x2 affine transformation matrix.
|
You must provide an array of length 4 or a 2x2 affine transformation matrix.
|
||||||
@ -101,31 +96,34 @@ By default, new pixels are filled with a black background. You can provide a bac
|
|||||||
A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolator` Object e.g. `sharp.interpolator.nohalo`.
|
A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolator` Object e.g. `sharp.interpolator.nohalo`.
|
||||||
|
|
||||||
In the case of a 2x2 matrix, the transform is:
|
In the case of a 2x2 matrix, the transform is:
|
||||||
|
- X = `matrix[0, 0]` \* (x + `idx`) + `matrix[0, 1]` \* (y + `idy`) + `odx`
|
||||||
* X = `matrix[0, 0]` \* (x + `idx`) + `matrix[0, 1]` \* (y + `idy`) + `odx`
|
- Y = `matrix[1, 0]` \* (x + `idx`) + `matrix[1, 1]` \* (y + `idy`) + `ody`
|
||||||
* Y = `matrix[1, 0]` \* (x + `idx`) + `matrix[1, 1]` \* (y + `idy`) + `ody`
|
|
||||||
|
|
||||||
where:
|
where:
|
||||||
|
- x and y are the coordinates in input image.
|
||||||
|
- X and Y are the coordinates in output image.
|
||||||
|
- (0,0) is the upper left corner.
|
||||||
|
|
||||||
* x and y are the coordinates in input image.
|
|
||||||
* X and Y are the coordinates in output image.
|
|
||||||
* (0,0) is the upper left corner.
|
|
||||||
|
|
||||||
### Parameters
|
**Throws**:
|
||||||
|
|
||||||
* `matrix` **([Array][7]<[Array][7]<[number][1]>> | [Array][7]<[number][1]>)** affine transformation matrix
|
- <code>Error</code> Invalid parameters
|
||||||
* `options` **[Object][2]?** if present, is an Object with optional attributes.
|
|
||||||
|
|
||||||
* `options.background` **([String][3] | [Object][2])** parsed by the [color][4] module to extract values for red, green, blue and alpha. (optional, default `"#000000"`)
|
**Since**: 0.27.0
|
||||||
* `options.idx` **[Number][1]** input horizontal offset (optional, default `0`)
|
|
||||||
* `options.idy` **[Number][1]** input vertical offset (optional, default `0`)
|
|
||||||
* `options.odx` **[Number][1]** output horizontal offset (optional, default `0`)
|
|
||||||
* `options.ody` **[Number][1]** output vertical offset (optional, default `0`)
|
|
||||||
* `options.interpolator` **[String][3]** interpolator (optional, default `sharp.interpolators.bicubic`)
|
|
||||||
|
|
||||||
### Examples
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| matrix | <code>Array.<Array.<number>></code> \| <code>Array.<number></code> | | affine transformation matrix |
|
||||||
|
| [options] | <code>Object</code> | | if present, is an Object with optional attributes. |
|
||||||
|
| [options.background] | <code>String</code> \| <code>Object</code> | <code>"#000000"</code> | parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. |
|
||||||
|
| [options.idx] | <code>Number</code> | <code>0</code> | input horizontal offset |
|
||||||
|
| [options.idy] | <code>Number</code> | <code>0</code> | input vertical offset |
|
||||||
|
| [options.odx] | <code>Number</code> | <code>0</code> | output horizontal offset |
|
||||||
|
| [options.ody] | <code>Number</code> | <code>0</code> | output vertical offset |
|
||||||
|
| [options.interpolator] | <code>String</code> | <code>sharp.interpolators.bicubic</code> | interpolator |
|
||||||
|
|
||||||
```javascript
|
**Example**
|
||||||
|
```js
|
||||||
const pipeline = sharp()
|
const pipeline = sharp()
|
||||||
.affine([[1, 0.3], [0.1, 0.7]], {
|
.affine([[1, 0.3], [0.1, 0.7]], {
|
||||||
background: 'white',
|
background: 'white',
|
||||||
@ -140,16 +138,8 @@ inputStream
|
|||||||
.pipe(pipeline);
|
.pipe(pipeline);
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][5]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
**Meta**
|
|
||||||
|
|
||||||
* **since**: 0.27.0
|
|
||||||
|
|
||||||
## sharpen
|
## sharpen
|
||||||
|
|
||||||
Sharpen the image.
|
Sharpen the image.
|
||||||
|
|
||||||
When used without parameters, performs a fast, mild sharpen of the output image.
|
When used without parameters, performs a fast, mild sharpen of the output image.
|
||||||
@ -157,32 +147,36 @@ When used without parameters, performs a fast, mild sharpen of the output image.
|
|||||||
When a `sigma` is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.
|
When a `sigma` is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.
|
||||||
Fine-grained control over the level of sharpening in "flat" (m1) and "jagged" (m2) areas is available.
|
Fine-grained control over the level of sharpening in "flat" (m1) and "jagged" (m2) areas is available.
|
||||||
|
|
||||||
See [libvips sharpen][8] operation.
|
See [libvips sharpen](https://www.libvips.org/API/current/libvips-convolution.html#vips-sharpen) operation.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **([Object][2] | [number][1])?** if present, is an Object with attributes
|
**Throws**:
|
||||||
|
|
||||||
* `options.sigma` **[number][1]?** the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`, between 0.000001 and 10000
|
- <code>Error</code> Invalid parameters
|
||||||
* `options.m1` **[number][1]** the level of sharpening to apply to "flat" areas, between 0 and 1000000 (optional, default `1.0`)
|
|
||||||
* `options.m2` **[number][1]** the level of sharpening to apply to "jagged" areas, between 0 and 1000000 (optional, default `2.0`)
|
|
||||||
* `options.x1` **[number][1]** threshold between "flat" and "jagged", between 0 and 1000000 (optional, default `2.0`)
|
|
||||||
* `options.y2` **[number][1]** maximum amount of brightening, between 0 and 1000000 (optional, default `10.0`)
|
|
||||||
* `options.y3` **[number][1]** maximum amount of darkening, between 0 and 1000000 (optional, default `20.0`)
|
|
||||||
* `flat` **[number][1]?** (deprecated) see `options.m1`.
|
|
||||||
* `jagged` **[number][1]?** (deprecated) see `options.m2`.
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [options] | <code>Object</code> \| <code>number</code> | | if present, is an Object with attributes |
|
||||||
|
| [options.sigma] | <code>number</code> | | the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`, between 0.000001 and 10000 |
|
||||||
|
| [options.m1] | <code>number</code> | <code>1.0</code> | the level of sharpening to apply to "flat" areas, between 0 and 1000000 |
|
||||||
|
| [options.m2] | <code>number</code> | <code>2.0</code> | the level of sharpening to apply to "jagged" areas, between 0 and 1000000 |
|
||||||
|
| [options.x1] | <code>number</code> | <code>2.0</code> | threshold between "flat" and "jagged", between 0 and 1000000 |
|
||||||
|
| [options.y2] | <code>number</code> | <code>10.0</code> | maximum amount of brightening, between 0 and 1000000 |
|
||||||
|
| [options.y3] | <code>number</code> | <code>20.0</code> | maximum amount of darkening, between 0 and 1000000 |
|
||||||
|
| [flat] | <code>number</code> | | (deprecated) see `options.m1`. |
|
||||||
|
| [jagged] | <code>number</code> | | (deprecated) see `options.m2`. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
const data = await sharp(input).sharpen().toBuffer();
|
const data = await sharp(input).sharpen().toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const data = await sharp(input).sharpen({ sigma: 2 }).toBuffer();
|
const data = await sharp(input).sharpen({ sigma: 2 }).toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const data = await sharp(input)
|
const data = await sharp(input)
|
||||||
.sharpen({
|
.sharpen({
|
||||||
sigma: 2,
|
sigma: 2,
|
||||||
@ -195,87 +189,83 @@ const data = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][5]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## median
|
## median
|
||||||
|
|
||||||
Apply median filter.
|
Apply median filter.
|
||||||
When used without parameters the default window is 3x3.
|
When used without parameters the default window is 3x3.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `size` **[number][1]** square mask size: size x size (optional, default `3`)
|
**Throws**:
|
||||||
|
|
||||||
### Examples
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
```javascript
|
|
||||||
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [size] | <code>number</code> | <code>3</code> | square mask size: size x size |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
const output = await sharp(input).median().toBuffer();
|
const output = await sharp(input).median().toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const output = await sharp(input).median(5).toBuffer();
|
const output = await sharp(input).median(5).toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][5]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## blur
|
## blur
|
||||||
|
|
||||||
Blur the image.
|
Blur the image.
|
||||||
|
|
||||||
When used without parameters, performs a fast 3x3 box blur (equivalent to a box linear filter).
|
When used without parameters, performs a fast 3x3 box blur (equivalent to a box linear filter).
|
||||||
|
|
||||||
When a `sigma` is provided, performs a slower, more accurate Gaussian blur.
|
When a `sigma` is provided, performs a slower, more accurate Gaussian blur.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `sigma` **[number][1]?** a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
**Throws**:
|
||||||
|
|
||||||
### Examples
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
```javascript
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| [sigma] | <code>number</code> | a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
const boxBlurred = await sharp(input)
|
const boxBlurred = await sharp(input)
|
||||||
.blur()
|
.blur()
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const gaussianBlurred = await sharp(input)
|
const gaussianBlurred = await sharp(input)
|
||||||
.blur(5)
|
.blur(5)
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][5]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## flatten
|
## flatten
|
||||||
|
|
||||||
Merge alpha transparency channel, if any, with a background, then remove the alpha channel.
|
Merge alpha transparency channel, if any, with a background, then remove the alpha channel.
|
||||||
|
|
||||||
See also [removeAlpha][9].
|
See also [removeAlpha](/api-channel#removealpha).
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][2]?** 
|
|
||||||
|
|
||||||
* `options.background` **([string][3] | [Object][2])** background colour, parsed by the [color][4] module, defaults to black. (optional, default `{r:0,g:0,b:0}`)
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [options] | <code>Object</code> | | |
|
||||||
|
| [options.background] | <code>string</code> \| <code>Object</code> | <code>"{r: 0, g: 0, b: 0}"</code> | background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black. |
|
||||||
|
|
||||||
### Examples
|
**Example**
|
||||||
|
```js
|
||||||
```javascript
|
|
||||||
await sharp(rgbaInput)
|
await sharp(rgbaInput)
|
||||||
.flatten({ background: '#F0A703' })
|
.flatten({ background: '#F0A703' })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## gamma
|
## gamma
|
||||||
|
|
||||||
Apply a gamma correction by reducing the encoding (darken) pre-resize at a factor of `1/gamma`
|
Apply a gamma correction by reducing the encoding (darken) pre-resize at a factor of `1/gamma`
|
||||||
then increasing the encoding (brighten) post-resize at a factor of `gamma`.
|
then increasing the encoding (brighten) post-resize at a factor of `gamma`.
|
||||||
This can improve the perceived brightness of a resized image in non-linear colour spaces.
|
This can improve the perceived brightness of a resized image in non-linear colour spaces.
|
||||||
@ -284,95 +274,95 @@ when applying a gamma correction.
|
|||||||
|
|
||||||
Supply a second argument to use a different output gamma value, otherwise the first value is used in both cases.
|
Supply a second argument to use a different output gamma value, otherwise the first value is used in both cases.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `gamma` **[number][1]** value between 1.0 and 3.0. (optional, default `2.2`)
|
**Throws**:
|
||||||
* `gammaOut` **[number][1]?** value between 1.0 and 3.0. (optional, defaults to same as `gamma`)
|
|
||||||
|
|
||||||
<!---->
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
|
|
||||||
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [gamma] | <code>number</code> | <code>2.2</code> | value between 1.0 and 3.0. |
|
||||||
|
| [gammaOut] | <code>number</code> | | value between 1.0 and 3.0. (optional, defaults to same as `gamma`) |
|
||||||
|
|
||||||
* Throws **[Error][5]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## negate
|
## negate
|
||||||
|
|
||||||
Produce the "negative" of the image.
|
Produce the "negative" of the image.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][2]?** 
|
|
||||||
|
|
||||||
* `options.alpha` **[Boolean][6]** Whether or not to negate any alpha channel (optional, default `true`)
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [options] | <code>Object</code> | | |
|
||||||
|
| [options.alpha] | <code>Boolean</code> | <code>true</code> | Whether or not to negate any alpha channel |
|
||||||
|
|
||||||
### Examples
|
**Example**
|
||||||
|
```js
|
||||||
```javascript
|
|
||||||
const output = await sharp(input)
|
const output = await sharp(input)
|
||||||
.negate()
|
.negate()
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const output = await sharp(input)
|
const output = await sharp(input)
|
||||||
.negate({ alpha: false })
|
.negate({ alpha: false })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## normalise
|
## normalise
|
||||||
|
|
||||||
Enhance output image contrast by stretching its luminance to cover the full dynamic range.
|
Enhance output image contrast by stretching its luminance to cover the full dynamic range.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `normalise` **[Boolean][6]** (optional, default `true`)
|
|
||||||
|
|
||||||
### Examples
|
| Param | Type | Default |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| [normalise] | <code>Boolean</code> | <code>true</code> |
|
||||||
|
|
||||||
```javascript
|
**Example**
|
||||||
|
```js
|
||||||
const output = await sharp(input).normalise().toBuffer();
|
const output = await sharp(input).normalise().toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## normalize
|
## normalize
|
||||||
|
|
||||||
Alternative spelling of normalise.
|
Alternative spelling of normalise.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `normalize` **[Boolean][6]** (optional, default `true`)
|
|
||||||
|
|
||||||
### Examples
|
| Param | Type | Default |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| [normalize] | <code>Boolean</code> | <code>true</code> |
|
||||||
|
|
||||||
```javascript
|
**Example**
|
||||||
|
```js
|
||||||
const output = await sharp(input).normalize().toBuffer();
|
const output = await sharp(input).normalize().toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## clahe
|
## clahe
|
||||||
|
|
||||||
Perform contrast limiting adaptive histogram equalization
|
Perform contrast limiting adaptive histogram equalization
|
||||||
[CLAHE][10].
|
[CLAHE](https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE).
|
||||||
|
|
||||||
This will, in general, enhance the clarity of the image by bringing out darker details.
|
This will, in general, enhance the clarity of the image by bringing out darker details.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][2]** 
|
**Throws**:
|
||||||
|
|
||||||
* `options.width` **[number][1]** integer width of the region in pixels.
|
- <code>Error</code> Invalid parameters
|
||||||
* `options.height` **[number][1]** integer height of the region in pixels.
|
|
||||||
* `options.maxSlope` **[number][1]** maximum value for the slope of the
|
|
||||||
cumulative histogram. A value of 0 disables contrast limiting. Valid values
|
|
||||||
are integers in the range 0-100 (inclusive) (optional, default `3`)
|
|
||||||
|
|
||||||
### Examples
|
**Since**: 0.28.3
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| options | <code>Object</code> | | |
|
||||||
|
| options.width | <code>number</code> | | integer width of the region in pixels. |
|
||||||
|
| options.height | <code>number</code> | | integer height of the region in pixels. |
|
||||||
|
| [options.maxSlope] | <code>number</code> | <code>3</code> | maximum value for the slope of the cumulative histogram. A value of 0 disables contrast limiting. Valid values are integers in the range 0-100 (inclusive) |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
const output = await sharp(input)
|
const output = await sharp(input)
|
||||||
.clahe({
|
.clahe({
|
||||||
width: 3,
|
width: 3,
|
||||||
@ -381,31 +371,27 @@ const output = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][5]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
**Meta**
|
|
||||||
|
|
||||||
* **since**: 0.28.3
|
|
||||||
|
|
||||||
## convolve
|
## convolve
|
||||||
|
|
||||||
Convolve the image with the specified kernel.
|
Convolve the image with the specified kernel.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `kernel` **[Object][2]** 
|
**Throws**:
|
||||||
|
|
||||||
* `kernel.width` **[number][1]** width of the kernel in pixels.
|
- <code>Error</code> Invalid parameters
|
||||||
* `kernel.height` **[number][1]** height of the kernel in pixels.
|
|
||||||
* `kernel.kernel` **[Array][7]<[number][1]>** Array of length `width*height` containing the kernel values.
|
|
||||||
* `kernel.scale` **[number][1]** the scale of the kernel in pixels. (optional, default `sum`)
|
|
||||||
* `kernel.offset` **[number][1]** the offset of the kernel in pixels. (optional, default `0`)
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| kernel | <code>Object</code> | | |
|
||||||
|
| kernel.width | <code>number</code> | | width of the kernel in pixels. |
|
||||||
|
| kernel.height | <code>number</code> | | height of the kernel in pixels. |
|
||||||
|
| kernel.kernel | <code>Array.<number></code> | | Array of length `width*height` containing the kernel values. |
|
||||||
|
| [kernel.scale] | <code>number</code> | <code>sum</code> | the scale of the kernel in pixels. |
|
||||||
|
| [kernel.offset] | <code>number</code> | <code>0</code> | the offset of the kernel in pixels. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.convolve({
|
.convolve({
|
||||||
width: 3,
|
width: 3,
|
||||||
@ -419,74 +405,74 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][5]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## threshold
|
## threshold
|
||||||
|
|
||||||
Any pixel value greater than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
|
Any pixel value greater than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `threshold` **[number][1]** a value in the range 0-255 representing the level at which the threshold will be applied. (optional, default `128`)
|
**Throws**:
|
||||||
* `options` **[Object][2]?** 
|
|
||||||
|
|
||||||
* `options.greyscale` **[Boolean][6]** convert to single channel greyscale. (optional, default `true`)
|
- <code>Error</code> Invalid parameters
|
||||||
* `options.grayscale` **[Boolean][6]** alternative spelling for greyscale. (optional, default `true`)
|
|
||||||
|
|
||||||
<!---->
|
|
||||||
|
|
||||||
* Throws **[Error][5]** Invalid parameters
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [threshold] | <code>number</code> | <code>128</code> | a value in the range 0-255 representing the level at which the threshold will be applied. |
|
||||||
|
| [options] | <code>Object</code> | | |
|
||||||
|
| [options.greyscale] | <code>Boolean</code> | <code>true</code> | convert to single channel greyscale. |
|
||||||
|
| [options.grayscale] | <code>Boolean</code> | <code>true</code> | alternative spelling for greyscale. |
|
||||||
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## boolean
|
## boolean
|
||||||
|
|
||||||
Perform a bitwise boolean operation with operand image.
|
Perform a bitwise boolean operation with operand image.
|
||||||
|
|
||||||
This operation creates an output image where each pixel is the result of
|
This operation creates an output image where each pixel is the result of
|
||||||
the selected bitwise boolean `operation` between the corresponding pixels of the input images.
|
the selected bitwise boolean `operation` between the corresponding pixels of the input images.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `operand` **([Buffer][11] | [string][3])** Buffer containing image data or string containing the path to an image file.
|
**Throws**:
|
||||||
* `operator` **[string][3]** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
|
||||||
* `options` **[Object][2]?** 
|
|
||||||
|
|
||||||
* `options.raw` **[Object][2]?** describes operand when using raw pixel data.
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
* `options.raw.width` **[number][1]?** 
|
|
||||||
* `options.raw.height` **[number][1]?** 
|
|
||||||
* `options.raw.channels` **[number][1]?** 
|
|
||||||
|
|
||||||
<!---->
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| operand | <code>Buffer</code> \| <code>string</code> | Buffer containing image data or string containing the path to an image file. |
|
||||||
|
| operator | <code>string</code> | one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively. |
|
||||||
|
| [options] | <code>Object</code> | |
|
||||||
|
| [options.raw] | <code>Object</code> | describes operand when using raw pixel data. |
|
||||||
|
| [options.raw.width] | <code>number</code> | |
|
||||||
|
| [options.raw.height] | <code>number</code> | |
|
||||||
|
| [options.raw.channels] | <code>number</code> | |
|
||||||
|
|
||||||
* Throws **[Error][5]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## linear
|
## linear
|
||||||
|
Apply the linear formula `a` * input + `b` to the image to adjust image levels.
|
||||||
Apply the linear formula `a` \* input + `b` to the image to adjust image levels.
|
|
||||||
|
|
||||||
When a single number is provided, it will be used for all image channels.
|
When a single number is provided, it will be used for all image channels.
|
||||||
When an array of numbers is provided, the array length must match the number of channels.
|
When an array of numbers is provided, the array length must match the number of channels.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `a` **([number][1] | [Array][7]<[number][1]>)** multiplier (optional, default `[]`)
|
**Throws**:
|
||||||
* `b` **([number][1] | [Array][7]<[number][1]>)** offset (optional, default `[]`)
|
|
||||||
|
|
||||||
### Examples
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
```javascript
|
|
||||||
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [a] | <code>number</code> \| <code>Array.<number></code> | <code>[]</code> | multiplier |
|
||||||
|
| [b] | <code>number</code> \| <code>Array.<number></code> | <code>[]</code> | offset |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
await sharp(input)
|
await sharp(input)
|
||||||
.linear(0.5, 2)
|
.linear(0.5, 2)
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
await sharp(rgbInput)
|
await sharp(rgbInput)
|
||||||
.linear(
|
.linear(
|
||||||
[0.25, 0.5, 0.75],
|
[0.25, 0.5, 0.75],
|
||||||
@ -495,21 +481,23 @@ await sharp(rgbInput)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][5]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## recomb
|
## recomb
|
||||||
|
|
||||||
Recomb the image with the specified matrix.
|
Recomb the image with the specified matrix.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `inputMatrix` **[Array][7]<[Array][7]<[number][1]>>** 3x3 Recombination matrix
|
**Throws**:
|
||||||
|
|
||||||
### Examples
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
```javascript
|
**Since**: 0.21.1
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| inputMatrix | <code>Array.<Array.<number>></code> | 3x3 Recombination matrix |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.recomb([
|
.recomb([
|
||||||
[0.3588, 0.7044, 0.1368],
|
[0.3588, 0.7044, 0.1368],
|
||||||
@ -523,32 +511,25 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][5]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
**Meta**
|
|
||||||
|
|
||||||
* **since**: 0.21.1
|
|
||||||
|
|
||||||
## modulate
|
## modulate
|
||||||
|
|
||||||
Transforms the image using brightness, saturation, hue rotation, and lightness.
|
Transforms the image using brightness, saturation, hue rotation, and lightness.
|
||||||
Brightness and lightness both operate on luminance, with the difference being that
|
Brightness and lightness both operate on luminance, with the difference being that
|
||||||
brightness is multiplicative whereas lightness is additive.
|
brightness is multiplicative whereas lightness is additive.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][2]?** 
|
**Since**: 0.22.1
|
||||||
|
|
||||||
* `options.brightness` **[number][1]?** Brightness multiplier
|
| Param | Type | Description |
|
||||||
* `options.saturation` **[number][1]?** Saturation multiplier
|
| --- | --- | --- |
|
||||||
* `options.hue` **[number][1]?** Degrees for hue rotation
|
| [options] | <code>Object</code> | |
|
||||||
* `options.lightness` **[number][1]?** Lightness addend
|
| [options.brightness] | <code>number</code> | Brightness multiplier |
|
||||||
|
| [options.saturation] | <code>number</code> | Saturation multiplier |
|
||||||
|
| [options.hue] | <code>number</code> | Degrees for hue rotation |
|
||||||
|
| [options.lightness] | <code>number</code> | Lightness addend |
|
||||||
|
|
||||||
### Examples
|
**Example**
|
||||||
|
```js
|
||||||
```javascript
|
|
||||||
// increase brightness by a factor of 2
|
// increase brightness by a factor of 2
|
||||||
const output = await sharp(input)
|
const output = await sharp(input)
|
||||||
.modulate({
|
.modulate({
|
||||||
@ -556,8 +537,8 @@ const output = await sharp(input)
|
|||||||
})
|
})
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// hue-rotate by 180 degrees
|
// hue-rotate by 180 degrees
|
||||||
const output = await sharp(input)
|
const output = await sharp(input)
|
||||||
.modulate({
|
.modulate({
|
||||||
@ -565,8 +546,8 @@ const output = await sharp(input)
|
|||||||
})
|
})
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// increase lightness by +50
|
// increase lightness by +50
|
||||||
const output = await sharp(input)
|
const output = await sharp(input)
|
||||||
.modulate({
|
.modulate({
|
||||||
@ -574,8 +555,8 @@ const output = await sharp(input)
|
|||||||
})
|
})
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// decreate brightness and saturation while also hue-rotating by 90 degrees
|
// decreate brightness and saturation while also hue-rotating by 90 degrees
|
||||||
const output = await sharp(input)
|
const output = await sharp(input)
|
||||||
.modulate({
|
.modulate({
|
||||||
@ -585,31 +566,3 @@ const output = await sharp(input)
|
|||||||
})
|
})
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
**Meta**
|
|
||||||
|
|
||||||
* **since**: 0.22.1
|
|
||||||
|
|
||||||
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
||||||
|
|
||||||
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
|
||||||
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
||||||
|
|
||||||
[4]: https://www.npmjs.org/package/color
|
|
||||||
|
|
||||||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
||||||
|
|
||||||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
||||||
|
|
||||||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
||||||
|
|
||||||
[8]: https://www.libvips.org/API/current/libvips-convolution.html#vips-sharpen
|
|
||||||
|
|
||||||
[9]: /api-channel#removealpha
|
|
||||||
|
|
||||||
[10]: https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE
|
|
||||||
|
|
||||||
[11]: https://nodejs.org/api/buffer.html
|
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
||||||
|
|
||||||
## toFile
|
## toFile
|
||||||
|
|
||||||
Write output image data to a file.
|
Write output image data to a file.
|
||||||
|
|
||||||
If an explicit output format is not selected, it will be inferred from the extension,
|
If an explicit output format is not selected, it will be inferred from the extension,
|
||||||
@ -9,92 +6,90 @@ with JPEG, PNG, WebP, AVIF, TIFF, GIF, DZI, and libvips' V format supported.
|
|||||||
Note that raw pixel data is only supported for buffer output.
|
Note that raw pixel data is only supported for buffer output.
|
||||||
|
|
||||||
By default all metadata will be removed, which includes EXIF-based orientation.
|
By default all metadata will be removed, which includes EXIF-based orientation.
|
||||||
See [withMetadata][1] for control over this.
|
See [withMetadata](#withMetadata) for control over this.
|
||||||
|
|
||||||
The caller is responsible for ensuring directory structures and permissions exist.
|
The caller is responsible for ensuring directory structures and permissions exist.
|
||||||
|
|
||||||
A `Promise` is returned when `callback` is not provided.
|
A `Promise` is returned when `callback` is not provided.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `fileOut` **[string][2]** the path to write the image data to.
|
**Returns**: <code>Promise.<Object></code> - - when no callback is provided
|
||||||
* `callback` **[Function][3]?** called on completion with two arguments `(err, info)`.
|
**Throws**:
|
||||||
`info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
|
||||||
`channels` and `premultiplied` (indicating if premultiplication was used).
|
|
||||||
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
|
||||||
May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text.
|
|
||||||
|
|
||||||
### Examples
|
- <code>Error</code> Invalid parameters
|
||||||
|
|
||||||
```javascript
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| fileOut | <code>string</code> | the path to write the image data to. |
|
||||||
|
| [callback] | <code>function</code> | called on completion with two arguments `(err, info)`. `info` contains the output image `format`, `size` (bytes), `width`, `height`, `channels` and `premultiplied` (indicating if premultiplication was used). When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`. May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.toFile('output.png', (err, info) => { ... });
|
.toFile('output.png', (err, info) => { ... });
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.toFile('output.png')
|
.toFile('output.png')
|
||||||
.then(info => { ... })
|
.then(info => { ... })
|
||||||
.catch(err => { ... });
|
.catch(err => { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **[Promise][5]<[Object][6]>** when no callback is provided
|
|
||||||
|
|
||||||
## toBuffer
|
## toBuffer
|
||||||
|
|
||||||
Write output to a Buffer.
|
Write output to a Buffer.
|
||||||
JPEG, PNG, WebP, AVIF, TIFF, GIF and raw pixel data output are supported.
|
JPEG, PNG, WebP, AVIF, TIFF, GIF and raw pixel data output are supported.
|
||||||
|
|
||||||
Use [toFormat][7] or one of the format-specific functions such as [jpeg][8], [png][9] etc. to set the output format.
|
Use [toFormat](#toFormat) or one of the format-specific functions such as [jpeg](#jpeg), [png](#png) etc. to set the output format.
|
||||||
|
|
||||||
If no explicit format is set, the output format will match the input image, except SVG input which becomes PNG output.
|
If no explicit format is set, the output format will match the input image, except SVG input which becomes PNG output.
|
||||||
|
|
||||||
By default all metadata will be removed, which includes EXIF-based orientation.
|
By default all metadata will be removed, which includes EXIF-based orientation.
|
||||||
See [withMetadata][1] for control over this.
|
See [withMetadata](#withMetadata) for control over this.
|
||||||
|
|
||||||
`callback`, if present, gets three arguments `(err, data, info)` where:
|
`callback`, if present, gets three arguments `(err, data, info)` where:
|
||||||
|
- `err` is an error, if any.
|
||||||
* `err` is an error, if any.
|
- `data` is the output image data.
|
||||||
* `data` is the output image data.
|
- `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
||||||
* `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
|
||||||
`channels` and `premultiplied` (indicating if premultiplication was used).
|
`channels` and `premultiplied` (indicating if premultiplication was used).
|
||||||
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
||||||
May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text.
|
May also contain `textAutofitDpi` (dpi the font was rendered at) if image was created from text.
|
||||||
|
|
||||||
A `Promise` is returned when `callback` is not provided.
|
A `Promise` is returned when `callback` is not provided.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][6]?** 
|
**Returns**: <code>Promise.<Buffer></code> - - when no callback is provided
|
||||||
|
|
||||||
* `options.resolveWithObject` **[boolean][10]?** Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
| Param | Type | Description |
|
||||||
* `callback` **[Function][3]?** 
|
| --- | --- | --- |
|
||||||
|
| [options] | <code>Object</code> | |
|
||||||
|
| [options.resolveWithObject] | <code>boolean</code> | Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`. |
|
||||||
|
| [callback] | <code>function</code> | |
|
||||||
|
|
||||||
### Examples
|
**Example**
|
||||||
|
```js
|
||||||
```javascript
|
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.toBuffer((err, data, info) => { ... });
|
.toBuffer((err, data, info) => { ... });
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.toBuffer()
|
.toBuffer()
|
||||||
.then(data => { ... })
|
.then(data => { ... })
|
||||||
.catch(err => { ... });
|
.catch(err => { ... });
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.png()
|
.png()
|
||||||
.toBuffer({ resolveWithObject: true })
|
.toBuffer({ resolveWithObject: true })
|
||||||
.then(({ data, info }) => { ... })
|
.then(({ data, info }) => { ... })
|
||||||
.catch(err => { ... });
|
.catch(err => { ... });
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const { data, info } = await sharp('my-image.jpg')
|
const { data, info } = await sharp('my-image.jpg')
|
||||||
// output the raw pixels
|
// output the raw pixels
|
||||||
.raw()
|
.raw()
|
||||||
@ -111,10 +106,8 @@ await sharp(pixelArray, { raw: { width, height, channels } })
|
|||||||
.toFile('my-changed-image.jpg');
|
.toFile('my-changed-image.jpg');
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Promise][5]<[Buffer][11]>** when no callback is provided
|
|
||||||
|
|
||||||
## withMetadata
|
## withMetadata
|
||||||
|
|
||||||
Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
|
Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
|
||||||
This will also convert to and add a web-friendly sRGB ICC profile unless a custom
|
This will also convert to and add a web-friendly sRGB ICC profile unless a custom
|
||||||
output profile is provided.
|
output profile is provided.
|
||||||
@ -124,25 +117,29 @@ sRGB colour space and strip all metadata, including the removal of any ICC profi
|
|||||||
|
|
||||||
EXIF metadata is unsupported for TIFF output.
|
EXIF metadata is unsupported for TIFF output.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][6]?** 
|
**Throws**:
|
||||||
|
|
||||||
* `options.orientation` **[number][12]?** value between 1 and 8, used to update the EXIF `Orientation` tag.
|
- <code>Error</code> Invalid parameters
|
||||||
* `options.icc` **[string][2]?** filesystem path to output ICC profile, defaults to sRGB.
|
|
||||||
* `options.exif` **[Object][6]<[Object][6]>** Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data. (optional, default `{}`)
|
|
||||||
* `options.density` **[number][12]?** Number of pixels per inch (DPI).
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [options] | <code>Object</code> | | |
|
||||||
|
| [options.orientation] | <code>number</code> | | value between 1 and 8, used to update the EXIF `Orientation` tag. |
|
||||||
|
| [options.icc] | <code>string</code> | | filesystem path to output ICC profile, defaults to sRGB. |
|
||||||
|
| [options.exif] | <code>Object.<Object></code> | <code>{}</code> | Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data. |
|
||||||
|
| [options.density] | <code>number</code> | | Number of pixels per inch (DPI). |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
sharp('input.jpg')
|
sharp('input.jpg')
|
||||||
.withMetadata()
|
.withMetadata()
|
||||||
.toFile('output-with-metadata.jpg')
|
.toFile('output-with-metadata.jpg')
|
||||||
.then(info => { ... });
|
.then(info => { ... });
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Set "IFD0-Copyright" in output EXIF metadata
|
// Set "IFD0-Copyright" in output EXIF metadata
|
||||||
const data = await sharp(input)
|
const data = await sharp(input)
|
||||||
.withMetadata({
|
.withMetadata({
|
||||||
@ -154,65 +151,66 @@ const data = await sharp(input)
|
|||||||
})
|
})
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Set output metadata to 96 DPI
|
// Set output metadata to 96 DPI
|
||||||
const data = await sharp(input)
|
const data = await sharp(input)
|
||||||
.withMetadata({ density: 96 })
|
.withMetadata({ density: 96 })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## toFormat
|
## toFormat
|
||||||
|
|
||||||
Force output to a given format.
|
Force output to a given format.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `format` **([string][2] | [Object][6])** as a string or an Object with an 'id' attribute
|
**Throws**:
|
||||||
* `options` **[Object][6]** output options
|
|
||||||
|
|
||||||
### Examples
|
- <code>Error</code> unsupported format or options
|
||||||
|
|
||||||
```javascript
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| format | <code>string</code> \| <code>Object</code> | as a string or an Object with an 'id' attribute |
|
||||||
|
| options | <code>Object</code> | output options |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
// Convert any input to PNG output
|
// Convert any input to PNG output
|
||||||
const data = await sharp(input)
|
const data = await sharp(input)
|
||||||
.toFormat('png')
|
.toFormat('png')
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][4]** unsupported format or options
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## jpeg
|
## jpeg
|
||||||
|
|
||||||
Use these JPEG options for output image.
|
Use these JPEG options for output image.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][6]?** output options
|
**Throws**:
|
||||||
|
|
||||||
* `options.quality` **[number][12]** quality, integer 1-100 (optional, default `80`)
|
- <code>Error</code> Invalid options
|
||||||
* `options.progressive` **[boolean][10]** use progressive (interlace) scan (optional, default `false`)
|
|
||||||
* `options.chromaSubsampling` **[string][2]** set to '4:4:4' to prevent chroma subsampling otherwise defaults to '4:2:0' chroma subsampling (optional, default `'4:2:0'`)
|
|
||||||
* `options.optimiseCoding` **[boolean][10]** optimise Huffman coding tables (optional, default `true`)
|
|
||||||
* `options.optimizeCoding` **[boolean][10]** alternative spelling of optimiseCoding (optional, default `true`)
|
|
||||||
* `options.mozjpeg` **[boolean][10]** use mozjpeg defaults, equivalent to `{ trellisQuantisation: true, overshootDeringing: true, optimiseScans: true, quantisationTable: 3 }` (optional, default `false`)
|
|
||||||
* `options.trellisQuantisation` **[boolean][10]** apply trellis quantisation (optional, default `false`)
|
|
||||||
* `options.overshootDeringing` **[boolean][10]** apply overshoot deringing (optional, default `false`)
|
|
||||||
* `options.optimiseScans` **[boolean][10]** optimise progressive scans, forces progressive (optional, default `false`)
|
|
||||||
* `options.optimizeScans` **[boolean][10]** alternative spelling of optimiseScans (optional, default `false`)
|
|
||||||
* `options.quantisationTable` **[number][12]** quantization table to use, integer 0-8 (optional, default `0`)
|
|
||||||
* `options.quantizationTable` **[number][12]** alternative spelling of quantisationTable (optional, default `0`)
|
|
||||||
* `options.force` **[boolean][10]** force JPEG output, otherwise attempt to use input format (optional, default `true`)
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [options] | <code>Object</code> | | output options |
|
||||||
|
| [options.quality] | <code>number</code> | <code>80</code> | quality, integer 1-100 |
|
||||||
|
| [options.progressive] | <code>boolean</code> | <code>false</code> | use progressive (interlace) scan |
|
||||||
|
| [options.chromaSubsampling] | <code>string</code> | <code>"'4:2:0'"</code> | set to '4:4:4' to prevent chroma subsampling otherwise defaults to '4:2:0' chroma subsampling |
|
||||||
|
| [options.optimiseCoding] | <code>boolean</code> | <code>true</code> | optimise Huffman coding tables |
|
||||||
|
| [options.optimizeCoding] | <code>boolean</code> | <code>true</code> | alternative spelling of optimiseCoding |
|
||||||
|
| [options.mozjpeg] | <code>boolean</code> | <code>false</code> | use mozjpeg defaults, equivalent to `{ trellisQuantisation: true, overshootDeringing: true, optimiseScans: true, quantisationTable: 3 }` |
|
||||||
|
| [options.trellisQuantisation] | <code>boolean</code> | <code>false</code> | apply trellis quantisation |
|
||||||
|
| [options.overshootDeringing] | <code>boolean</code> | <code>false</code> | apply overshoot deringing |
|
||||||
|
| [options.optimiseScans] | <code>boolean</code> | <code>false</code> | optimise progressive scans, forces progressive |
|
||||||
|
| [options.optimizeScans] | <code>boolean</code> | <code>false</code> | alternative spelling of optimiseScans |
|
||||||
|
| [options.quantisationTable] | <code>number</code> | <code>0</code> | quantization table to use, integer 0-8 |
|
||||||
|
| [options.quantizationTable] | <code>number</code> | <code>0</code> | alternative spelling of quantisationTable |
|
||||||
|
| [options.force] | <code>boolean</code> | <code>true</code> | force JPEG output, otherwise attempt to use input format |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
// Convert any input to very high quality JPEG output
|
// Convert any input to very high quality JPEG output
|
||||||
const data = await sharp(input)
|
const data = await sharp(input)
|
||||||
.jpeg({
|
.jpeg({
|
||||||
@ -221,234 +219,186 @@ const data = await sharp(input)
|
|||||||
})
|
})
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Use mozjpeg to reduce output JPEG file size (slower)
|
// Use mozjpeg to reduce output JPEG file size (slower)
|
||||||
const data = await sharp(input)
|
const data = await sharp(input)
|
||||||
.jpeg({ mozjpeg: true })
|
.jpeg({ mozjpeg: true })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid options
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## png
|
## png
|
||||||
|
|
||||||
Use these PNG options for output image.
|
Use these PNG options for output image.
|
||||||
|
|
||||||
By default, PNG output is full colour at 8 or 16 bits per pixel.
|
By default, PNG output is full colour at 8 or 16 bits per pixel.
|
||||||
Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
||||||
Set `palette` to `true` for slower, indexed PNG output.
|
Set `palette` to `true` for slower, indexed PNG output.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][6]?** 
|
**Throws**:
|
||||||
|
|
||||||
* `options.progressive` **[boolean][10]** use progressive (interlace) scan (optional, default `false`)
|
- <code>Error</code> Invalid options
|
||||||
* `options.compressionLevel` **[number][12]** zlib compression level, 0 (fastest, largest) to 9 (slowest, smallest) (optional, default `6`)
|
|
||||||
* `options.adaptiveFiltering` **[boolean][10]** use adaptive row filtering (optional, default `false`)
|
|
||||||
* `options.palette` **[boolean][10]** quantise to a palette-based image with alpha transparency support (optional, default `false`)
|
|
||||||
* `options.quality` **[number][12]** use the lowest number of colours needed to achieve given quality, sets `palette` to `true` (optional, default `100`)
|
|
||||||
* `options.effort` **[number][12]** CPU effort, between 1 (fastest) and 10 (slowest), sets `palette` to `true` (optional, default `7`)
|
|
||||||
* `options.colours` **[number][12]** maximum number of palette entries, sets `palette` to `true` (optional, default `256`)
|
|
||||||
* `options.colors` **[number][12]** alternative spelling of `options.colours`, sets `palette` to `true` (optional, default `256`)
|
|
||||||
* `options.dither` **[number][12]** level of Floyd-Steinberg error diffusion, sets `palette` to `true` (optional, default `1.0`)
|
|
||||||
* `options.force` **[boolean][10]** force PNG output, otherwise attempt to use input format (optional, default `true`)
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [options] | <code>Object</code> | | |
|
||||||
|
| [options.progressive] | <code>boolean</code> | <code>false</code> | use progressive (interlace) scan |
|
||||||
|
| [options.compressionLevel] | <code>number</code> | <code>6</code> | zlib compression level, 0 (fastest, largest) to 9 (slowest, smallest) |
|
||||||
|
| [options.adaptiveFiltering] | <code>boolean</code> | <code>false</code> | use adaptive row filtering |
|
||||||
|
| [options.palette] | <code>boolean</code> | <code>false</code> | quantise to a palette-based image with alpha transparency support |
|
||||||
|
| [options.quality] | <code>number</code> | <code>100</code> | use the lowest number of colours needed to achieve given quality, sets `palette` to `true` |
|
||||||
|
| [options.effort] | <code>number</code> | <code>7</code> | CPU effort, between 1 (fastest) and 10 (slowest), sets `palette` to `true` |
|
||||||
|
| [options.colours] | <code>number</code> | <code>256</code> | maximum number of palette entries, sets `palette` to `true` |
|
||||||
|
| [options.colors] | <code>number</code> | <code>256</code> | alternative spelling of `options.colours`, sets `palette` to `true` |
|
||||||
|
| [options.dither] | <code>number</code> | <code>1.0</code> | level of Floyd-Steinberg error diffusion, sets `palette` to `true` |
|
||||||
|
| [options.force] | <code>boolean</code> | <code>true</code> | force PNG output, otherwise attempt to use input format |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
// Convert any input to full colour PNG output
|
// Convert any input to full colour PNG output
|
||||||
const data = await sharp(input)
|
const data = await sharp(input)
|
||||||
.png()
|
.png()
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Convert any input to indexed PNG output (slower)
|
// Convert any input to indexed PNG output (slower)
|
||||||
const data = await sharp(input)
|
const data = await sharp(input)
|
||||||
.png({ palette: true })
|
.png({ palette: true })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid options
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## webp
|
## webp
|
||||||
|
|
||||||
Use these WebP options for output image.
|
Use these WebP options for output image.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][6]?** output options
|
**Throws**:
|
||||||
|
|
||||||
* `options.quality` **[number][12]** quality, integer 1-100 (optional, default `80`)
|
- <code>Error</code> Invalid options
|
||||||
* `options.alphaQuality` **[number][12]** quality of alpha layer, integer 0-100 (optional, default `100`)
|
|
||||||
* `options.lossless` **[boolean][10]** use lossless compression mode (optional, default `false`)
|
|
||||||
* `options.nearLossless` **[boolean][10]** use near\_lossless compression mode (optional, default `false`)
|
|
||||||
* `options.smartSubsample` **[boolean][10]** use high quality chroma subsampling (optional, default `false`)
|
|
||||||
* `options.effort` **[number][12]** CPU effort, between 0 (fastest) and 6 (slowest) (optional, default `4`)
|
|
||||||
* `options.loop` **[number][12]** number of animation iterations, use 0 for infinite animation (optional, default `0`)
|
|
||||||
* `options.delay` **([number][12] | [Array][13]<[number][12]>)?** delay(s) between animation frames (in milliseconds)
|
|
||||||
* `options.minSize` **[boolean][10]** prevent use of animation key frames to minimise file size (slow) (optional, default `false`)
|
|
||||||
* `options.mixed` **[boolean][10]** allow mixture of lossy and lossless animation frames (slow) (optional, default `false`)
|
|
||||||
* `options.force` **[boolean][10]** force WebP output, otherwise attempt to use input format (optional, default `true`)
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [options] | <code>Object</code> | | output options |
|
||||||
|
| [options.quality] | <code>number</code> | <code>80</code> | quality, integer 1-100 |
|
||||||
|
| [options.alphaQuality] | <code>number</code> | <code>100</code> | quality of alpha layer, integer 0-100 |
|
||||||
|
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression mode |
|
||||||
|
| [options.nearLossless] | <code>boolean</code> | <code>false</code> | use near_lossless compression mode |
|
||||||
|
| [options.smartSubsample] | <code>boolean</code> | <code>false</code> | use high quality chroma subsampling |
|
||||||
|
| [options.effort] | <code>number</code> | <code>4</code> | CPU effort, between 0 (fastest) and 6 (slowest) |
|
||||||
|
| [options.loop] | <code>number</code> | <code>0</code> | number of animation iterations, use 0 for infinite animation |
|
||||||
|
| [options.delay] | <code>number</code> \| <code>Array.<number></code> | | delay(s) between animation frames (in milliseconds) |
|
||||||
|
| [options.minSize] | <code>boolean</code> | <code>false</code> | prevent use of animation key frames to minimise file size (slow) |
|
||||||
|
| [options.mixed] | <code>boolean</code> | <code>false</code> | allow mixture of lossy and lossless animation frames (slow) |
|
||||||
|
| [options.force] | <code>boolean</code> | <code>true</code> | force WebP output, otherwise attempt to use input format |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
// Convert any input to lossless WebP output
|
// Convert any input to lossless WebP output
|
||||||
const data = await sharp(input)
|
const data = await sharp(input)
|
||||||
.webp({ lossless: true })
|
.webp({ lossless: true })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Optimise the file size of an animated WebP
|
// Optimise the file size of an animated WebP
|
||||||
const outputWebp = await sharp(inputWebp, { animated: true })
|
const outputWebp = await sharp(inputWebp, { animated: true })
|
||||||
.webp({ effort: 6 })
|
.webp({ effort: 6 })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid options
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## gif
|
## gif
|
||||||
|
|
||||||
Use these GIF options for the output image.
|
Use these GIF options for the output image.
|
||||||
|
|
||||||
The first entry in the palette is reserved for transparency.
|
The first entry in the palette is reserved for transparency.
|
||||||
|
|
||||||
The palette of the input image will be re-used if possible.
|
The palette of the input image will be re-used if possible.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][6]?** output options
|
**Throws**:
|
||||||
|
|
||||||
* `options.reuse` **[boolean][10]** re-use existing palette, otherwise generate new (slow) (optional, default `true`)
|
- <code>Error</code> Invalid options
|
||||||
* `options.progressive` **[boolean][10]** use progressive (interlace) scan (optional, default `false`)
|
|
||||||
* `options.colours` **[number][12]** maximum number of palette entries, including transparency, between 2 and 256 (optional, default `256`)
|
|
||||||
* `options.colors` **[number][12]** alternative spelling of `options.colours` (optional, default `256`)
|
|
||||||
* `options.effort` **[number][12]** CPU effort, between 1 (fastest) and 10 (slowest) (optional, default `7`)
|
|
||||||
* `options.dither` **[number][12]** level of Floyd-Steinberg error diffusion, between 0 (least) and 1 (most) (optional, default `1.0`)
|
|
||||||
* `options.interFrameMaxError` **[number][12]** maximum inter-frame error for transparency, between 0 (lossless) and 32 (optional, default `0`)
|
|
||||||
* `options.interPaletteMaxError` **[number][12]** maximum inter-palette error for palette reuse, between 0 and 256 (optional, default `3`)
|
|
||||||
* `options.loop` **[number][12]** number of animation iterations, use 0 for infinite animation (optional, default `0`)
|
|
||||||
* `options.delay` **([number][12] | [Array][13]<[number][12]>)?** delay(s) between animation frames (in milliseconds)
|
|
||||||
* `options.force` **[boolean][10]** force GIF output, otherwise attempt to use input format (optional, default `true`)
|
|
||||||
|
|
||||||
### Examples
|
**Since**: 0.30.0
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [options] | <code>Object</code> | | output options |
|
||||||
|
| [options.reuse] | <code>boolean</code> | <code>true</code> | re-use existing palette, otherwise generate new (slow) |
|
||||||
|
| [options.progressive] | <code>boolean</code> | <code>false</code> | use progressive (interlace) scan |
|
||||||
|
| [options.colours] | <code>number</code> | <code>256</code> | maximum number of palette entries, including transparency, between 2 and 256 |
|
||||||
|
| [options.colors] | <code>number</code> | <code>256</code> | alternative spelling of `options.colours` |
|
||||||
|
| [options.effort] | <code>number</code> | <code>7</code> | CPU effort, between 1 (fastest) and 10 (slowest) |
|
||||||
|
| [options.dither] | <code>number</code> | <code>1.0</code> | level of Floyd-Steinberg error diffusion, between 0 (least) and 1 (most) |
|
||||||
|
| [options.interFrameMaxError] | <code>number</code> | <code>0</code> | maximum inter-frame error for transparency, between 0 (lossless) and 32 |
|
||||||
|
| [options.interPaletteMaxError] | <code>number</code> | <code>3</code> | maximum inter-palette error for palette reuse, between 0 and 256 |
|
||||||
|
| [options.loop] | <code>number</code> | <code>0</code> | number of animation iterations, use 0 for infinite animation |
|
||||||
|
| [options.delay] | <code>number</code> \| <code>Array.<number></code> | | delay(s) between animation frames (in milliseconds) |
|
||||||
|
| [options.force] | <code>boolean</code> | <code>true</code> | force GIF output, otherwise attempt to use input format |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
// Convert PNG to GIF
|
// Convert PNG to GIF
|
||||||
await sharp(pngBuffer)
|
await sharp(pngBuffer)
|
||||||
.gif()
|
.gif()
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Convert animated WebP to animated GIF
|
// Convert animated WebP to animated GIF
|
||||||
await sharp('animated.webp', { animated: true })
|
await sharp('animated.webp', { animated: true })
|
||||||
.toFile('animated.gif');
|
.toFile('animated.gif');
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Create a 128x128, cropped, non-dithered, animated thumbnail of an animated GIF
|
// Create a 128x128, cropped, non-dithered, animated thumbnail of an animated GIF
|
||||||
const out = await sharp('in.gif', { animated: true })
|
const out = await sharp('in.gif', { animated: true })
|
||||||
.resize({ width: 128, height: 128 })
|
.resize({ width: 128, height: 128 })
|
||||||
.gif({ dither: 0 })
|
.gif({ dither: 0 })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Lossy file size reduction of animated GIF
|
// Lossy file size reduction of animated GIF
|
||||||
await sharp('in.gif', { animated: true })
|
await sharp('in.gif', { animated: true })
|
||||||
.gif({ interFrameMaxError: 8 })
|
.gif({ interFrameMaxError: 8 })
|
||||||
.toFile('optim.gif');
|
.toFile('optim.gif');
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid options
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
**Meta**
|
|
||||||
|
|
||||||
* **since**: 0.30.0
|
|
||||||
|
|
||||||
## jp2
|
|
||||||
|
|
||||||
Use these JP2 options for output image.
|
|
||||||
|
|
||||||
Requires libvips compiled with support for OpenJPEG.
|
|
||||||
The prebuilt binaries do not include this - see
|
|
||||||
[installing a custom libvips][14].
|
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][6]?** output options
|
|
||||||
|
|
||||||
* `options.quality` **[number][12]** quality, integer 1-100 (optional, default `80`)
|
|
||||||
* `options.lossless` **[boolean][10]** use lossless compression mode (optional, default `false`)
|
|
||||||
* `options.tileWidth` **[number][12]** horizontal tile size (optional, default `512`)
|
|
||||||
* `options.tileHeight` **[number][12]** vertical tile size (optional, default `512`)
|
|
||||||
* `options.chromaSubsampling` **[string][2]** set to '4:2:0' to use chroma subsampling (optional, default `'4:4:4'`)
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// Convert any input to lossless JP2 output
|
|
||||||
const data = await sharp(input)
|
|
||||||
.jp2({ lossless: true })
|
|
||||||
.toBuffer();
|
|
||||||
```
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// Convert any input to very high quality JP2 output
|
|
||||||
const data = await sharp(input)
|
|
||||||
.jp2({
|
|
||||||
quality: 100,
|
|
||||||
chromaSubsampling: '4:4:4'
|
|
||||||
})
|
|
||||||
.toBuffer();
|
|
||||||
```
|
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid options
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
**Meta**
|
|
||||||
|
|
||||||
* **since**: 0.29.1
|
|
||||||
|
|
||||||
## tiff
|
## tiff
|
||||||
|
|
||||||
Use these TIFF options for output image.
|
Use these TIFF options for output image.
|
||||||
|
|
||||||
The `density` can be set in pixels/inch via [withMetadata][1] instead of providing `xres` and `yres` in pixels/mm.
|
The `density` can be set in pixels/inch via [withMetadata](#withMetadata) instead of providing `xres` and `yres` in pixels/mm.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][6]?** output options
|
**Throws**:
|
||||||
|
|
||||||
* `options.quality` **[number][12]** quality, integer 1-100 (optional, default `80`)
|
- <code>Error</code> Invalid options
|
||||||
* `options.force` **[boolean][10]** force TIFF output, otherwise attempt to use input format (optional, default `true`)
|
|
||||||
* `options.compression` **[string][2]** compression options: none, jpeg, deflate, packbits, ccittfax4, lzw, webp, zstd, jp2k (optional, default `'jpeg'`)
|
|
||||||
* `options.predictor` **[string][2]** compression predictor options: none, horizontal, float (optional, default `'horizontal'`)
|
|
||||||
* `options.pyramid` **[boolean][10]** write an image pyramid (optional, default `false`)
|
|
||||||
* `options.tile` **[boolean][10]** write a tiled tiff (optional, default `false`)
|
|
||||||
* `options.tileWidth` **[number][12]** horizontal tile size (optional, default `256`)
|
|
||||||
* `options.tileHeight` **[number][12]** vertical tile size (optional, default `256`)
|
|
||||||
* `options.xres` **[number][12]** horizontal resolution in pixels/mm (optional, default `1.0`)
|
|
||||||
* `options.yres` **[number][12]** vertical resolution in pixels/mm (optional, default `1.0`)
|
|
||||||
* `options.resolutionUnit` **[string][2]** resolution unit options: inch, cm (optional, default `'inch'`)
|
|
||||||
* `options.bitdepth` **[number][12]** reduce bitdepth to 1, 2 or 4 bit (optional, default `8`)
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [options] | <code>Object</code> | | output options |
|
||||||
|
| [options.quality] | <code>number</code> | <code>80</code> | quality, integer 1-100 |
|
||||||
|
| [options.force] | <code>boolean</code> | <code>true</code> | force TIFF output, otherwise attempt to use input format |
|
||||||
|
| [options.compression] | <code>string</code> | <code>"'jpeg'"</code> | compression options: none, jpeg, deflate, packbits, ccittfax4, lzw, webp, zstd, jp2k |
|
||||||
|
| [options.predictor] | <code>string</code> | <code>"'horizontal'"</code> | compression predictor options: none, horizontal, float |
|
||||||
|
| [options.pyramid] | <code>boolean</code> | <code>false</code> | write an image pyramid |
|
||||||
|
| [options.tile] | <code>boolean</code> | <code>false</code> | write a tiled tiff |
|
||||||
|
| [options.tileWidth] | <code>number</code> | <code>256</code> | horizontal tile size |
|
||||||
|
| [options.tileHeight] | <code>number</code> | <code>256</code> | vertical tile size |
|
||||||
|
| [options.xres] | <code>number</code> | <code>1.0</code> | horizontal resolution in pixels/mm |
|
||||||
|
| [options.yres] | <code>number</code> | <code>1.0</code> | vertical resolution in pixels/mm |
|
||||||
|
| [options.resolutionUnit] | <code>string</code> | <code>"'inch'"</code> | resolution unit options: inch, cm |
|
||||||
|
| [options.bitdepth] | <code>number</code> | <code>8</code> | reduce bitdepth to 1, 2 or 4 bit |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
// Convert SVG input to LZW-compressed, 1 bit per pixel TIFF output
|
// Convert SVG input to LZW-compressed, 1 bit per pixel TIFF output
|
||||||
sharp('input.svg')
|
sharp('input.svg')
|
||||||
.tiff({
|
.tiff({
|
||||||
@ -459,12 +409,8 @@ sharp('input.svg')
|
|||||||
.then(info => { ... });
|
.then(info => { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid options
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## avif
|
## avif
|
||||||
|
|
||||||
Use these AVIF options for output image.
|
Use these AVIF options for output image.
|
||||||
|
|
||||||
Whilst it is possible to create AVIF images smaller than 16x16 pixels,
|
Whilst it is possible to create AVIF images smaller than 16x16 pixels,
|
||||||
@ -472,124 +418,119 @@ most web browsers do not display these properly.
|
|||||||
|
|
||||||
AVIF image sequences are not supported.
|
AVIF image sequences are not supported.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][6]?** output options
|
**Throws**:
|
||||||
|
|
||||||
* `options.quality` **[number][12]** quality, integer 1-100 (optional, default `50`)
|
- <code>Error</code> Invalid options
|
||||||
* `options.lossless` **[boolean][10]** use lossless compression (optional, default `false`)
|
|
||||||
* `options.effort` **[number][12]** CPU effort, between 0 (fastest) and 9 (slowest) (optional, default `4`)
|
|
||||||
* `options.chromaSubsampling` **[string][2]** set to '4:2:0' to use chroma subsampling (optional, default `'4:4:4'`)
|
|
||||||
|
|
||||||
### Examples
|
**Since**: 0.27.0
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [options] | <code>Object</code> | | output options |
|
||||||
|
| [options.quality] | <code>number</code> | <code>50</code> | quality, integer 1-100 |
|
||||||
|
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression |
|
||||||
|
| [options.effort] | <code>number</code> | <code>4</code> | CPU effort, between 0 (fastest) and 9 (slowest) |
|
||||||
|
| [options.chromaSubsampling] | <code>string</code> | <code>"'4:4:4'"</code> | set to '4:2:0' to use chroma subsampling |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
const data = await sharp(input)
|
const data = await sharp(input)
|
||||||
.avif({ effort: 2 })
|
.avif({ effort: 2 })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const data = await sharp(input)
|
const data = await sharp(input)
|
||||||
.avif({ lossless: true })
|
.avif({ lossless: true })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid options
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
**Meta**
|
|
||||||
|
|
||||||
* **since**: 0.27.0
|
|
||||||
|
|
||||||
## heif
|
## heif
|
||||||
|
|
||||||
Use these HEIF options for output image.
|
Use these HEIF options for output image.
|
||||||
|
|
||||||
Support for patent-encumbered HEIC images using `hevc` compression requires the use of a
|
Support for patent-encumbered HEIC images using `hevc` compression requires the use of a
|
||||||
globally-installed libvips compiled with support for libheif, libde265 and x265.
|
globally-installed libvips compiled with support for libheif, libde265 and x265.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][6]?** output options
|
**Throws**:
|
||||||
|
|
||||||
* `options.quality` **[number][12]** quality, integer 1-100 (optional, default `50`)
|
- <code>Error</code> Invalid options
|
||||||
* `options.compression` **[string][2]** compression format: av1, hevc (optional, default `'av1'`)
|
|
||||||
* `options.lossless` **[boolean][10]** use lossless compression (optional, default `false`)
|
|
||||||
* `options.effort` **[number][12]** CPU effort, between 0 (fastest) and 9 (slowest) (optional, default `4`)
|
|
||||||
* `options.chromaSubsampling` **[string][2]** set to '4:2:0' to use chroma subsampling (optional, default `'4:4:4'`)
|
|
||||||
|
|
||||||
### Examples
|
**Since**: 0.23.0
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [options] | <code>Object</code> | | output options |
|
||||||
|
| [options.quality] | <code>number</code> | <code>50</code> | quality, integer 1-100 |
|
||||||
|
| [options.compression] | <code>string</code> | <code>"'av1'"</code> | compression format: av1, hevc |
|
||||||
|
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression |
|
||||||
|
| [options.effort] | <code>number</code> | <code>4</code> | CPU effort, between 0 (fastest) and 9 (slowest) |
|
||||||
|
| [options.chromaSubsampling] | <code>string</code> | <code>"'4:4:4'"</code> | set to '4:2:0' to use chroma subsampling |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
const data = await sharp(input)
|
const data = await sharp(input)
|
||||||
.heif({ compression: 'hevc' })
|
.heif({ compression: 'hevc' })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid options
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
**Meta**
|
|
||||||
|
|
||||||
* **since**: 0.23.0
|
|
||||||
|
|
||||||
## jxl
|
## jxl
|
||||||
|
|
||||||
Use these JPEG-XL (JXL) options for output image.
|
Use these JPEG-XL (JXL) options for output image.
|
||||||
|
|
||||||
This feature is experimental, please do not use in production systems.
|
This feature is experimental, please do not use in production systems.
|
||||||
|
|
||||||
Requires libvips compiled with support for libjxl.
|
Requires libvips compiled with support for libjxl.
|
||||||
The prebuilt binaries do not include this - see
|
The prebuilt binaries do not include this - see
|
||||||
[installing a custom libvips][14].
|
[installing a custom libvips](https://sharp.pixelplumbing.com/install#custom-libvips).
|
||||||
|
|
||||||
Image metadata (EXIF, XMP) is unsupported.
|
Image metadata (EXIF, XMP) is unsupported.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][6]?** output options
|
**Throws**:
|
||||||
|
|
||||||
* `options.distance` **[number][12]** maximum encoding error, between 0 (highest quality) and 15 (lowest quality) (optional, default `1.0`)
|
- <code>Error</code> Invalid options
|
||||||
* `options.quality` **[number][12]?** calculate `distance` based on JPEG-like quality, between 1 and 100, overrides distance if specified
|
|
||||||
* `options.decodingTier` **[number][12]** target decode speed tier, between 0 (highest quality) and 4 (lowest quality) (optional, default `0`)
|
|
||||||
* `options.lossless` **[boolean][10]** use lossless compression (optional, default `false`)
|
|
||||||
* `options.effort` **[number][12]** CPU effort, between 3 (fastest) and 9 (slowest) (optional, default `7`)
|
|
||||||
|
|
||||||
<!---->
|
**Since**: 0.31.3
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid options
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [options] | <code>Object</code> | | output options |
|
||||||
|
| [options.distance] | <code>number</code> | <code>1.0</code> | maximum encoding error, between 0 (highest quality) and 15 (lowest quality) |
|
||||||
|
| [options.quality] | <code>number</code> | | calculate `distance` based on JPEG-like quality, between 1 and 100, overrides distance if specified |
|
||||||
|
| [options.decodingTier] | <code>number</code> | <code>0</code> | target decode speed tier, between 0 (highest quality) and 4 (lowest quality) |
|
||||||
|
| [options.lossless] | <code>boolean</code> | <code>false</code> | use lossless compression |
|
||||||
|
| [options.effort] | <code>number</code> | <code>7</code> | CPU effort, between 3 (fastest) and 9 (slowest) |
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
**Meta**
|
|
||||||
|
|
||||||
* **since**: 0.31.3
|
|
||||||
|
|
||||||
## raw
|
## raw
|
||||||
|
|
||||||
Force output to be raw, uncompressed pixel data.
|
Force output to be raw, uncompressed pixel data.
|
||||||
Pixel ordering is left-to-right, top-to-bottom, without padding.
|
Pixel ordering is left-to-right, top-to-bottom, without padding.
|
||||||
Channel ordering will be RGB or RGBA for non-greyscale colourspaces.
|
Channel ordering will be RGB or RGBA for non-greyscale colourspaces.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][6]?** output options
|
**Throws**:
|
||||||
|
|
||||||
* `options.depth` **[string][2]** bit depth, one of: char, uchar (default), short, ushort, int, uint, float, complex, double, dpcomplex (optional, default `'uchar'`)
|
- <code>Error</code> Invalid options
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [options] | <code>Object</code> | | output options |
|
||||||
|
| [options.depth] | <code>string</code> | <code>"'uchar'"</code> | bit depth, one of: char, uchar (default), short, ushort, int, uint, float, complex, double, dpcomplex |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
// Extract raw, unsigned 8-bit RGB pixel data from JPEG input
|
// Extract raw, unsigned 8-bit RGB pixel data from JPEG input
|
||||||
const { data, info } = await sharp('input.jpg')
|
const { data, info } = await sharp('input.jpg')
|
||||||
.raw()
|
.raw()
|
||||||
.toBuffer({ resolveWithObject: true });
|
.toBuffer({ resolveWithObject: true });
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Extract alpha channel as raw, unsigned 16-bit pixel data from PNG input
|
// Extract alpha channel as raw, unsigned 16-bit pixel data from PNG input
|
||||||
const data = await sharp('input.png')
|
const data = await sharp('input.png')
|
||||||
.ensureAlpha()
|
.ensureAlpha()
|
||||||
@ -599,10 +540,8 @@ const data = await sharp('input.png')
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid options
|
|
||||||
|
|
||||||
## tile
|
## tile
|
||||||
|
|
||||||
Use tile-based deep zoom (image pyramid) output.
|
Use tile-based deep zoom (image pyramid) output.
|
||||||
|
|
||||||
Set the format and options for tile images via the `toFormat`, `jpeg`, `png` or `webp` functions.
|
Set the format and options for tile images via the `toFormat`, `jpeg`, `png` or `webp` functions.
|
||||||
@ -610,26 +549,30 @@ Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed arc
|
|||||||
|
|
||||||
The container will be set to `zip` when the output is a Buffer or Stream, otherwise it will default to `fs`.
|
The container will be set to `zip` when the output is a Buffer or Stream, otherwise it will default to `fs`.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][6]?** 
|
**Throws**:
|
||||||
|
|
||||||
* `options.size` **[number][12]** tile size in pixels, a value between 1 and 8192. (optional, default `256`)
|
- <code>Error</code> Invalid parameters
|
||||||
* `options.overlap` **[number][12]** tile overlap in pixels, a value between 0 and 8192. (optional, default `0`)
|
|
||||||
* `options.angle` **[number][12]** tile angle of rotation, must be a multiple of 90. (optional, default `0`)
|
|
||||||
* `options.background` **([string][2] | [Object][6])** background colour, parsed by the [color][15] module, defaults to white without transparency. (optional, default `{r:255,g:255,b:255,alpha:1}`)
|
|
||||||
* `options.depth` **[string][2]?** how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
|
||||||
* `options.skipBlanks` **[number][12]** threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images (optional, default `-1`)
|
|
||||||
* `options.container` **[string][2]** tile container, with value `fs` (filesystem) or `zip` (compressed file). (optional, default `'fs'`)
|
|
||||||
* `options.layout` **[string][2]** filesystem layout, possible values are `dz`, `iiif`, `iiif3`, `zoomify` or `google`. (optional, default `'dz'`)
|
|
||||||
* `options.centre` **[boolean][10]** centre image in tile. (optional, default `false`)
|
|
||||||
* `options.center` **[boolean][10]** alternative spelling of centre. (optional, default `false`)
|
|
||||||
* `options.id` **[string][2]** when `layout` is `iiif`/`iiif3`, sets the `@id`/`id` attribute of `info.json` (optional, default `'https://example.com/iiif'`)
|
|
||||||
* `options.basename` **[string][2]?** the name of the directory within the zip file when container is `zip`.
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [options] | <code>Object</code> | | |
|
||||||
|
| [options.size] | <code>number</code> | <code>256</code> | tile size in pixels, a value between 1 and 8192. |
|
||||||
|
| [options.overlap] | <code>number</code> | <code>0</code> | tile overlap in pixels, a value between 0 and 8192. |
|
||||||
|
| [options.angle] | <code>number</code> | <code>0</code> | tile angle of rotation, must be a multiple of 90. |
|
||||||
|
| [options.background] | <code>string</code> \| <code>Object</code> | <code>"{r: 255, g: 255, b: 255, alpha: 1}"</code> | background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to white without transparency. |
|
||||||
|
| [options.depth] | <code>string</code> | | how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout. |
|
||||||
|
| [options.skipBlanks] | <code>number</code> | <code>-1</code> | threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images |
|
||||||
|
| [options.container] | <code>string</code> | <code>"'fs'"</code> | tile container, with value `fs` (filesystem) or `zip` (compressed file). |
|
||||||
|
| [options.layout] | <code>string</code> | <code>"'dz'"</code> | filesystem layout, possible values are `dz`, `iiif`, `iiif3`, `zoomify` or `google`. |
|
||||||
|
| [options.centre] | <code>boolean</code> | <code>false</code> | centre image in tile. |
|
||||||
|
| [options.center] | <code>boolean</code> | <code>false</code> | alternative spelling of centre. |
|
||||||
|
| [options.id] | <code>string</code> | <code>"'https://example.com/iiif'"</code> | when `layout` is `iiif`/`iiif3`, sets the `@id`/`id` attribute of `info.json` |
|
||||||
|
| [options.basename] | <code>string</code> | | the name of the directory within the zip file when container is `zip`. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
sharp('input.tiff')
|
sharp('input.tiff')
|
||||||
.png()
|
.png()
|
||||||
.tile({
|
.tile({
|
||||||
@ -640,41 +583,38 @@ sharp('input.tiff')
|
|||||||
// output_files contains 512x512 tiles grouped by zoom level
|
// output_files contains 512x512 tiles grouped by zoom level
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const zipFileWithTiles = await sharp(input)
|
const zipFileWithTiles = await sharp(input)
|
||||||
.tile({ basename: "tiles" })
|
.tile({ basename: "tiles" })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const iiififier = sharp().tile({ layout: "iiif" });
|
const iiififier = sharp().tile({ layout: "iiif" });
|
||||||
readableStream
|
readableStream
|
||||||
.pipe(iiififier)
|
.pipe(iiififier)
|
||||||
.pipe(writeableStream);
|
.pipe(writeableStream);
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][4]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## timeout
|
## timeout
|
||||||
|
|
||||||
Set a timeout for processing, in seconds.
|
Set a timeout for processing, in seconds.
|
||||||
Use a value of zero to continue processing indefinitely, the default behaviour.
|
Use a value of zero to continue processing indefinitely, the default behaviour.
|
||||||
|
|
||||||
The clock starts when libvips opens an input image for processing.
|
The clock starts when libvips opens an input image for processing.
|
||||||
Time spent waiting for a libuv thread to become available is not included.
|
Time spent waiting for a libuv thread to become available is not included.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][6]** 
|
**Since**: 0.29.2
|
||||||
|
|
||||||
* `options.seconds` **[number][12]** Number of seconds after which processing will be stopped
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| options | <code>Object</code> | |
|
||||||
|
| options.seconds | <code>number</code> | Number of seconds after which processing will be stopped |
|
||||||
|
|
||||||
### Examples
|
**Example**
|
||||||
|
```js
|
||||||
```javascript
|
|
||||||
// Ensure processing takes no longer than 3 seconds
|
// Ensure processing takes no longer than 3 seconds
|
||||||
try {
|
try {
|
||||||
const data = await sharp(input)
|
const data = await sharp(input)
|
||||||
@ -685,39 +625,3 @@ try {
|
|||||||
if (err.message.includes('timeout')) { ... }
|
if (err.message.includes('timeout')) { ... }
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
**Meta**
|
|
||||||
|
|
||||||
* **since**: 0.29.2
|
|
||||||
|
|
||||||
[1]: #withmetadata
|
|
||||||
|
|
||||||
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
||||||
|
|
||||||
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
|
|
||||||
|
|
||||||
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
||||||
|
|
||||||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
|
||||||
|
|
||||||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
|
||||||
[7]: #toformat
|
|
||||||
|
|
||||||
[8]: #jpeg
|
|
||||||
|
|
||||||
[9]: #png
|
|
||||||
|
|
||||||
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
||||||
|
|
||||||
[11]: https://nodejs.org/api/buffer.html
|
|
||||||
|
|
||||||
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
||||||
|
|
||||||
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
||||||
|
|
||||||
[14]: https://sharp.pixelplumbing.com/install#custom-libvips
|
|
||||||
|
|
||||||
[15]: https://www.npmjs.org/package/color
|
|
||||||
|
@ -1,65 +1,62 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
||||||
|
|
||||||
## resize
|
## resize
|
||||||
|
|
||||||
Resize image to `width`, `height` or `width x height`.
|
Resize image to `width`, `height` or `width x height`.
|
||||||
|
|
||||||
When both a `width` and `height` are provided, the possible methods by which the image should **fit** these are:
|
When both a `width` and `height` are provided, the possible methods by which the image should **fit** these are:
|
||||||
|
- `cover`: (default) Preserving aspect ratio, ensure the image covers both provided dimensions by cropping/clipping to fit.
|
||||||
|
- `contain`: Preserving aspect ratio, contain within both provided dimensions using "letterboxing" where necessary.
|
||||||
|
- `fill`: Ignore the aspect ratio of the input and stretch to both provided dimensions.
|
||||||
|
- `inside`: Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to both those specified.
|
||||||
|
- `outside`: Preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to both those specified.
|
||||||
|
|
||||||
* `cover`: (default) Preserving aspect ratio, ensure the image covers both provided dimensions by cropping/clipping to fit.
|
Some of these values are based on the [object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) CSS property.
|
||||||
* `contain`: Preserving aspect ratio, contain within both provided dimensions using "letterboxing" where necessary.
|
|
||||||
* `fill`: Ignore the aspect ratio of the input and stretch to both provided dimensions.
|
|
||||||
* `inside`: Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to both those specified.
|
|
||||||
* `outside`: Preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to both those specified.
|
|
||||||
|
|
||||||
Some of these values are based on the [object-fit][1] CSS property.
|
|
||||||
|
|
||||||
<img alt="Examples of various values for the fit property when resizing" width="100%" style="aspect-ratio: 998/243" src="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/api-resize-fit.png">
|
<img alt="Examples of various values for the fit property when resizing" width="100%" style="aspect-ratio: 998/243" src="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/image/api-resize-fit.png">
|
||||||
|
|
||||||
When using a **fit** of `cover` or `contain`, the default **position** is `centre`. Other options are:
|
When using a **fit** of `cover` or `contain`, the default **position** is `centre`. Other options are:
|
||||||
|
- `sharp.position`: `top`, `right top`, `right`, `right bottom`, `bottom`, `left bottom`, `left`, `left top`.
|
||||||
|
- `sharp.gravity`: `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` or `centre`.
|
||||||
|
- `sharp.strategy`: `cover` only, dynamically crop using either the `entropy` or `attention` strategy.
|
||||||
|
|
||||||
* `sharp.position`: `top`, `right top`, `right`, `right bottom`, `bottom`, `left bottom`, `left`, `left top`.
|
Some of these values are based on the [object-position](https://developer.mozilla.org/en-US/docs/Web/CSS/object-position) CSS property.
|
||||||
* `sharp.gravity`: `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` or `centre`.
|
|
||||||
* `sharp.strategy`: `cover` only, dynamically crop using either the `entropy` or `attention` strategy.
|
|
||||||
|
|
||||||
Some of these values are based on the [object-position][2] CSS property.
|
|
||||||
|
|
||||||
The experimental strategy-based approach resizes so one dimension is at its target length
|
The experimental strategy-based approach resizes so one dimension is at its target length
|
||||||
then repeatedly ranks edge regions, discarding the edge with the lowest score based on the selected strategy.
|
then repeatedly ranks edge regions, discarding the edge with the lowest score based on the selected strategy.
|
||||||
|
- `entropy`: focus on the region with the highest [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_%28information_theory%29).
|
||||||
* `entropy`: focus on the region with the highest [Shannon entropy][3].
|
- `attention`: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
|
||||||
* `attention`: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
|
|
||||||
|
|
||||||
Possible interpolation kernels are:
|
Possible interpolation kernels are:
|
||||||
|
- `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
|
||||||
* `nearest`: Use [nearest neighbour interpolation][4].
|
- `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
|
||||||
* `cubic`: Use a [Catmull-Rom spline][5].
|
- `mitchell`: Use a [Mitchell-Netravali spline](https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf).
|
||||||
* `mitchell`: Use a [Mitchell-Netravali spline][6].
|
- `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
|
||||||
* `lanczos2`: Use a [Lanczos kernel][7] with `a=2`.
|
- `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
||||||
* `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
|
||||||
|
|
||||||
Only one resize can occur per pipeline.
|
Only one resize can occur per pipeline.
|
||||||
Previous calls to `resize` in the same pipeline will be ignored.
|
Previous calls to `resize` in the same pipeline will be ignored.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `width` **[number][8]?** pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.
|
**Throws**:
|
||||||
* `height` **[number][8]?** pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
|
|
||||||
* `options` **[Object][9]?** 
|
|
||||||
|
|
||||||
* `options.width` **[String][10]?** alternative means of specifying `width`. If both are present this takes priority.
|
- <code>Error</code> Invalid parameters
|
||||||
* `options.height` **[String][10]?** alternative means of specifying `height`. If both are present this takes priority.
|
|
||||||
* `options.fit` **[String][10]** how the image should be resized to fit both provided dimensions, one of `cover`, `contain`, `fill`, `inside` or `outside`. (optional, default `'cover'`)
|
|
||||||
* `options.position` **[String][10]** position, gravity or strategy to use when `fit` is `cover` or `contain`. (optional, default `'centre'`)
|
|
||||||
* `options.background` **([String][10] | [Object][9])** background colour when `fit` is `contain`, parsed by the [color][11] module, defaults to black without transparency. (optional, default `{r:0,g:0,b:0,alpha:1}`)
|
|
||||||
* `options.kernel` **[String][10]** the kernel to use for image reduction. (optional, default `'lanczos3'`)
|
|
||||||
* `options.withoutEnlargement` **[Boolean][12]** do not enlarge if the width *or* height are already less than the specified dimensions, equivalent to GraphicsMagick's `>` geometry option. (optional, default `false`)
|
|
||||||
* `options.withoutReduction` **[Boolean][12]** do not reduce if the width *or* height are already greater than the specified dimensions, equivalent to GraphicsMagick's `<` geometry option. (optional, default `false`)
|
|
||||||
* `options.fastShrinkOnLoad` **[Boolean][12]** take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern on some images. (optional, default `true`)
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| [width] | <code>number</code> | | pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height. |
|
||||||
|
| [height] | <code>number</code> | | pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width. |
|
||||||
|
| [options] | <code>Object</code> | | |
|
||||||
|
| [options.width] | <code>String</code> | | alternative means of specifying `width`. If both are present this takes priority. |
|
||||||
|
| [options.height] | <code>String</code> | | alternative means of specifying `height`. If both are present this takes priority. |
|
||||||
|
| [options.fit] | <code>String</code> | <code>'cover'</code> | how the image should be resized to fit both provided dimensions, one of `cover`, `contain`, `fill`, `inside` or `outside`. |
|
||||||
|
| [options.position] | <code>String</code> | <code>'centre'</code> | position, gravity or strategy to use when `fit` is `cover` or `contain`. |
|
||||||
|
| [options.background] | <code>String</code> \| <code>Object</code> | <code>{r: 0, g: 0, b: 0, alpha: 1}</code> | background colour when `fit` is `contain`, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency. |
|
||||||
|
| [options.kernel] | <code>String</code> | <code>'lanczos3'</code> | the kernel to use for image reduction. Use the `fastShrinkOnLoad` option to control kernel vs shrink-on-load. |
|
||||||
|
| [options.withoutEnlargement] | <code>Boolean</code> | <code>false</code> | do not enlarge if the width *or* height are already less than the specified dimensions, equivalent to GraphicsMagick's `>` geometry option. |
|
||||||
|
| [options.withoutReduction] | <code>Boolean</code> | <code>false</code> | do not reduce if the width *or* height are already greater than the specified dimensions, equivalent to GraphicsMagick's `<` geometry option. |
|
||||||
|
| [options.fastShrinkOnLoad] | <code>Boolean</code> | <code>true</code> | take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern on some images. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.resize({ width: 100 })
|
.resize({ width: 100 })
|
||||||
.toBuffer()
|
.toBuffer()
|
||||||
@ -67,8 +64,8 @@ sharp(input)
|
|||||||
// 100 pixels wide, auto-scaled height
|
// 100 pixels wide, auto-scaled height
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.resize({ height: 100 })
|
.resize({ height: 100 })
|
||||||
.toBuffer()
|
.toBuffer()
|
||||||
@ -76,8 +73,8 @@ sharp(input)
|
|||||||
// 100 pixels high, auto-scaled width
|
// 100 pixels high, auto-scaled width
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.resize(200, 300, {
|
.resize(200, 300, {
|
||||||
kernel: sharp.kernel.nearest,
|
kernel: sharp.kernel.nearest,
|
||||||
@ -92,8 +89,8 @@ sharp(input)
|
|||||||
// contained within the north-east corner of a semi-transparent white canvas
|
// contained within the north-east corner of a semi-transparent white canvas
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const transformer = sharp()
|
const transformer = sharp()
|
||||||
.resize({
|
.resize({
|
||||||
width: 200,
|
width: 200,
|
||||||
@ -107,8 +104,8 @@ readableStream
|
|||||||
.pipe(transformer)
|
.pipe(transformer)
|
||||||
.pipe(writableStream);
|
.pipe(writableStream);
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.inside,
|
fit: sharp.fit.inside,
|
||||||
@ -122,8 +119,8 @@ sharp(input)
|
|||||||
// and no larger than the input image
|
// and no larger than the input image
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.resize(200, 200, {
|
.resize(200, 200, {
|
||||||
fit: sharp.fit.outside,
|
fit: sharp.fit.outside,
|
||||||
@ -137,8 +134,8 @@ sharp(input)
|
|||||||
// and no smaller than the input image
|
// and no smaller than the input image
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const scaleByHalf = await sharp(input)
|
const scaleByHalf = await sharp(input)
|
||||||
.metadata()
|
.metadata()
|
||||||
.then(({ width }) => sharp(input)
|
.then(({ width }) => sharp(input)
|
||||||
@ -147,28 +144,28 @@ const scaleByHalf = await sharp(input)
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][13]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## extend
|
## extend
|
||||||
|
|
||||||
Extends/pads the edges of the image with the provided background colour.
|
Extends/pads the edges of the image with the provided background colour.
|
||||||
This operation will always occur after resizing and extraction, if any.
|
This operation will always occur after resizing and extraction, if any.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `extend` **([number][8] | [Object][9])** single pixel count to add to all edges or an Object with per-edge counts
|
**Throws**:
|
||||||
|
|
||||||
* `extend.top` **[number][8]** (optional, default `0`)
|
- <code>Error</code> Invalid parameters
|
||||||
* `extend.left` **[number][8]** (optional, default `0`)
|
|
||||||
* `extend.bottom` **[number][8]** (optional, default `0`)
|
|
||||||
* `extend.right` **[number][8]** (optional, default `0`)
|
|
||||||
* `extend.background` **([String][10] | [Object][9])** background colour, parsed by the [color][11] module, defaults to black without transparency. (optional, default `{r:0,g:0,b:0,alpha:1}`)
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| extend | <code>number</code> \| <code>Object</code> | | single pixel count to add to all edges or an Object with per-edge counts |
|
||||||
|
| [extend.top] | <code>number</code> | <code>0</code> | |
|
||||||
|
| [extend.left] | <code>number</code> | <code>0</code> | |
|
||||||
|
| [extend.bottom] | <code>number</code> | <code>0</code> | |
|
||||||
|
| [extend.right] | <code>number</code> | <code>0</code> | |
|
||||||
|
| [extend.background] | <code>String</code> \| <code>Object</code> | <code>{r: 0, g: 0, b: 0, alpha: 1}</code> | background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
// Resize to 140 pixels wide, then add 10 transparent pixels
|
// Resize to 140 pixels wide, then add 10 transparent pixels
|
||||||
// to the top, left and right edges and 20 to the bottom edge
|
// to the top, left and right edges and 20 to the bottom edge
|
||||||
sharp(input)
|
sharp(input)
|
||||||
@ -182,8 +179,8 @@ sharp(input)
|
|||||||
})
|
})
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Add a row of 10 red pixels to the bottom
|
// Add a row of 10 red pixels to the bottom
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.extend({
|
.extend({
|
||||||
@ -193,38 +190,38 @@ sharp(input)
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][13]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## extract
|
## extract
|
||||||
|
|
||||||
Extract/crop a region of the image.
|
Extract/crop a region of the image.
|
||||||
|
|
||||||
* Use `extract` before `resize` for pre-resize extraction.
|
- Use `extract` before `resize` for pre-resize extraction.
|
||||||
* Use `extract` after `resize` for post-resize extraction.
|
- Use `extract` after `resize` for post-resize extraction.
|
||||||
* Use `extract` before and after for both.
|
- Use `extract` before and after for both.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **[Object][9]** describes the region to extract using integral pixel values
|
**Throws**:
|
||||||
|
|
||||||
* `options.left` **[number][8]** zero-indexed offset from left edge
|
- <code>Error</code> Invalid parameters
|
||||||
* `options.top` **[number][8]** zero-indexed offset from top edge
|
|
||||||
* `options.width` **[number][8]** width of region to extract
|
|
||||||
* `options.height` **[number][8]** height of region to extract
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| options | <code>Object</code> | describes the region to extract using integral pixel values |
|
||||||
|
| options.left | <code>number</code> | zero-indexed offset from left edge |
|
||||||
|
| options.top | <code>number</code> | zero-indexed offset from top edge |
|
||||||
|
| options.width | <code>number</code> | width of region to extract |
|
||||||
|
| options.height | <code>number</code> | height of region to extract |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.extract({ left: left, top: top, width: width, height: height })
|
.extract({ left: left, top: top, width: width, height: height })
|
||||||
.toFile(output, function(err) {
|
.toFile(output, function(err) {
|
||||||
// Extract a region of the input image, saving in the same format.
|
// Extract a region of the input image, saving in the same format.
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.extract({ left: leftOffsetPre, top: topOffsetPre, width: widthPre, height: heightPre })
|
.extract({ left: leftOffsetPre, top: topOffsetPre, width: widthPre, height: heightPre })
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
@ -234,12 +231,8 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][13]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
## trim
|
## trim
|
||||||
|
|
||||||
Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.
|
Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.
|
||||||
|
|
||||||
Images with an alpha channel will use the combined bounding box of alpha and non-alpha channels.
|
Images with an alpha channel will use the combined bounding box of alpha and non-alpha channels.
|
||||||
@ -249,16 +242,20 @@ If the result of this operation would trim an image to nothing then no change is
|
|||||||
The `info` response Object, obtained from callback of `.toFile()` or `.toBuffer()`,
|
The `info` response Object, obtained from callback of `.toFile()` or `.toBuffer()`,
|
||||||
will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `trim` **([string][10] | [number][8] | [Object][9])** the specific background colour to trim, the threshold for doing so or an Object with both.
|
**Throws**:
|
||||||
|
|
||||||
* `trim.background` **([string][10] | [Object][9])** background colour, parsed by the [color][11] module, defaults to that of the top-left pixel. (optional, default `'top-left pixel'`)
|
- <code>Error</code> Invalid parameters
|
||||||
* `trim.threshold` **[number][8]** the allowed difference from the above colour, a positive number. (optional, default `10`)
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
| Param | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| trim | <code>string</code> \| <code>number</code> \| <code>Object</code> | | the specific background colour to trim, the threshold for doing so or an Object with both. |
|
||||||
|
| [trim.background] | <code>string</code> \| <code>Object</code> | <code>"'top-left pixel'"</code> | background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to that of the top-left pixel. |
|
||||||
|
| [trim.threshold] | <code>number</code> | <code>10</code> | the allowed difference from the above colour, a positive number. |
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
// Trim pixels with a colour similar to that of the top-left pixel.
|
// Trim pixels with a colour similar to that of the top-left pixel.
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.trim()
|
.trim()
|
||||||
@ -266,8 +263,8 @@ sharp(input)
|
|||||||
...
|
...
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Trim pixels with the exact same colour as that of the top-left pixel.
|
// Trim pixels with the exact same colour as that of the top-left pixel.
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.trim(0)
|
.trim(0)
|
||||||
@ -275,8 +272,8 @@ sharp(input)
|
|||||||
...
|
...
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Trim only pixels with a similar colour to red.
|
// Trim only pixels with a similar colour to red.
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.trim("#FF0000")
|
.trim("#FF0000")
|
||||||
@ -284,8 +281,8 @@ sharp(input)
|
|||||||
...
|
...
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
// Trim all "yellow-ish" pixels, being more lenient with the higher threshold.
|
// Trim all "yellow-ish" pixels, being more lenient with the higher threshold.
|
||||||
sharp(input)
|
sharp(input)
|
||||||
.trim({
|
.trim({
|
||||||
@ -296,33 +293,3 @@ sharp(input)
|
|||||||
...
|
...
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
* Throws **[Error][13]** Invalid parameters
|
|
||||||
|
|
||||||
Returns **Sharp** 
|
|
||||||
|
|
||||||
[1]: https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit
|
|
||||||
|
|
||||||
[2]: https://developer.mozilla.org/en-US/docs/Web/CSS/object-position
|
|
||||||
|
|
||||||
[3]: https://en.wikipedia.org/wiki/Entropy_%28information_theory%29
|
|
||||||
|
|
||||||
[4]: http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation
|
|
||||||
|
|
||||||
[5]: https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline
|
|
||||||
|
|
||||||
[6]: https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf
|
|
||||||
|
|
||||||
[7]: https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel
|
|
||||||
|
|
||||||
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
||||||
|
|
||||||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
|
||||||
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
||||||
|
|
||||||
[11]: https://www.npmjs.org/package/color
|
|
||||||
|
|
||||||
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
||||||
|
|
||||||
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
||||||
|
@ -1,101 +1,96 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
||||||
|
|
||||||
## format
|
|
||||||
|
|
||||||
An Object containing nested boolean values representing the available input and output formats/methods.
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
console.log(sharp.format);
|
|
||||||
```
|
|
||||||
|
|
||||||
Returns **[Object][1]** 
|
|
||||||
|
|
||||||
## interpolators
|
|
||||||
|
|
||||||
An Object containing the available interpolators and their proper values
|
|
||||||
|
|
||||||
Type: [string][2]
|
|
||||||
|
|
||||||
### nearest
|
|
||||||
|
|
||||||
[Nearest neighbour interpolation][3]. Suitable for image enlargement only.
|
|
||||||
|
|
||||||
### bilinear
|
|
||||||
|
|
||||||
[Bilinear interpolation][4]. Faster than bicubic but with less smooth results.
|
|
||||||
|
|
||||||
### bicubic
|
|
||||||
|
|
||||||
[Bicubic interpolation][5] (the default).
|
|
||||||
|
|
||||||
### locallyBoundedBicubic
|
|
||||||
|
|
||||||
[LBB interpolation][6]. Prevents some "[acutance][7]" but typically reduces performance by a factor of 2.
|
|
||||||
|
|
||||||
### nohalo
|
|
||||||
|
|
||||||
[Nohalo interpolation][8]. Prevents acutance but typically reduces performance by a factor of 3.
|
|
||||||
|
|
||||||
### vertexSplitQuadraticBasisSpline
|
|
||||||
|
|
||||||
[VSQBS interpolation][9]. Prevents "staircasing" when enlarging.
|
|
||||||
|
|
||||||
## versions
|
## versions
|
||||||
|
|
||||||
An Object containing the version numbers of libvips and its dependencies.
|
An Object containing the version numbers of libvips and its dependencies.
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
**Example**
|
||||||
|
```js
|
||||||
console.log(sharp.versions);
|
console.log(sharp.versions);
|
||||||
```
|
```
|
||||||
|
|
||||||
## vendor
|
|
||||||
|
|
||||||
|
## interpolators
|
||||||
|
An Object containing the available interpolators and their proper values
|
||||||
|
|
||||||
|
|
||||||
|
**Read only**: true
|
||||||
|
**Properties**
|
||||||
|
|
||||||
|
| Name | Type | Default | Description |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| nearest | <code>string</code> | <code>"nearest"</code> | [Nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation). Suitable for image enlargement only. |
|
||||||
|
| bilinear | <code>string</code> | <code>"bilinear"</code> | [Bilinear interpolation](http://en.wikipedia.org/wiki/Bilinear_interpolation). Faster than bicubic but with less smooth results. |
|
||||||
|
| bicubic | <code>string</code> | <code>"bicubic"</code> | [Bicubic interpolation](http://en.wikipedia.org/wiki/Bicubic_interpolation) (the default). |
|
||||||
|
| locallyBoundedBicubic | <code>string</code> | <code>"lbb"</code> | [LBB interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/lbb.cpp#L100). Prevents some "[acutance](http://en.wikipedia.org/wiki/Acutance)" but typically reduces performance by a factor of 2. |
|
||||||
|
| nohalo | <code>string</code> | <code>"nohalo"</code> | [Nohalo interpolation](http://eprints.soton.ac.uk/268086/). Prevents acutance but typically reduces performance by a factor of 3. |
|
||||||
|
| vertexSplitQuadraticBasisSpline | <code>string</code> | <code>"vsqbs"</code> | [VSQBS interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/vsqbs.cpp#L48). Prevents "staircasing" when enlarging. |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## format
|
||||||
|
An Object containing nested boolean values representing the available input and output formats/methods.
|
||||||
|
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
|
console.log(sharp.format);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## vendor
|
||||||
An Object containing the platform and architecture
|
An Object containing the platform and architecture
|
||||||
of the current and installed vendored binaries.
|
of the current and installed vendored binaries.
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
**Example**
|
||||||
|
```js
|
||||||
console.log(sharp.vendor);
|
console.log(sharp.vendor);
|
||||||
```
|
```
|
||||||
|
|
||||||
## cache
|
|
||||||
|
|
||||||
Gets or, when options are provided, sets the limits of *libvips'* operation cache.
|
## queue
|
||||||
|
An EventEmitter that emits a `change` event when a task is either:
|
||||||
|
- queued, waiting for _libuv_ to provide a worker thread
|
||||||
|
- complete
|
||||||
|
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
```js
|
||||||
|
sharp.queue.on('change', function(queueLength) {
|
||||||
|
console.log('Queue contains ' + queueLength + ' task(s)');
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## cache
|
||||||
|
Gets or, when options are provided, sets the limits of _libvips'_ operation cache.
|
||||||
Existing entries in the cache will be trimmed after any change in limits.
|
Existing entries in the cache will be trimmed after any change in limits.
|
||||||
This method always returns cache statistics,
|
This method always returns cache statistics,
|
||||||
useful for determining how much working memory is required for a particular task.
|
useful for determining how much working memory is required for a particular task.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `options` **([Object][1] | [boolean][10])** Object with the following attributes, or boolean where true uses default cache settings and false removes all caching (optional, default `true`)
|
|
||||||
|
|
||||||
* `options.memory` **[number][11]** is the maximum memory in MB to use for this cache (optional, default `50`)
|
| Param | Type | Default | Description |
|
||||||
* `options.files` **[number][11]** is the maximum number of files to hold open (optional, default `20`)
|
| --- | --- | --- | --- |
|
||||||
* `options.items` **[number][11]** is the maximum number of operations to cache (optional, default `100`)
|
| [options] | <code>Object</code> \| <code>boolean</code> | <code>true</code> | Object with the following attributes, or boolean where true uses default cache settings and false removes all caching |
|
||||||
|
| [options.memory] | <code>number</code> | <code>50</code> | is the maximum memory in MB to use for this cache |
|
||||||
|
| [options.files] | <code>number</code> | <code>20</code> | is the maximum number of files to hold open |
|
||||||
|
| [options.items] | <code>number</code> | <code>100</code> | is the maximum number of operations to cache |
|
||||||
|
|
||||||
### Examples
|
**Example**
|
||||||
|
```js
|
||||||
```javascript
|
|
||||||
const stats = sharp.cache();
|
const stats = sharp.cache();
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
sharp.cache( { items: 200 } );
|
sharp.cache( { items: 200 } );
|
||||||
sharp.cache( { files: 0 } );
|
sharp.cache( { files: 0 } );
|
||||||
sharp.cache(false);
|
sharp.cache(false);
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Object][1]** 
|
|
||||||
|
|
||||||
## concurrency
|
## concurrency
|
||||||
|
|
||||||
Gets or, when a concurrency is provided, sets
|
Gets or, when a concurrency is provided, sets
|
||||||
the maximum number of threads *libvips* should use to process *each image*.
|
the maximum number of threads _libvips_ should use to process _each image_.
|
||||||
These are from a thread pool managed by glib,
|
These are from a thread pool managed by glib,
|
||||||
which helps avoid the overhead of creating new threads.
|
which helps avoid the overhead of creating new threads.
|
||||||
|
|
||||||
@ -115,102 +110,59 @@ The maximum number of images that sharp can process in parallel
|
|||||||
is controlled by libuv's `UV_THREADPOOL_SIZE` environment variable,
|
is controlled by libuv's `UV_THREADPOOL_SIZE` environment variable,
|
||||||
which defaults to 4.
|
which defaults to 4.
|
||||||
|
|
||||||
[https://nodejs.org/api/cli.html#uv\_threadpool\_sizesize][12]
|
https://nodejs.org/api/cli.html#uv_threadpool_sizesize
|
||||||
|
|
||||||
For example, by default, a machine with 8 CPU cores will process
|
For example, by default, a machine with 8 CPU cores will process
|
||||||
4 images in parallel and use up to 8 threads per image,
|
4 images in parallel and use up to 8 threads per image,
|
||||||
so there will be up to 32 concurrent threads.
|
so there will be up to 32 concurrent threads.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `concurrency` **[number][11]?** 
|
**Returns**: <code>number</code> - concurrency
|
||||||
|
|
||||||
### Examples
|
| Param | Type |
|
||||||
|
| --- | --- |
|
||||||
|
| [concurrency] | <code>number</code> |
|
||||||
|
|
||||||
```javascript
|
**Example**
|
||||||
|
```js
|
||||||
const threads = sharp.concurrency(); // 4
|
const threads = sharp.concurrency(); // 4
|
||||||
sharp.concurrency(2); // 2
|
sharp.concurrency(2); // 2
|
||||||
sharp.concurrency(0); // 4
|
sharp.concurrency(0); // 4
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[number][11]** concurrency
|
|
||||||
|
|
||||||
## queue
|
|
||||||
|
|
||||||
An EventEmitter that emits a `change` event when a task is either:
|
|
||||||
|
|
||||||
* queued, waiting for *libuv* to provide a worker thread
|
|
||||||
* complete
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
sharp.queue.on('change', function(queueLength) {
|
|
||||||
console.log('Queue contains ' + queueLength + ' task(s)');
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## counters
|
## counters
|
||||||
|
|
||||||
Provides access to internal task counters.
|
Provides access to internal task counters.
|
||||||
|
- queue is the number of tasks this module has queued waiting for _libuv_ to provide a worker thread from its pool.
|
||||||
|
- process is the number of resize tasks currently being processed.
|
||||||
|
|
||||||
* queue is the number of tasks this module has queued waiting for *libuv* to provide a worker thread from its pool.
|
|
||||||
* process is the number of resize tasks currently being processed.
|
|
||||||
|
|
||||||
### Examples
|
**Example**
|
||||||
|
```js
|
||||||
```javascript
|
|
||||||
const counters = sharp.counters(); // { queue: 2, process: 4 }
|
const counters = sharp.counters(); // { queue: 2, process: 4 }
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Object][1]** 
|
|
||||||
|
|
||||||
## simd
|
## simd
|
||||||
|
|
||||||
Get and set use of SIMD vector unit instructions.
|
Get and set use of SIMD vector unit instructions.
|
||||||
Requires libvips to have been compiled with liborc support.
|
Requires libvips to have been compiled with liborc support.
|
||||||
|
|
||||||
Improves the performance of `resize`, `blur` and `sharpen` operations
|
Improves the performance of `resize`, `blur` and `sharpen` operations
|
||||||
by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
|
by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
* `simd` **[boolean][10]** (optional, default `true`)
|
|
||||||
|
|
||||||
### Examples
|
| Param | Type | Default |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| [simd] | <code>boolean</code> | <code>true</code> |
|
||||||
|
|
||||||
```javascript
|
**Example**
|
||||||
|
```js
|
||||||
const simd = sharp.simd();
|
const simd = sharp.simd();
|
||||||
// simd is `true` if the runtime use of liborc is currently enabled
|
// simd is `true` if the runtime use of liborc is currently enabled
|
||||||
```
|
```
|
||||||
|
**Example**
|
||||||
```javascript
|
```js
|
||||||
const simd = sharp.simd(false);
|
const simd = sharp.simd(false);
|
||||||
// prevent libvips from using liborc at runtime
|
// prevent libvips from using liborc at runtime
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[boolean][10]** 
|
|
||||||
|
|
||||||
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
|
||||||
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
||||||
|
|
||||||
[3]: http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation
|
|
||||||
|
|
||||||
[4]: http://en.wikipedia.org/wiki/Bilinear_interpolation
|
|
||||||
|
|
||||||
[5]: http://en.wikipedia.org/wiki/Bicubic_interpolation
|
|
||||||
|
|
||||||
[6]: https://github.com/libvips/libvips/blob/master/libvips/resample/lbb.cpp#L100
|
|
||||||
|
|
||||||
[7]: http://en.wikipedia.org/wiki/Acutance
|
|
||||||
|
|
||||||
[8]: http://eprints.soton.ac.uk/268086/
|
|
||||||
|
|
||||||
[9]: https://github.com/libvips/libvips/blob/master/libvips/resample/vsqbs.cpp#L48
|
|
||||||
|
|
||||||
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
||||||
|
|
||||||
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
||||||
|
|
||||||
[12]: https://nodejs.org/api/cli.html#uv_threadpool_sizesize
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const fs = require('fs').promises;
|
const fs = require('fs').promises;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const jsdoc2md = require('jsdoc-to-markdown');
|
||||||
|
|
||||||
[
|
[
|
||||||
'constructor',
|
'constructor',
|
||||||
@ -14,13 +15,21 @@ const path = require('path');
|
|||||||
'output',
|
'output',
|
||||||
'utility'
|
'utility'
|
||||||
].forEach(async (m) => {
|
].forEach(async (m) => {
|
||||||
const documentation = await import('documentation');
|
|
||||||
|
|
||||||
const input = path.join('lib', `${m}.js`);
|
const input = path.join('lib', `${m}.js`);
|
||||||
const output = path.join('docs', `api-${m}.md`);
|
const output = path.join('docs', `api-${m}.md`);
|
||||||
|
|
||||||
const ast = await documentation.build(input, { shallow: true });
|
const ast = await jsdoc2md.getTemplateData({ files: input });
|
||||||
const markdown = await documentation.formats.md(ast, { markdownToc: false });
|
const markdown = await jsdoc2md.render({
|
||||||
|
data: ast,
|
||||||
await fs.writeFile(output, markdown);
|
'global-index-format': 'none',
|
||||||
|
'module-index-format': 'none'
|
||||||
|
});
|
||||||
|
|
||||||
|
const cleanMarkdown = markdown
|
||||||
|
.replace(/(## [A-Za-z]+)[^\n]*/g, '$1') // simplify headings to match those of documentationjs, ensures existing URLs work
|
||||||
|
.replace(/<a name="[A-Za-z+]+"><\/a>/g, '') // remove anchors, let docute add these (at markdown to HTML render time)
|
||||||
|
.replace(/\*\*Kind\*\*: global[^\n]+/g, '') // remove all "global" Kind labels (requires JSDoc refactoring)
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
await fs.writeFile(output, cleanMarkdown);
|
||||||
});
|
});
|
||||||
|
@ -77,9 +77,7 @@
|
|||||||
.map(function (sidebarLink) {
|
.map(function (sidebarLink) {
|
||||||
return sidebarLink.title;
|
return sidebarLink.title;
|
||||||
})[0];
|
})[0];
|
||||||
return title
|
return title ? `# ${title}\n${md}` : md;
|
||||||
? md.replace(/<!-- Generated by documentation.js. Update this documentation by updating the source code. -->/, '# ' + title)
|
|
||||||
: md;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
File diff suppressed because one or more lines are too long
@ -95,7 +95,7 @@
|
|||||||
"test-unit": "nyc --reporter=lcov --reporter=text --check-coverage --branches=100 mocha",
|
"test-unit": "nyc --reporter=lcov --reporter=text --check-coverage --branches=100 mocha",
|
||||||
"test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;MIT\"",
|
"test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;MIT\"",
|
||||||
"test-leak": "./test/leak/leak.sh",
|
"test-leak": "./test/leak/leak.sh",
|
||||||
"docs-build": "documentation lint lib && node docs/build && node docs/search-index/build",
|
"docs-build": "node docs/build && node docs/search-index/build",
|
||||||
"docs-serve": "cd docs && npx serve",
|
"docs-serve": "cd docs && npx serve",
|
||||||
"docs-publish": "cd docs && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
|
"docs-publish": "cd docs && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
|
||||||
},
|
},
|
||||||
@ -141,10 +141,10 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^3.2.4",
|
"async": "^3.2.4",
|
||||||
"cc": "^3.0.1",
|
"cc": "^3.0.1",
|
||||||
"documentation": "^14.0.1",
|
|
||||||
"exif-reader": "^1.1.0",
|
"exif-reader": "^1.1.0",
|
||||||
"extract-zip": "^2.0.1",
|
"extract-zip": "^2.0.1",
|
||||||
"icc": "^2.0.0",
|
"icc": "^2.0.0",
|
||||||
|
"jsdoc-to-markdown": "^8.0.0",
|
||||||
"license-checker": "^25.0.1",
|
"license-checker": "^25.0.1",
|
||||||
"mocha": "^10.2.0",
|
"mocha": "^10.2.0",
|
||||||
"mock-fs": "^5.2.0",
|
"mock-fs": "^5.2.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user