Documentation refresh

This commit is contained in:
Lovell Fuller 2018-06-20 08:14:03 +01:00
parent 94607b585a
commit 0d9590a9a0
11 changed files with 683 additions and 440 deletions

View File

@ -3,18 +3,23 @@
### Table of Contents ### Table of Contents
- [extractChannel][1] - [extractChannel][1]
- [joinChannel][2] - [Parameters][2]
- [bandbool][3] - [Examples][3]
- [joinChannel][4]
- [Parameters][5]
- [bandbool][6]
- [Parameters][7]
- [Examples][8]
## extractChannel ## extractChannel
Extract a single channel from a multi-channel image. Extract a single channel from a multi-channel image.
**Parameters** ### Parameters
- `channel` **([Number][4] \| [String][5])** zero-indexed band number to extract, or `red`, `green` or `blue` as alternative to `0`, `1` or `2` respectively. - `channel` **([Number][9] \| [String][10])** zero-indexed band number to extract, or `red`, `green` or `blue` as alternative to `0`, `1` or `2` respectively.
**Examples** ### Examples
```javascript ```javascript
sharp(input) sharp(input)
@ -25,7 +30,7 @@ sharp(input)
}); });
``` ```
- Throws **[Error][6]** Invalid channel - Throws **[Error][11]** Invalid channel
Returns **Sharp** Returns **Sharp**
@ -42,13 +47,13 @@ Channel ordering follows vips convention:
Buffers may be any of the image formats supported by sharp: JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data. Buffers may be any of the image formats supported by sharp: JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data.
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** ### Parameters
- `images` **([Array][7]<([String][5] \| [Buffer][8])> | [String][5] \| [Buffer][8])** one or more images (file paths, Buffers). - `images` **([Array][12]<([String][10] \| [Buffer][13])> | [String][10] \| [Buffer][13])** one or more images (file paths, Buffers).
- `options` **[Object][9]** image options, see `sharp()` constructor. - `options` **[Object][14]** image options, see `sharp()` constructor.
- Throws **[Error][6]** Invalid parameters - Throws **[Error][11]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -56,11 +61,11 @@ Returns **Sharp**
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** ### Parameters
- `boolOp` **[String][5]** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively. - `boolOp` **[String][10]** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
**Examples** ### Examples
```javascript ```javascript
sharp('3-channel-rgb-input.png') sharp('3-channel-rgb-input.png')
@ -72,24 +77,34 @@ sharp('3-channel-rgb-input.png')
}); });
``` ```
- Throws **[Error][6]** Invalid parameters - Throws **[Error][11]** Invalid parameters
Returns **Sharp** Returns **Sharp**
[1]: #extractchannel [1]: #extractchannel
[2]: #joinchannel [2]: #parameters
[3]: #bandbool [3]: #examples
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number [4]: #joinchannel
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String [5]: #parameters-1
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error [6]: #bandbool
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array [7]: #parameters-2
[8]: https://nodejs.org/api/buffer.html [8]: #examples-1
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[13]: https://nodejs.org/api/buffer.html
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

View File

@ -3,11 +3,17 @@
### Table of Contents ### Table of Contents
- [background][1] - [background][1]
- [tint][2] - [Parameters][2]
- [greyscale][3] - [tint][3]
- [grayscale][4] - [Parameters][4]
- [toColourspace][5] - [greyscale][5]
- [toColorspace][6] - [Parameters][6]
- [grayscale][7]
- [Parameters][8]
- [toColourspace][9]
- [Parameters][10]
- [toColorspace][11]
- [Parameters][12]
## background ## background
@ -18,12 +24,12 @@ Delegates to the _color_ module, which can throw an Error
but is liberal in what it accepts, clipping values to sensible min/max. but is liberal in what it accepts, clipping values to sensible min/max.
The alpha value is a float between `0` (transparent) and `1` (opaque). The alpha value is a float between `0` (transparent) and `1` (opaque).
**Parameters** ### Parameters
- `rgba` **([String][7] \| [Object][8])** parsed by the [color][9] module to extract values for red, green, blue and alpha. - `rgba` **([String][13] \| [Object][14])** parsed by the [color][15] module to extract values for red, green, blue and alpha.
- Throws **[Error][10]** Invalid parameter - Throws **[Error][16]** Invalid parameter
Returns **Sharp** Returns **Sharp**
@ -32,12 +38,12 @@ Returns **Sharp**
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** ### Parameters
- `rgb` **([String][7] \| [Object][8])** parsed by the [color][9] module to extract chroma values. - `rgb` **([String][13] \| [Object][14])** parsed by the [color][15] module to extract chroma values.
- Throws **[Error][10]** Invalid parameter - Throws **[Error][16]** Invalid parameter
Returns **Sharp** Returns **Sharp**
@ -50,9 +56,9 @@ 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** ### Parameters
- `greyscale` **[Boolean][11]** (optional, default `true`) - `greyscale` **[Boolean][17]** (optional, default `true`)
Returns **Sharp** Returns **Sharp**
@ -60,9 +66,9 @@ Returns **Sharp**
Alternative spelling of `greyscale`. Alternative spelling of `greyscale`.
**Parameters** ### Parameters
- `grayscale` **[Boolean][11]** (optional, default `true`) - `grayscale` **[Boolean][17]** (optional, default `true`)
Returns **Sharp** Returns **Sharp**
@ -71,12 +77,12 @@ Returns **Sharp**
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** ### Parameters
- `colourspace` **[String][7]?** output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][12] - `colourspace` **[String][13]?** output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][18]
- Throws **[Error][10]** Invalid parameters - Throws **[Error][16]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -84,35 +90,47 @@ Returns **Sharp**
Alternative spelling of `toColourspace`. Alternative spelling of `toColourspace`.
**Parameters** ### Parameters
- `colorspace` **[String][7]?** output colorspace. - `colorspace` **[String][13]?** output colorspace.
- Throws **[Error][10]** Invalid parameters - Throws **[Error][16]** Invalid parameters
Returns **Sharp** Returns **Sharp**
[1]: #background [1]: #background
[2]: #tint [2]: #parameters
[3]: #greyscale [3]: #tint
[4]: #grayscale [4]: #parameters-1
[5]: #tocolourspace [5]: #greyscale
[6]: #tocolorspace [6]: #parameters-2
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String [7]: #grayscale
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [8]: #parameters-3
[9]: https://www.npmjs.org/package/color [9]: #tocolourspace
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error [10]: #parameters-4
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean [11]: #tocolorspace
[12]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L568 [12]: #parameters-5
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[15]: https://www.npmjs.org/package/color
[16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
[17]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[18]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L568

View File

@ -3,6 +3,8 @@
### Table of Contents ### Table of Contents
- [overlayWith][1] - [overlayWith][1]
- [Parameters][2]
- [Examples][3]
## overlayWith ## overlayWith
@ -13,27 +15,27 @@ If both `top` and `left` options are provided, they take precedence over `gravit
If the overlay image contains an alpha channel then composition with premultiplication will occur. If the overlay image contains an alpha channel then composition with premultiplication will occur.
**Parameters** ### Parameters
- `overlay` **([Buffer][2] \| [String][3])** Buffer containing image data or String containing the path to an image file. - `overlay` **([Buffer][4] \| [String][5])** Buffer containing image data or String containing the path to an image file.
- `options` **[Object][4]?** - `options` **[Object][6]?**
- `options.gravity` **[String][3]** gravity at which to place the overlay. (optional, default `'centre'`) - `options.gravity` **[String][5]** gravity at which to place the overlay. (optional, default `'centre'`)
- `options.top` **[Number][5]?** the pixel offset from the top edge. - `options.top` **[Number][7]?** the pixel offset from the top edge.
- `options.left` **[Number][5]?** the pixel offset from the left edge. - `options.left` **[Number][7]?** the pixel offset from the left edge.
- `options.tile` **[Boolean][6]** set to true to repeat the overlay image across the entire image with the given `gravity`. (optional, default `false`) - `options.tile` **[Boolean][8]** set to true to repeat the overlay image across the entire image with the given `gravity`. (optional, default `false`)
- `options.cutout` **[Boolean][6]** set to true to apply only the alpha channel of the overlay image to the input image, giving the appearance of one image being cut out of another. (optional, default `false`) - `options.cutout` **[Boolean][8]** set to true to apply only the alpha channel of the overlay image to the input image, giving the appearance of one image being cut out of another. (optional, default `false`)
- `options.density` **[Number][5]** integral number representing the DPI for vector overlay image. (optional, default `72`) - `options.density` **[Number][7]** integral number representing the DPI for vector overlay image. (optional, default `72`)
- `options.raw` **[Object][4]?** describes overlay when using raw pixel data. - `options.raw` **[Object][6]?** describes overlay when using raw pixel data.
- `options.raw.width` **[Number][5]?** - `options.raw.width` **[Number][7]?**
- `options.raw.height` **[Number][5]?** - `options.raw.height` **[Number][7]?**
- `options.raw.channels` **[Number][5]?** - `options.raw.channels` **[Number][7]?**
- `options.create` **[Object][4]?** describes a blank overlay to be created. - `options.create` **[Object][6]?** describes a blank overlay to be created.
- `options.create.width` **[Number][5]?** - `options.create.width` **[Number][7]?**
- `options.create.height` **[Number][5]?** - `options.create.height` **[Number][7]?**
- `options.create.channels` **[Number][5]?** 3-4 - `options.create.channels` **[Number][7]?** 3-4
- `options.create.background` **([String][3] \| [Object][4])?** parsed by the [color][7] module to extract values for red, green, blue and alpha. - `options.create.background` **([String][5] \| [Object][6])?** parsed by the [color][9] module to extract values for red, green, blue and alpha.
**Examples** ### Examples
```javascript ```javascript
sharp('input.png') sharp('input.png')
@ -54,22 +56,26 @@ sharp('input.png')
}); });
``` ```
- Throws **[Error][8]** Invalid parameters - Throws **[Error][10]** Invalid parameters
Returns **Sharp** Returns **Sharp**
[1]: #overlaywith [1]: #overlaywith
[2]: https://nodejs.org/api/buffer.html [2]: #parameters
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String [3]: #examples
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [4]: https://nodejs.org/api/buffer.html
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[7]: https://www.npmjs.org/package/color [7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error [8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[9]: https://www.npmjs.org/package/color
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error

View File

@ -3,35 +3,40 @@
### Table of Contents ### Table of Contents
- [Sharp][1] - [Sharp][1]
- [format][2] - [Parameters][2]
- [versions][3] - [Examples][3]
- [queue][4] - [format][4]
- [Examples][5]
- [versions][6]
- [Examples][7]
- [queue][8]
- [Examples][9]
## Sharp ## Sharp
**Parameters** ### Parameters
- `input` **([Buffer][5] \| [String][6])?** if present, can be - `input` **([Buffer][10] \| [String][11])?** if present, can be
a Buffer containing JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data, or a Buffer containing JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data, or
a String containing the path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file. a String containing the path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present. JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
- `options` **[Object][7]?** if present, is an Object with optional attributes. - `options` **[Object][12]?** if present, is an Object with optional attributes.
- `options.failOnError` **[Boolean][8]** by default apply a "best effort" - `options.failOnError` **[Boolean][13]** by default apply a "best effort"
to decode images, even if the data is corrupt or invalid. Set this flag to true to decode images, even if the data is corrupt or invalid. Set this flag to true
if you'd rather halt processing and raise an error when loading invalid images. (optional, default `false`) if you'd rather halt processing and raise an error when loading invalid images. (optional, default `false`)
- `options.density` **[Number][9]** integral number representing the DPI for vector images. (optional, default `72`) - `options.density` **[Number][14]** integral number representing the DPI for vector images. (optional, default `72`)
- `options.page` **[Number][9]** page number to extract for multi-page input (GIF, TIFF) (optional, default `0`) - `options.page` **[Number][14]** page number to extract for multi-page input (GIF, TIFF) (optional, default `0`)
- `options.raw` **[Object][7]?** describes raw pixel input image data. See `raw()` for pixel ordering. - `options.raw` **[Object][12]?** describes raw pixel input image data. See `raw()` for pixel ordering.
- `options.raw.width` **[Number][9]?** - `options.raw.width` **[Number][14]?**
- `options.raw.height` **[Number][9]?** - `options.raw.height` **[Number][14]?**
- `options.raw.channels` **[Number][9]?** 1-4 - `options.raw.channels` **[Number][14]?** 1-4
- `options.create` **[Object][7]?** describes a new image to be created. - `options.create` **[Object][12]?** describes a new image to be created.
- `options.create.width` **[Number][9]?** - `options.create.width` **[Number][14]?**
- `options.create.height` **[Number][9]?** - `options.create.height` **[Number][14]?**
- `options.create.channels` **[Number][9]?** 3-4 - `options.create.channels` **[Number][14]?** 3-4
- `options.create.background` **([String][6] \| [Object][7])?** parsed by the [color][10] module to extract values for red, green, blue and alpha. - `options.create.background` **([String][11] \| [Object][12])?** parsed by the [color][15] module to extract values for red, green, blue and alpha.
**Examples** ### Examples
```javascript ```javascript
sharp('input.jpg') sharp('input.jpg')
@ -70,27 +75,27 @@ sharp({
.then( ... ); .then( ... );
``` ```
- Throws **[Error][11]** Invalid parameters - Throws **[Error][16]** Invalid parameters
Returns **[Sharp][12]** Returns **[Sharp][17]**
### format ### format
An Object containing nested boolean values representing the available input and output formats/methods. An Object containing nested boolean values representing the available input and output formats/methods.
**Examples** #### Examples
```javascript ```javascript
console.log(sharp.format); console.log(sharp.format);
``` ```
Returns **[Object][7]** Returns **[Object][12]**
### 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** #### Examples
```javascript ```javascript
console.log(sharp.versions); console.log(sharp.versions);
@ -103,7 +108,7 @@ An EventEmitter that emits a `change` event when a task is either:
- queued, waiting for _libuv_ to provide a worker thread - queued, waiting for _libuv_ to provide a worker thread
- complete - complete
**Examples** ### Examples
```javascript ```javascript
sharp.queue.on('change', function(queueLength) { sharp.queue.on('change', function(queueLength) {
@ -113,24 +118,34 @@ sharp.queue.on('change', function(queueLength) {
[1]: #sharp [1]: #sharp
[2]: #format [2]: #parameters
[3]: #versions [3]: #examples
[4]: #queue [4]: #format
[5]: https://nodejs.org/api/buffer.html [5]: #examples-1
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String [6]: #versions
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [7]: #examples-2
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean [8]: #queue
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number [9]: #examples-3
[10]: https://www.npmjs.org/package/color [10]: https://nodejs.org/api/buffer.html
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error [11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[12]: #sharp [12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[15]: https://www.npmjs.org/package/color
[16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
[17]: #sharp

View File

@ -3,10 +3,17 @@
### Table of Contents ### Table of Contents
- [clone][1] - [clone][1]
- [metadata][2] - [Examples][2]
- [stats][3] - [metadata][3]
- [limitInputPixels][4] - [Parameters][4]
- [sequentialRead][5] - [Examples][5]
- [stats][6]
- [Parameters][7]
- [Examples][8]
- [limitInputPixels][9]
- [Parameters][10]
- [sequentialRead][11]
- [Parameters][12]
## clone ## clone
@ -14,7 +21,7 @@ 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** ### Examples
```javascript ```javascript
const pipeline = sharp().rotate(); const pipeline = sharp().rotate();
@ -35,23 +42,23 @@ A Promises/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`
- `width`: Number of pixels wide (EXIF orientation is not taken into consideration) - `width`: Number of pixels wide (EXIF orientation is not taken into consideration)
- `height`: Number of pixels high (EXIF orientation is not taken into consideration) - `height`: Number of pixels high (EXIF orientation is not taken into consideration)
- `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][6] - `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][13]
- `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` [...][7] - `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...][14]
- `density`: Number of pixels per inch (DPI), if present - `density`: Number of pixels per inch (DPI), 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][8] profile data, if present - `icc`: Buffer containing raw [ICC][15] 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
**Parameters** ### Parameters
- `callback` **[Function][9]?** called with the arguments `(err, metadata)` - `callback` **[Function][16]?** called with the arguments `(err, metadata)`
**Examples** ### Examples
```javascript ```javascript
const image = sharp(inputJpg); const image = sharp(inputJpg);
@ -68,7 +75,7 @@ image
}); });
``` ```
Returns **([Promise][10]<[Object][11]> | Sharp)** Returns **([Promise][17]<[Object][18]> | Sharp)**
## stats ## stats
@ -88,11 +95,11 @@ A Promise is returned when `callback` is not provided.
- `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`: Value to identify if the image is opaque or transparent, based on the presence and use of alpha channel - `isOpaque`: Value to identify if the image is opaque or transparent, based on the presence and use of alpha channel
**Parameters** ### Parameters
- `callback` **[Function][9]?** called with the arguments `(err, stats)` - `callback` **[Function][16]?** called with the arguments `(err, stats)`
**Examples** ### Examples
```javascript ```javascript
const image = sharp(inputJpg); const image = sharp(inputJpg);
@ -103,7 +110,7 @@ image
}); });
``` ```
Returns **[Promise][10]<[Object][11]>** Returns **[Promise][17]<[Object][18]>**
## limitInputPixels ## limitInputPixels
@ -111,12 +118,12 @@ Do not process input images where the number of pixels (width _ height) exceeds
Assumes image dimensions contained in the input metadata can be trusted. Assumes image dimensions contained in the input metadata can be trusted.
The default limit is 268402689 (0x3FFF _ 0x3FFF) pixels. The default limit is 268402689 (0x3FFF _ 0x3FFF) pixels.
**Parameters** ### Parameters
- `limit` **([Number][12] \| [Boolean][13])** an integral Number of pixels, zero or false to remove limit, true to use default limit. - `limit` **([Number][19] \| [Boolean][20])** an integral Number of pixels, zero or false to remove limit, true to use default limit.
- Throws **[Error][14]** Invalid limit - Throws **[Error][21]** Invalid limit
Returns **Sharp** Returns **Sharp**
@ -127,36 +134,50 @@ This will reduce memory usage and can improve performance on some systems.
The default behaviour _before_ function call is `false`, meaning the libvips access method is not sequential. The default behaviour _before_ function call is `false`, meaning the libvips access method is not sequential.
**Parameters** ### Parameters
- `sequentialRead` **[Boolean][13]** (optional, default `true`) - `sequentialRead` **[Boolean][20]** (optional, default `true`)
Returns **Sharp** Returns **Sharp**
[1]: #clone [1]: #clone
[2]: #metadata [2]: #examples
[3]: #stats [3]: #metadata
[4]: #limitinputpixels [4]: #parameters
[5]: #sequentialread [5]: #examples-1
[6]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L636 [6]: #stats
[7]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L672 [7]: #parameters-1
[8]: https://www.npmjs.com/package/icc [8]: #examples-2
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function [9]: #limitinputpixels
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise [10]: #parameters-2
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [11]: #sequentialread
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number [12]: #parameters-3
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean [13]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L636
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error [14]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L672
[15]: https://www.npmjs.com/package/icc
[16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
[17]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
[18]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[19]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[20]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[21]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error

View File

@ -3,23 +3,45 @@
### Table of Contents ### Table of Contents
- [rotate][1] - [rotate][1]
- [extract][2] - [Parameters][2]
- [flip][3] - [Examples][3]
- [flop][4] - [extract][4]
- [sharpen][5] - [Parameters][5]
- [median][6] - [Examples][6]
- [blur][7] - [flip][7]
- [extend][8] - [Parameters][8]
- [flatten][9] - [flop][9]
- [trim][10] - [Parameters][10]
- [gamma][11] - [sharpen][11]
- [negate][12] - [Parameters][12]
- [normalise][13] - [median][13]
- [normalize][14] - [Parameters][14]
- [convolve][15] - [blur][15]
- [threshold][16] - [Parameters][16]
- [boolean][17] - [extend][17]
- [linear][18] - [Parameters][18]
- [Examples][19]
- [flatten][20]
- [Parameters][21]
- [trim][22]
- [Parameters][23]
- [gamma][24]
- [Parameters][25]
- [negate][26]
- [Parameters][27]
- [normalise][28]
- [Parameters][29]
- [normalize][30]
- [Parameters][31]
- [convolve][32]
- [Parameters][33]
- [Examples][34]
- [threshold][35]
- [Parameters][36]
- [boolean][37]
- [Parameters][38]
- [linear][39]
- [Parameters][40]
## rotate ## rotate
@ -37,11 +59,11 @@ The use of `rotate` implies the removal of the EXIF `Orientation` tag, if any.
Method order is important when both rotating and extracting regions, Method order is important when both rotating and 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** ### Parameters
- `angle` **[Number][19]** angle of rotation, must be a multiple of 90. (optional, default `auto`) - `angle` **[Number][41]** angle of rotation, must be a multiple of 90. (optional, default `auto`)
**Examples** ### Examples
```javascript ```javascript
const pipeline = sharp() const pipeline = sharp()
@ -55,7 +77,7 @@ const pipeline = sharp()
readableStream.pipe(pipeline); readableStream.pipe(pipeline);
``` ```
- Throws **[Error][20]** Invalid parameters - Throws **[Error][42]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -67,15 +89,15 @@ Extract a region of the image.
- 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** ### Parameters
- `options` **[Object][21]** - `options` **[Object][43]**
- `options.left` **[Number][19]** zero-indexed offset from left edge - `options.left` **[Number][41]** zero-indexed offset from left edge
- `options.top` **[Number][19]** zero-indexed offset from top edge - `options.top` **[Number][41]** zero-indexed offset from top edge
- `options.width` **[Number][19]** dimension of extracted image - `options.width` **[Number][41]** dimension of extracted image
- `options.height` **[Number][19]** dimension of extracted image - `options.height` **[Number][41]** dimension of extracted image
**Examples** ### Examples
```javascript ```javascript
sharp(input) sharp(input)
@ -95,7 +117,7 @@ sharp(input)
}); });
``` ```
- Throws **[Error][20]** Invalid parameters - Throws **[Error][42]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -104,9 +126,9 @@ Returns **Sharp**
Flip the image about the vertical Y axis. This always occurs after rotation, if any. Flip the image about the vertical Y axis. This always occurs after 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** ### Parameters
- `flip` **[Boolean][22]** (optional, default `true`) - `flip` **[Boolean][44]** (optional, default `true`)
Returns **Sharp** Returns **Sharp**
@ -115,9 +137,9 @@ Returns **Sharp**
Flop the image about the horizontal X axis. This always occurs after rotation, if any. Flop the image about the horizontal X axis. This always occurs after 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** ### Parameters
- `flop` **[Boolean][22]** (optional, default `true`) - `flop` **[Boolean][44]** (optional, default `true`)
Returns **Sharp** Returns **Sharp**
@ -128,14 +150,14 @@ 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.
Separate control over the level of sharpening in "flat" and "jagged" areas is available. Separate control over the level of sharpening in "flat" and "jagged" areas is available.
**Parameters** ### Parameters
- `sigma` **[Number][19]?** the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`. - `sigma` **[Number][41]?** the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
- `flat` **[Number][19]** the level of sharpening to apply to "flat" areas. (optional, default `1.0`) - `flat` **[Number][41]** the level of sharpening to apply to "flat" areas. (optional, default `1.0`)
- `jagged` **[Number][19]** the level of sharpening to apply to "jagged" areas. (optional, default `2.0`) - `jagged` **[Number][41]** the level of sharpening to apply to "jagged" areas. (optional, default `2.0`)
- Throws **[Error][20]** Invalid parameters - Throws **[Error][42]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -144,12 +166,12 @@ Returns **Sharp**
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** ### Parameters
- `size` **[Number][19]** square mask size: size x size (optional, default `3`) - `size` **[Number][41]** square mask size: size x size (optional, default `3`)
- Throws **[Error][20]** Invalid parameters - Throws **[Error][42]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -159,12 +181,12 @@ Blur the image.
When used without parameters, performs a fast, mild blur of the output image. When used without parameters, performs a fast, mild blur of the output image.
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** ### Parameters
- `sigma` **[Number][19]?** a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`. - `sigma` **[Number][41]?** a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
- Throws **[Error][20]** Invalid parameters - Throws **[Error][42]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -173,15 +195,15 @@ Returns **Sharp**
Extends/pads the edges of the image with the colour provided to the `background` method. Extends/pads the edges of the image with the colour provided to the `background` method.
This operation will always occur after resizing and extraction, if any. This operation will always occur after resizing and extraction, if any.
**Parameters** ### Parameters
- `extend` **([Number][19] \| [Object][21])** single pixel count to add to all edges or an Object with per-edge counts - `extend` **([Number][41] \| [Object][43])** single pixel count to add to all edges or an Object with per-edge counts
- `extend.top` **[Number][19]?** - `extend.top` **[Number][41]?**
- `extend.left` **[Number][19]?** - `extend.left` **[Number][41]?**
- `extend.bottom` **[Number][19]?** - `extend.bottom` **[Number][41]?**
- `extend.right` **[Number][19]?** - `extend.right` **[Number][41]?**
**Examples** ### Examples
```javascript ```javascript
// Resize to 140 pixels wide, then add 10 transparent pixels // Resize to 140 pixels wide, then add 10 transparent pixels
@ -193,7 +215,7 @@ sharp(input)
... ...
``` ```
- Throws **[Error][20]** Invalid parameters - Throws **[Error][42]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -201,9 +223,9 @@ Returns **Sharp**
Merge alpha transparency channel, if any, with `background`. Merge alpha transparency channel, if any, with `background`.
**Parameters** ### Parameters
- `flatten` **[Boolean][22]** (optional, default `true`) - `flatten` **[Boolean][44]** (optional, default `true`)
Returns **Sharp** Returns **Sharp**
@ -211,12 +233,12 @@ Returns **Sharp**
Trim "boring" pixels from all edges that contain values within a percentage similarity of the top-left pixel. Trim "boring" pixels from all edges that contain values within a percentage similarity of the top-left pixel.
**Parameters** ### Parameters
- `tolerance` **[Number][19]** value between 1 and 99 representing the percentage similarity. (optional, default `10`) - `tolerance` **[Number][41]** value between 1 and 99 representing the percentage similarity. (optional, default `10`)
- Throws **[Error][20]** Invalid parameters - Throws **[Error][42]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -228,12 +250,12 @@ This can improve the perceived brightness of a resized image in non-linear colou
JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation
when applying a gamma correction. when applying a gamma correction.
**Parameters** ### Parameters
- `gamma` **[Number][19]** value between 1.0 and 3.0. (optional, default `2.2`) - `gamma` **[Number][41]** value between 1.0 and 3.0. (optional, default `2.2`)
- Throws **[Error][20]** Invalid parameters - Throws **[Error][42]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -241,9 +263,9 @@ Returns **Sharp**
Produce the "negative" of the image. Produce the "negative" of the image.
**Parameters** ### Parameters
- `negate` **[Boolean][22]** (optional, default `true`) - `negate` **[Boolean][44]** (optional, default `true`)
Returns **Sharp** Returns **Sharp**
@ -251,9 +273,9 @@ Returns **Sharp**
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** ### Parameters
- `normalise` **[Boolean][22]** (optional, default `true`) - `normalise` **[Boolean][44]** (optional, default `true`)
Returns **Sharp** Returns **Sharp**
@ -261,9 +283,9 @@ Returns **Sharp**
Alternative spelling of normalise. Alternative spelling of normalise.
**Parameters** ### Parameters
- `normalize` **[Boolean][22]** (optional, default `true`) - `normalize` **[Boolean][44]** (optional, default `true`)
Returns **Sharp** Returns **Sharp**
@ -271,16 +293,16 @@ Returns **Sharp**
Convolve the image with the specified kernel. Convolve the image with the specified kernel.
**Parameters** ### Parameters
- `kernel` **[Object][21]** - `kernel` **[Object][43]**
- `kernel.width` **[Number][19]** width of the kernel in pixels. - `kernel.width` **[Number][41]** width of the kernel in pixels.
- `kernel.height` **[Number][19]** width of the kernel in pixels. - `kernel.height` **[Number][41]** width of the kernel in pixels.
- `kernel.kernel` **[Array][23]<[Number][19]>** Array of length `width*height` containing the kernel values. - `kernel.kernel` **[Array][45]<[Number][41]>** Array of length `width*height` containing the kernel values.
- `kernel.scale` **[Number][19]** the scale of the kernel in pixels. (optional, default `sum`) - `kernel.scale` **[Number][41]** the scale of the kernel in pixels. (optional, default `sum`)
- `kernel.offset` **[Number][19]** the offset of the kernel in pixels. (optional, default `0`) - `kernel.offset` **[Number][41]** the offset of the kernel in pixels. (optional, default `0`)
**Examples** ### Examples
```javascript ```javascript
sharp(input) sharp(input)
@ -296,7 +318,7 @@ sharp(input)
}); });
``` ```
- Throws **[Error][20]** Invalid parameters - Throws **[Error][42]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -304,15 +326,15 @@ Returns **Sharp**
Any pixel value greather than or equal to the threshold value will be set to 255, otherwise it will be set to 0. Any pixel value greather than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
**Parameters** ### Parameters
- `threshold` **[Number][19]** a value in the range 0-255 representing the level at which the threshold will be applied. (optional, default `128`) - `threshold` **[Number][41]** a value in the range 0-255 representing the level at which the threshold will be applied. (optional, default `128`)
- `options` **[Object][21]?** - `options` **[Object][43]?**
- `options.greyscale` **[Boolean][22]** convert to single channel greyscale. (optional, default `true`) - `options.greyscale` **[Boolean][44]** convert to single channel greyscale. (optional, default `true`)
- `options.grayscale` **[Boolean][22]** alternative spelling for greyscale. (optional, default `true`) - `options.grayscale` **[Boolean][44]** alternative spelling for greyscale. (optional, default `true`)
- Throws **[Error][20]** Invalid parameters - Throws **[Error][42]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -323,18 +345,18 @@ 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** ### Parameters
- `operand` **([Buffer][24] \| [String][25])** Buffer containing image data or String containing the path to an image file. - `operand` **([Buffer][46] \| [String][47])** Buffer containing image data or String containing the path to an image file.
- `operator` **[String][25]** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively. - `operator` **[String][47]** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
- `options` **[Object][21]?** - `options` **[Object][43]?**
- `options.raw` **[Object][21]?** describes operand when using raw pixel data. - `options.raw` **[Object][43]?** describes operand when using raw pixel data.
- `options.raw.width` **[Number][19]?** - `options.raw.width` **[Number][41]?**
- `options.raw.height` **[Number][19]?** - `options.raw.height` **[Number][41]?**
- `options.raw.channels` **[Number][19]?** - `options.raw.channels` **[Number][41]?**
- Throws **[Error][20]** Invalid parameters - Throws **[Error][42]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -342,62 +364,106 @@ Returns **Sharp**
Apply the linear formula a \* input + b to the image (levels adjustment) Apply the linear formula a \* input + b to the image (levels adjustment)
**Parameters** ### Parameters
- `a` **[Number][19]** multiplier (optional, default `1.0`) - `a` **[Number][41]** multiplier (optional, default `1.0`)
- `b` **[Number][19]** offset (optional, default `0.0`) - `b` **[Number][41]** offset (optional, default `0.0`)
- Throws **[Error][20]** Invalid parameters - Throws **[Error][42]** Invalid parameters
Returns **Sharp** Returns **Sharp**
[1]: #rotate [1]: #rotate
[2]: #extract [2]: #parameters
[3]: #flip [3]: #examples
[4]: #flop [4]: #extract
[5]: #sharpen [5]: #parameters-1
[6]: #median [6]: #examples-1
[7]: #blur [7]: #flip
[8]: #extend [8]: #parameters-2
[9]: #flatten [9]: #flop
[10]: #trim [10]: #parameters-3
[11]: #gamma [11]: #sharpen
[12]: #negate [12]: #parameters-4
[13]: #normalise [13]: #median
[14]: #normalize [14]: #parameters-5
[15]: #convolve [15]: #blur
[16]: #threshold [16]: #parameters-6
[17]: #boolean [17]: #extend
[18]: #linear [18]: #parameters-7
[19]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number [19]: #examples-2
[20]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error [20]: #flatten
[21]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [21]: #parameters-8
[22]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean [22]: #trim
[23]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array [23]: #parameters-9
[24]: https://nodejs.org/api/buffer.html [24]: #gamma
[25]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String [25]: #parameters-10
[26]: #negate
[27]: #parameters-11
[28]: #normalise
[29]: #parameters-12
[30]: #normalize
[31]: #parameters-13
[32]: #convolve
[33]: #parameters-14
[34]: #examples-3
[35]: #threshold
[36]: #parameters-15
[37]: #boolean
[38]: #parameters-16
[39]: #linear
[40]: #parameters-17
[41]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[42]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
[43]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[44]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[45]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[46]: https://nodejs.org/api/buffer.html
[47]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

View File

@ -3,15 +3,34 @@
### Table of Contents ### Table of Contents
- [toFile][1] - [toFile][1]
- [toBuffer][2] - [Parameters][2]
- [withMetadata][3] - [Examples][3]
- [jpeg][4] - [toBuffer][4]
- [png][5] - [Parameters][5]
- [webp][6] - [Examples][6]
- [tiff][7] - [withMetadata][7]
- [raw][8] - [Parameters][8]
- [toFormat][9] - [Examples][9]
- [tile][10] - [jpeg][10]
- [Parameters][11]
- [Examples][12]
- [png][13]
- [Parameters][14]
- [Examples][15]
- [webp][16]
- [Parameters][17]
- [Examples][18]
- [tiff][19]
- [Parameters][20]
- [Examples][21]
- [raw][22]
- [Examples][23]
- [toFormat][24]
- [Parameters][25]
- [Examples][26]
- [tile][27]
- [Parameters][28]
- [Examples][29]
## toFile ## toFile
@ -23,15 +42,15 @@ Note that raw pixel data is only supported for buffer output.
A `Promise` is returned when `callback` is not provided. A `Promise` is returned when `callback` is not provided.
**Parameters** ### Parameters
- `fileOut` **[String][11]** the path to write the image data to. - `fileOut` **[String][30]** the path to write the image data to.
- `callback` **[Function][12]?** called on completion with two arguments `(err, info)`. - `callback` **[Function][31]?** called on completion with two arguments `(err, info)`.
`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`.
**Examples** ### Examples
```javascript ```javascript
sharp(input) sharp(input)
@ -45,9 +64,9 @@ sharp(input)
.catch(err => { ... }); .catch(err => { ... });
``` ```
- Throws **[Error][13]** Invalid parameters - Throws **[Error][32]** Invalid parameters
Returns **[Promise][14]<[Object][15]>** when no callback is provided Returns **[Promise][33]<[Object][34]>** when no callback is provided
## toBuffer ## toBuffer
@ -65,13 +84,13 @@ By default, the format will match the input image, except GIF and SVG input whic
A `Promise` is returned when `callback` is not provided. A `Promise` is returned when `callback` is not provided.
**Parameters** ### Parameters
- `options` **[Object][15]?** - `options` **[Object][34]?**
- `options.resolveWithObject` **[Boolean][16]?** Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`. - `options.resolveWithObject` **[Boolean][35]?** Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
- `callback` **[Function][12]?** - `callback` **[Function][31]?**
**Examples** ### Examples
```javascript ```javascript
sharp(input) sharp(input)
@ -92,7 +111,7 @@ sharp(input)
.catch(err => { ... }); .catch(err => { ... });
``` ```
Returns **[Promise][14]<[Buffer][17]>** when no callback is provided Returns **[Promise][33]<[Buffer][36]>** when no callback is provided
## withMetadata ## withMetadata
@ -100,12 +119,12 @@ Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
The default behaviour, when `withMetadata` is not used, is to strip all metadata and convert to the device-independent sRGB colour space. The default behaviour, when `withMetadata` is not used, is to strip all metadata and convert to the device-independent sRGB colour space.
This will also convert to and add a web-friendly sRGB ICC profile. This will also convert to and add a web-friendly sRGB ICC profile.
**Parameters** ### Parameters
- `withMetadata` **[Object][15]?** - `withMetadata` **[Object][34]?**
- `withMetadata.orientation` **[Number][18]?** value between 1 and 8, used to update the EXIF `Orientation` tag. - `withMetadata.orientation` **[Number][37]?** value between 1 and 8, used to update the EXIF `Orientation` tag.
**Examples** ### Examples
```javascript ```javascript
sharp('input.jpg') sharp('input.jpg')
@ -114,7 +133,7 @@ sharp('input.jpg')
.then(info => { ... }); .then(info => { ... });
``` ```
- Throws **[Error][13]** Invalid parameters - Throws **[Error][32]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -122,19 +141,19 @@ Returns **Sharp**
Use these JPEG options for output image. Use these JPEG options for output image.
**Parameters** ### Parameters
- `options` **[Object][15]?** output options - `options` **[Object][34]?** output options
- `options.quality` **[Number][18]** quality, integer 1-100 (optional, default `80`) - `options.quality` **[Number][37]** quality, integer 1-100 (optional, default `80`)
- `options.progressive` **[Boolean][16]** use progressive (interlace) scan (optional, default `false`) - `options.progressive` **[Boolean][35]** use progressive (interlace) scan (optional, default `false`)
- `options.chromaSubsampling` **[String][11]** set to '4:4:4' to prevent chroma subsampling when quality <= 90 (optional, default `'4:2:0'`) - `options.chromaSubsampling` **[String][30]** set to '4:4:4' to prevent chroma subsampling when quality <= 90 (optional, default `'4:2:0'`)
- `options.trellisQuantisation` **[Boolean][16]** apply trellis quantisation, requires mozjpeg (optional, default `false`) - `options.trellisQuantisation` **[Boolean][35]** apply trellis quantisation, requires mozjpeg (optional, default `false`)
- `options.overshootDeringing` **[Boolean][16]** apply overshoot deringing, requires mozjpeg (optional, default `false`) - `options.overshootDeringing` **[Boolean][35]** apply overshoot deringing, requires mozjpeg (optional, default `false`)
- `options.optimiseScans` **[Boolean][16]** optimise progressive scans, forces progressive, requires mozjpeg (optional, default `false`) - `options.optimiseScans` **[Boolean][35]** optimise progressive scans, forces progressive, requires mozjpeg (optional, default `false`)
- `options.optimizeScans` **[Boolean][16]** alternative spelling of optimiseScans (optional, default `false`) - `options.optimizeScans` **[Boolean][35]** alternative spelling of optimiseScans (optional, default `false`)
- `options.force` **[Boolean][16]** force JPEG output, otherwise attempt to use input format (optional, default `true`) - `options.force` **[Boolean][35]** force JPEG output, otherwise attempt to use input format (optional, default `true`)
**Examples** ### Examples
```javascript ```javascript
// Convert any input to very high quality JPEG output // Convert any input to very high quality JPEG output
@ -146,7 +165,7 @@ const data = await sharp(input)
.toBuffer(); .toBuffer();
``` ```
- Throws **[Error][13]** Invalid options - Throws **[Error][32]** Invalid options
Returns **Sharp** Returns **Sharp**
@ -157,15 +176,15 @@ Use these PNG options for output image.
PNG output is always full colour at 8 or 16 bits per pixel. PNG output is always 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.
**Parameters** ### Parameters
- `options` **[Object][15]?** - `options` **[Object][34]?**
- `options.progressive` **[Boolean][16]** use progressive (interlace) scan (optional, default `false`) - `options.progressive` **[Boolean][35]** use progressive (interlace) scan (optional, default `false`)
- `options.compressionLevel` **[Number][18]** zlib compression level, 0-9 (optional, default `9`) - `options.compressionLevel` **[Number][37]** zlib compression level, 0-9 (optional, default `9`)
- `options.adaptiveFiltering` **[Boolean][16]** use adaptive row filtering (optional, default `false`) - `options.adaptiveFiltering` **[Boolean][35]** use adaptive row filtering (optional, default `false`)
- `options.force` **[Boolean][16]** force PNG output, otherwise attempt to use input format (optional, default `true`) - `options.force` **[Boolean][35]** force PNG output, otherwise attempt to use input format (optional, default `true`)
**Examples** ### Examples
```javascript ```javascript
// Convert any input to PNG output // Convert any input to PNG output
@ -174,7 +193,7 @@ const data = await sharp(input)
.toBuffer(); .toBuffer();
``` ```
- Throws **[Error][13]** Invalid options - Throws **[Error][32]** Invalid options
Returns **Sharp** Returns **Sharp**
@ -182,16 +201,16 @@ Returns **Sharp**
Use these WebP options for output image. Use these WebP options for output image.
**Parameters** ### Parameters
- `options` **[Object][15]?** output options - `options` **[Object][34]?** output options
- `options.quality` **[Number][18]** quality, integer 1-100 (optional, default `80`) - `options.quality` **[Number][37]** quality, integer 1-100 (optional, default `80`)
- `options.alphaQuality` **[Number][18]** quality of alpha layer, integer 0-100 (optional, default `100`) - `options.alphaQuality` **[Number][37]** quality of alpha layer, integer 0-100 (optional, default `100`)
- `options.lossless` **[Boolean][16]** use lossless compression mode (optional, default `false`) - `options.lossless` **[Boolean][35]** use lossless compression mode (optional, default `false`)
- `options.nearLossless` **[Boolean][16]** use near_lossless compression mode (optional, default `false`) - `options.nearLossless` **[Boolean][35]** use near_lossless compression mode (optional, default `false`)
- `options.force` **[Boolean][16]** force WebP output, otherwise attempt to use input format (optional, default `true`) - `options.force` **[Boolean][35]** force WebP output, otherwise attempt to use input format (optional, default `true`)
**Examples** ### Examples
```javascript ```javascript
// Convert any input to lossless WebP output // Convert any input to lossless WebP output
@ -200,7 +219,7 @@ const data = await sharp(input)
.toBuffer(); .toBuffer();
``` ```
- Throws **[Error][13]** Invalid options - Throws **[Error][32]** Invalid options
Returns **Sharp** Returns **Sharp**
@ -208,18 +227,18 @@ Returns **Sharp**
Use these TIFF options for output image. Use these TIFF options for output image.
**Parameters** ### Parameters
- `options` **[Object][15]?** output options - `options` **[Object][34]?** output options
- `options.quality` **[Number][18]** quality, integer 1-100 (optional, default `80`) - `options.quality` **[Number][37]** quality, integer 1-100 (optional, default `80`)
- `options.force` **[Boolean][16]** force TIFF output, otherwise attempt to use input format (optional, default `true`) - `options.force` **[Boolean][35]** force TIFF output, otherwise attempt to use input format (optional, default `true`)
- `options.compression` **[Boolean][16]** compression options: lzw, deflate, jpeg, ccittfax4 (optional, default `'jpeg'`) - `options.compression` **[Boolean][35]** compression options: lzw, deflate, jpeg, ccittfax4 (optional, default `'jpeg'`)
- `options.predictor` **[Boolean][16]** compression predictor options: none, horizontal, float (optional, default `'horizontal'`) - `options.predictor` **[Boolean][35]** compression predictor options: none, horizontal, float (optional, default `'horizontal'`)
- `options.xres` **[Number][18]** horizontal resolution in pixels/mm (optional, default `1.0`) - `options.xres` **[Number][37]** horizontal resolution in pixels/mm (optional, default `1.0`)
- `options.yres` **[Number][18]** vertical resolution in pixels/mm (optional, default `1.0`) - `options.yres` **[Number][37]** vertical resolution in pixels/mm (optional, default `1.0`)
- `options.squash` **[Boolean][16]** squash 8-bit images down to 1 bit (optional, default `false`) - `options.squash` **[Boolean][35]** squash 8-bit images down to 1 bit (optional, default `false`)
**Examples** ### Examples
```javascript ```javascript
// Convert SVG input to LZW-compressed, 1 bit per pixel TIFF output // Convert SVG input to LZW-compressed, 1 bit per pixel TIFF output
@ -232,7 +251,7 @@ sharp('input.svg')
.then(info => { ... }); .then(info => { ... });
``` ```
- Throws **[Error][13]** Invalid options - Throws **[Error][32]** Invalid options
Returns **Sharp** Returns **Sharp**
@ -240,7 +259,7 @@ Returns **Sharp**
Force output to be raw, uncompressed uint8 pixel data. Force output to be raw, uncompressed uint8 pixel data.
**Examples** ### Examples
```javascript ```javascript
// Extract raw RGB pixel data from JPEG input // Extract raw RGB pixel data from JPEG input
@ -255,12 +274,12 @@ Returns **Sharp**
Force output to a given format. Force output to a given format.
**Parameters** ### Parameters
- `format` **([String][11] \| [Object][15])** as a String or an Object with an 'id' attribute - `format` **([String][30] \| [Object][34])** as a String or an Object with an 'id' attribute
- `options` **[Object][15]** output options - `options` **[Object][34]** output options
**Examples** ### Examples
```javascript ```javascript
// Convert any input to PNG output // Convert any input to PNG output
@ -269,7 +288,7 @@ const data = await sharp(input)
.toBuffer(); .toBuffer();
``` ```
- Throws **[Error][13]** unsupported format or options - Throws **[Error][32]** unsupported format or options
Returns **Sharp** Returns **Sharp**
@ -281,16 +300,16 @@ Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed arc
Warning: multiple sharp instances concurrently producing tile output can expose a possible race condition in some versions of libgsf. Warning: multiple sharp instances concurrently producing tile output can expose a possible race condition in some versions of libgsf.
**Parameters** ### Parameters
- `tile` **[Object][15]?** - `tile` **[Object][34]?**
- `tile.size` **[Number][18]** tile size in pixels, a value between 1 and 8192. (optional, default `256`) - `tile.size` **[Number][37]** tile size in pixels, a value between 1 and 8192. (optional, default `256`)
- `tile.overlap` **[Number][18]** tile overlap in pixels, a value between 0 and 8192. (optional, default `0`) - `tile.overlap` **[Number][37]** tile overlap in pixels, a value between 0 and 8192. (optional, default `0`)
- `tile.angle` **[Number][18]** tile angle of rotation, must be a multiple of 90. (optional, default `0`) - `tile.angle` **[Number][37]** tile angle of rotation, must be a multiple of 90. (optional, default `0`)
- `tile.container` **[String][11]** tile container, with value `fs` (filesystem) or `zip` (compressed file). (optional, default `'fs'`) - `tile.container` **[String][30]** tile container, with value `fs` (filesystem) or `zip` (compressed file). (optional, default `'fs'`)
- `tile.layout` **[String][11]** filesystem layout, possible values are `dz`, `zoomify` or `google`. (optional, default `'dz'`) - `tile.layout` **[String][30]** filesystem layout, possible values are `dz`, `zoomify` or `google`. (optional, default `'dz'`)
**Examples** ### Examples
```javascript ```javascript
sharp('input.tiff') sharp('input.tiff')
@ -304,42 +323,80 @@ sharp('input.tiff')
}); });
``` ```
- Throws **[Error][13]** Invalid parameters - Throws **[Error][32]** Invalid parameters
Returns **Sharp** Returns **Sharp**
[1]: #tofile [1]: #tofile
[2]: #tobuffer [2]: #parameters
[3]: #withmetadata [3]: #examples
[4]: #jpeg [4]: #tobuffer
[5]: #png [5]: #parameters-1
[6]: #webp [6]: #examples-1
[7]: #tiff [7]: #withmetadata
[8]: #raw [8]: #parameters-2
[9]: #toformat [9]: #examples-2
[10]: #tile [10]: #jpeg
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String [11]: #parameters-3
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function [12]: #examples-3
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error [13]: #png
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise [14]: #parameters-4
[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [15]: #examples-4
[16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean [16]: #webp
[17]: https://nodejs.org/api/buffer.html [17]: #parameters-5
[18]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number [18]: #examples-5
[19]: #tiff
[20]: #parameters-6
[21]: #examples-6
[22]: #raw
[23]: #examples-7
[24]: #toformat
[25]: #parameters-7
[26]: #examples-8
[27]: #tile
[28]: #parameters-8
[29]: #examples-9
[30]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[31]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
[32]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
[33]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
[34]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[35]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[36]: https://nodejs.org/api/buffer.html
[37]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number

View File

@ -3,12 +3,20 @@
### Table of Contents ### Table of Contents
- [resize][1] - [resize][1]
- [crop][2] - [Parameters][2]
- [embed][3] - [Examples][3]
- [max][4] - [crop][4]
- [min][5] - [Parameters][5]
- [ignoreAspectRatio][6] - [Examples][6]
- [withoutEnlargement][7] - [embed][7]
- [Parameters][8]
- [Examples][9]
- [max][10]
- [Examples][11]
- [min][12]
- [ignoreAspectRatio][13]
- [withoutEnlargement][14]
- [Parameters][15]
## resize ## resize
@ -17,20 +25,20 @@ By default, the resized image is centre cropped to the exact size specified.
Possible kernels are: Possible kernels are:
- `nearest`: Use [nearest neighbour interpolation][8]. - `nearest`: Use [nearest neighbour interpolation][16].
- `cubic`: Use a [Catmull-Rom spline][9]. - `cubic`: Use a [Catmull-Rom spline][17].
- `lanczos2`: Use a [Lanczos kernel][10] with `a=2`. - `lanczos2`: Use a [Lanczos kernel][18] with `a=2`.
- `lanczos3`: Use a Lanczos kernel with `a=3` (the default). - `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
**Parameters** ### Parameters
- `width` **[Number][11]?** pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height. - `width` **[Number][19]?** pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.
- `height` **[Number][11]?** pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width. - `height` **[Number][19]?** pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
- `options` **[Object][12]?** - `options` **[Object][20]?**
- `options.kernel` **[String][13]** the kernel to use for image reduction. (optional, default `'lanczos3'`) - `options.kernel` **[String][21]** the kernel to use for image reduction. (optional, default `'lanczos3'`)
- `options.fastShrinkOnLoad` **[Boolean][14]** 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`) - `options.fastShrinkOnLoad` **[Boolean][22]** 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** ### Examples
```javascript ```javascript
sharp(inputBuffer) sharp(inputBuffer)
@ -47,7 +55,7 @@ sharp(inputBuffer)
}); });
``` ```
- Throws **[Error][15]** Invalid parameters - Throws **[Error][23]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -61,14 +69,14 @@ Possible attributes of the optional `sharp.gravity` are `north`, `northeast`, `e
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][16]. - `entropy`: focus on the region with the highest [Shannon entropy][24].
- `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.
**Parameters** ### Parameters
- `crop` **[String][13]** A member of `sharp.gravity` to crop to an edge/corner or `sharp.strategy` to crop dynamically. (optional, default `'centre'`) - `crop` **[String][21]** A member of `sharp.gravity` to crop to an edge/corner or `sharp.strategy` to crop dynamically. (optional, default `'centre'`)
**Examples** ### Examples
```javascript ```javascript
const transformer = sharp() const transformer = sharp()
@ -82,7 +90,7 @@ const transformer = sharp()
readableStream.pipe(transformer).pipe(writableStream); readableStream.pipe(transformer).pipe(writableStream);
``` ```
- Throws **[Error][15]** Invalid parameters - Throws **[Error][23]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -94,11 +102,11 @@ then embed on a background of the exact `width` and `height` specified.
If the background contains an alpha value then WebP and PNG format output images will If the background contains an alpha value then WebP and PNG format output images will
contain an alpha channel, even when the input image does not. contain an alpha channel, even when the input image does not.
**Parameters** ### Parameters
- `embed` **[String][13]** A member of `sharp.gravity` to embed to an edge/corner. (optional, default `'centre'`) - `embed` **[String][21]** A member of `sharp.gravity` to embed to an edge/corner. (optional, default `'centre'`)
**Examples** ### Examples
```javascript ```javascript
sharp('input.gif') sharp('input.gif')
@ -115,7 +123,7 @@ sharp('input.gif')
}); });
``` ```
- Throws **[Error][15]** Invalid parameters - Throws **[Error][23]** Invalid parameters
Returns **Sharp** Returns **Sharp**
@ -126,7 +134,7 @@ while ensuring its dimensions are less than or equal to the `width` and `height`
Both `width` and `height` must be provided via `resize` otherwise the behaviour will default to `crop`. Both `width` and `height` must be provided via `resize` otherwise the behaviour will default to `crop`.
**Examples** ### Examples
```javascript ```javascript
sharp(inputBuffer) sharp(inputBuffer)
@ -167,40 +175,56 @@ Use with `max()` to preserve the image's aspect ratio.
The default behaviour _before_ function call is `false`, meaning the image will be enlarged. The default behaviour _before_ function call is `false`, meaning the image will be enlarged.
**Parameters** ### Parameters
- `withoutEnlargement` **[Boolean][14]** (optional, default `true`) - `withoutEnlargement` **[Boolean][22]** (optional, default `true`)
Returns **Sharp** Returns **Sharp**
[1]: #resize [1]: #resize
[2]: #crop [2]: #parameters
[3]: #embed [3]: #examples
[4]: #max [4]: #crop
[5]: #min [5]: #parameters-1
[6]: #ignoreaspectratio [6]: #examples-1
[7]: #withoutenlargement [7]: #embed
[8]: http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation [8]: #parameters-2
[9]: https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline [9]: #examples-2
[10]: https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel [10]: #max
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number [11]: #examples-3
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [12]: #min
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String [13]: #ignoreaspectratio
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean [14]: #withoutenlargement
[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error [15]: #parameters-3
[16]: https://en.wikipedia.org/wiki/Entropy_%28information_theory%29 [16]: http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation
[17]: https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline
[18]: https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel
[19]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[20]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[21]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[22]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[23]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
[24]: https://en.wikipedia.org/wiki/Entropy_%28information_theory%29

View File

@ -3,9 +3,16 @@
### Table of Contents ### Table of Contents
- [cache][1] - [cache][1]
- [concurrency][2] - [Parameters][2]
- [counters][3] - [Examples][3]
- [simd][4] - [concurrency][4]
- [Parameters][5]
- [Examples][6]
- [counters][7]
- [Examples][8]
- [simd][9]
- [Parameters][10]
- [Examples][11]
## cache ## cache
@ -14,14 +21,14 @@ 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** ### Parameters
- `options` **([Object][5] \| [Boolean][6])** Object with the following attributes, or Boolean where true uses default cache settings and false removes all caching (optional, default `true`) - `options` **([Object][12] \| [Boolean][13])** Object with the following attributes, or Boolean where true uses default cache settings and false removes all caching (optional, default `true`)
- `options.memory` **[Number][7]** is the maximum memory in MB to use for this cache (optional, default `50`) - `options.memory` **[Number][14]** is the maximum memory in MB to use for this cache (optional, default `50`)
- `options.files` **[Number][7]** is the maximum number of files to hold open (optional, default `20`) - `options.files` **[Number][14]** is the maximum number of files to hold open (optional, default `20`)
- `options.items` **[Number][7]** is the maximum number of operations to cache (optional, default `100`) - `options.items` **[Number][14]** is the maximum number of operations to cache (optional, default `100`)
**Examples** ### Examples
```javascript ```javascript
const stats = sharp.cache(); const stats = sharp.cache();
@ -33,7 +40,7 @@ sharp.cache( { files: 0 } );
sharp.cache(false); sharp.cache(false);
``` ```
Returns **[Object][5]** Returns **[Object][12]**
## concurrency ## concurrency
@ -47,11 +54,11 @@ is limited by libuv's `UV_THREADPOOL_SIZE` environment variable.
This method always returns the current concurrency. This method always returns the current concurrency.
**Parameters** ### Parameters
- `concurrency` **[Number][7]?** - `concurrency` **[Number][14]?**
**Examples** ### Examples
```javascript ```javascript
const threads = sharp.concurrency(); // 4 const threads = sharp.concurrency(); // 4
@ -59,7 +66,7 @@ sharp.concurrency(2); // 2
sharp.concurrency(0); // 4 sharp.concurrency(0); // 4
``` ```
Returns **[Number][7]** concurrency Returns **[Number][14]** concurrency
## counters ## counters
@ -68,13 +75,13 @@ 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. - 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. - process is the number of resize tasks currently being processed.
**Examples** ### Examples
```javascript ```javascript
const counters = sharp.counters(); // { queue: 2, process: 4 } const counters = sharp.counters(); // { queue: 2, process: 4 }
``` ```
Returns **[Object][5]** Returns **[Object][12]**
## simd ## simd
@ -87,11 +94,11 @@ by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM N
This feature is currently off by default but future versions may reverse this. This feature is currently off by default but future versions may reverse this.
Versions of liborc prior to 0.4.25 are known to segfault under heavy load. Versions of liborc prior to 0.4.25 are known to segfault under heavy load.
**Parameters** ### Parameters
- `simd` **[Boolean][6]** (optional, default `false`) - `simd` **[Boolean][13]** (optional, default `false`)
**Examples** ### Examples
```javascript ```javascript
const simd = sharp.simd(); const simd = sharp.simd();
@ -103,18 +110,32 @@ const simd = sharp.simd(true);
// attempts to enable the use of SIMD, returning true if available // attempts to enable the use of SIMD, returning true if available
``` ```
Returns **[Boolean][6]** Returns **[Boolean][13]**
[1]: #cache [1]: #cache
[2]: #concurrency [2]: #parameters
[3]: #counters [3]: #examples
[4]: #simd [4]: #concurrency
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [5]: #parameters-1
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean [6]: #examples-1
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number [7]: #counters
[8]: #examples-2
[9]: #simd
[10]: #parameters-2
[11]: #examples-3
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number

View File

@ -4,7 +4,7 @@
Requires libvips v8.6.1. Requires libvips v8.6.1.
#### v0.20.3 - TBD #### v0.20.4 - TBD
* Prevent possible rounding error when using shrink-on-load and 90/270 degree rotation. * Prevent possible rounding error when using shrink-on-load and 90/270 degree rotation.
[#1241](https://github.com/lovell/sharp/issues/1241) [#1241](https://github.com/lovell/sharp/issues/1241)

View File

@ -95,11 +95,11 @@
"async": "^2.6.1", "async": "^2.6.1",
"cc": "^1.0.2", "cc": "^1.0.2",
"decompress-zip": "^0.3.1", "decompress-zip": "^0.3.1",
"documentation": "^7.1.0", "documentation": "^8.0.0",
"exif-reader": "^1.0.2", "exif-reader": "^1.0.2",
"icc": "^1.0.0", "icc": "^1.0.0",
"mocha": "^5.2.0", "mocha": "^5.2.0",
"nyc": "^11.8.0", "nyc": "^12.0.2",
"prebuild": "^7.6.0", "prebuild": "^7.6.0",
"prebuild-ci": "^2.2.3", "prebuild-ci": "^2.2.3",
"rimraf": "^2.6.2", "rimraf": "^2.6.2",