Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
873aa6700f | ||
|
|
0d9590a9a0 | ||
|
|
94607b585a | ||
|
|
da0b0348a2 | ||
|
|
09263455b5 | ||
|
|
ddc23493d4 | ||
|
|
54a71fc142 | ||
|
|
b1a9bf10a2 | ||
|
|
97cfbe1b63 | ||
|
|
0ee8c63551 | ||
|
|
0ac5a9ad82 | ||
|
|
6e51f2d608 | ||
|
|
f23a8dc9dc | ||
|
|
d09fe6178c | ||
|
|
ae2cfcc4f3 | ||
|
|
853cc65e32 | ||
|
|
5d140d949f | ||
|
|
6d2da2b3ba | ||
|
|
165e337e44 | ||
|
|
b154cd0418 | ||
|
|
8ef1532691 | ||
|
|
771e44f2a7 | ||
|
|
8933f1128d | ||
|
|
dbac4b9a63 | ||
|
|
bdac5b5807 | ||
|
|
b0961b5213 | ||
|
|
0d7c3fc4d8 | ||
|
|
8dac256096 | ||
|
|
8320da39c3 | ||
|
|
875937e3d8 | ||
|
|
f880adbaac | ||
|
|
48c5f86adb | ||
|
|
f60f7dab12 |
@@ -16,7 +16,7 @@ matrix:
|
|||||||
- os: linux
|
- os: linux
|
||||||
dist: trusty
|
dist: trusty
|
||||||
sudo: false
|
sudo: false
|
||||||
node_js: "9"
|
node_js: "10"
|
||||||
- os: osx
|
- os: osx
|
||||||
osx_image: xcode8.3
|
osx_image: xcode8.3
|
||||||
node_js: "4"
|
node_js: "4"
|
||||||
@@ -28,7 +28,7 @@ matrix:
|
|||||||
node_js: "8"
|
node_js: "8"
|
||||||
- os: osx
|
- os: osx
|
||||||
osx_image: xcode8.3
|
osx_image: xcode8.3
|
||||||
node_js: "9"
|
node_js: "10"
|
||||||
after_success:
|
after_success:
|
||||||
- npm install coveralls
|
- npm install coveralls
|
||||||
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
|
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ Any change that modifies the existing public API should be added to the relevant
|
|||||||
|
|
||||||
| Release | WIP branch |
|
| Release | WIP branch |
|
||||||
| ------: | :--------- |
|
| ------: | :--------- |
|
||||||
| v0.20.0 | prebuild |
|
|
||||||
| v0.21.0 | teeth |
|
| v0.21.0 | teeth |
|
||||||
| v0.22.0 | uptake |
|
| v0.22.0 | uptake |
|
||||||
|
|
||||||
@@ -90,15 +89,6 @@ Requires [Valgrind](http://valgrind.org/).
|
|||||||
npm run test-leak
|
npm run test-leak
|
||||||
```
|
```
|
||||||
|
|
||||||
### Packaging tests
|
|
||||||
|
|
||||||
Tests the installation on a number of Linux-based operating systems.
|
|
||||||
Requires docker.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm run test-packaging
|
|
||||||
```
|
|
||||||
|
|
||||||
## Finally
|
## Finally
|
||||||
|
|
||||||
Please feel free to ask any questions via a
|
Please feel free to ask any questions via a
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ As well as image resizing, operations such as
|
|||||||
rotation, extraction, compositing and gamma correction are available.
|
rotation, extraction, compositing and gamma correction are available.
|
||||||
|
|
||||||
Most modern 64-bit OS X, Windows and Linux (glibc) systems running
|
Most modern 64-bit OS X, Windows and Linux (glibc) systems running
|
||||||
Node versions 4, 6, 8 and 9
|
Node versions 4, 6, 8 and 10
|
||||||
do not require any additional install or runtime dependencies.
|
do not require any additional install or runtime dependencies.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ environment:
|
|||||||
- nodejs_version: "4"
|
- nodejs_version: "4"
|
||||||
- nodejs_version: "6"
|
- nodejs_version: "6"
|
||||||
- nodejs_version: "8"
|
- nodejs_version: "8"
|
||||||
- nodejs_version: "9"
|
- nodejs_version: "10"
|
||||||
install:
|
install:
|
||||||
- ps: Install-Product node $env:nodejs_version x64
|
- ps: Install-Product node $env:nodejs_version x64
|
||||||
- npm install -g npm@5.3.x
|
- npm install -g npm@5
|
||||||
- npm install
|
- npm install
|
||||||
test_script:
|
test_script:
|
||||||
- npm test
|
- npm test
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -3,10 +3,17 @@
|
|||||||
### Table of Contents
|
### Table of Contents
|
||||||
|
|
||||||
- [background][1]
|
- [background][1]
|
||||||
- [greyscale][2]
|
- [Parameters][2]
|
||||||
- [grayscale][3]
|
- [tint][3]
|
||||||
- [toColourspace][4]
|
- [Parameters][4]
|
||||||
- [toColorspace][5]
|
- [greyscale][5]
|
||||||
|
- [Parameters][6]
|
||||||
|
- [grayscale][7]
|
||||||
|
- [Parameters][8]
|
||||||
|
- [toColourspace][9]
|
||||||
|
- [Parameters][10]
|
||||||
|
- [toColorspace][11]
|
||||||
|
- [Parameters][12]
|
||||||
|
|
||||||
## background
|
## background
|
||||||
|
|
||||||
@@ -17,12 +24,26 @@ 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][6] \| [Object][7])** parsed by the [color][8] 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][9]** Invalid parameter
|
- Throws **[Error][16]** Invalid parameter
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
|
## tint
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
- `rgb` **([String][13] \| [Object][14])** parsed by the [color][15] module to extract chroma values.
|
||||||
|
|
||||||
|
|
||||||
|
- Throws **[Error][16]** Invalid parameter
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -35,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][10]** (optional, default `true`)
|
- `greyscale` **[Boolean][17]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -45,9 +66,9 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Alternative spelling of `greyscale`.
|
Alternative spelling of `greyscale`.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `grayscale` **[Boolean][10]** (optional, default `true`)
|
- `grayscale` **[Boolean][17]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -56,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][6]?** output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][11]
|
- `colourspace` **[String][13]?** output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][18]
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][9]** Invalid parameters
|
- Throws **[Error][16]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -69,33 +90,47 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Alternative spelling of `toColourspace`.
|
Alternative spelling of `toColourspace`.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `colorspace` **[String][6]?** output colorspace.
|
- `colorspace` **[String][13]?** output colorspace.
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][9]** Invalid parameters
|
- Throws **[Error][16]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
[1]: #background
|
[1]: #background
|
||||||
|
|
||||||
[2]: #greyscale
|
[2]: #parameters
|
||||||
|
|
||||||
[3]: #grayscale
|
[3]: #tint
|
||||||
|
|
||||||
[4]: #tocolourspace
|
[4]: #parameters-1
|
||||||
|
|
||||||
[5]: #tocolorspace
|
[5]: #greyscale
|
||||||
|
|
||||||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
[6]: #parameters-2
|
||||||
|
|
||||||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
[7]: #grayscale
|
||||||
|
|
||||||
[8]: https://www.npmjs.org/package/color
|
[8]: #parameters-3
|
||||||
|
|
||||||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
[9]: #tocolourspace
|
||||||
|
|
||||||
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
[10]: #parameters-4
|
||||||
|
|
||||||
[11]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L568
|
[11]: #tocolorspace
|
||||||
|
|
||||||
|
[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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -3,34 +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.raw` **[Object][7]?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
- `options.page` **[Number][14]** page number to extract for multi-page input (GIF, TIFF) (optional, default `0`)
|
||||||
- `options.raw.width` **[Number][9]?**
|
- `options.raw` **[Object][12]?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
||||||
- `options.raw.height` **[Number][9]?**
|
- `options.raw.width` **[Number][14]?**
|
||||||
- `options.raw.channels` **[Number][9]?** 1-4
|
- `options.raw.height` **[Number][14]?**
|
||||||
- `options.create` **[Object][7]?** describes a new image to be created.
|
- `options.raw.channels` **[Number][14]?** 1-4
|
||||||
- `options.create.width` **[Number][9]?**
|
- `options.create` **[Object][12]?** describes a new image to be created.
|
||||||
- `options.create.height` **[Number][9]?**
|
- `options.create.width` **[Number][14]?**
|
||||||
- `options.create.channels` **[Number][9]?** 3-4
|
- `options.create.height` **[Number][14]?**
|
||||||
- `options.create.background` **([String][6] \| [Object][7])?** parsed by the [color][10] module to extract values for red, green, blue and alpha.
|
- `options.create.channels` **[Number][14]?** 3-4
|
||||||
|
- `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')
|
||||||
@@ -69,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);
|
||||||
@@ -102,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) {
|
||||||
@@ -112,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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -3,22 +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]
|
||||||
- [blur][6]
|
- [Examples][6]
|
||||||
- [extend][7]
|
- [flip][7]
|
||||||
- [flatten][8]
|
- [Parameters][8]
|
||||||
- [trim][9]
|
- [flop][9]
|
||||||
- [gamma][10]
|
- [Parameters][10]
|
||||||
- [negate][11]
|
- [sharpen][11]
|
||||||
- [normalise][12]
|
- [Parameters][12]
|
||||||
- [normalize][13]
|
- [median][13]
|
||||||
- [convolve][14]
|
- [Parameters][14]
|
||||||
- [threshold][15]
|
- [blur][15]
|
||||||
- [boolean][16]
|
- [Parameters][16]
|
||||||
- [linear][17]
|
- [extend][17]
|
||||||
|
- [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
|
||||||
|
|
||||||
@@ -36,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][18]** 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()
|
||||||
@@ -54,7 +77,7 @@ const pipeline = sharp()
|
|||||||
readableStream.pipe(pipeline);
|
readableStream.pipe(pipeline);
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][19]** Invalid parameters
|
- Throws **[Error][42]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -66,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][20]**
|
- `options` **[Object][43]**
|
||||||
- `options.left` **[Number][18]** zero-indexed offset from left edge
|
- `options.left` **[Number][41]** zero-indexed offset from left edge
|
||||||
- `options.top` **[Number][18]** zero-indexed offset from top edge
|
- `options.top` **[Number][41]** zero-indexed offset from top edge
|
||||||
- `options.width` **[Number][18]** dimension of extracted image
|
- `options.width` **[Number][41]** dimension of extracted image
|
||||||
- `options.height` **[Number][18]** dimension of extracted image
|
- `options.height` **[Number][41]** dimension of extracted image
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp(input)
|
sharp(input)
|
||||||
@@ -94,7 +117,7 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][19]** Invalid parameters
|
- Throws **[Error][42]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -103,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][21]** (optional, default `true`)
|
- `flip` **[Boolean][44]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -114,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][21]** (optional, default `true`)
|
- `flop` **[Boolean][44]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -127,14 +150,28 @@ 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][18]?** 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][18]** 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][18]** 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][19]** Invalid parameters
|
- Throws **[Error][42]** Invalid parameters
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
|
## median
|
||||||
|
|
||||||
|
Apply median filter.
|
||||||
|
When used without parameters the default window is 3x3.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
- `size` **[Number][41]** square mask size: size x size (optional, default `3`)
|
||||||
|
|
||||||
|
|
||||||
|
- Throws **[Error][42]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -144,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][18]?** 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][19]** Invalid parameters
|
- Throws **[Error][42]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -158,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][18] \| [Object][20])** 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][18]?**
|
- `extend.top` **[Number][41]?**
|
||||||
- `extend.left` **[Number][18]?**
|
- `extend.left` **[Number][41]?**
|
||||||
- `extend.bottom` **[Number][18]?**
|
- `extend.bottom` **[Number][41]?**
|
||||||
- `extend.right` **[Number][18]?**
|
- `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
|
||||||
@@ -178,7 +215,7 @@ sharp(input)
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][19]** Invalid parameters
|
- Throws **[Error][42]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -186,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][21]** (optional, default `true`)
|
- `flatten` **[Boolean][44]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -196,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][18]** 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][19]** Invalid parameters
|
- Throws **[Error][42]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -213,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][18]** 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][19]** Invalid parameters
|
- Throws **[Error][42]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -226,9 +263,9 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Produce the "negative" of the image.
|
Produce the "negative" of the image.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `negate` **[Boolean][21]** (optional, default `true`)
|
- `negate` **[Boolean][44]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -236,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][21]** (optional, default `true`)
|
- `normalise` **[Boolean][44]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -246,9 +283,9 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Alternative spelling of normalise.
|
Alternative spelling of normalise.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `normalize` **[Boolean][21]** (optional, default `true`)
|
- `normalize` **[Boolean][44]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -256,16 +293,16 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Convolve the image with the specified kernel.
|
Convolve the image with the specified kernel.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `kernel` **[Object][20]**
|
- `kernel` **[Object][43]**
|
||||||
- `kernel.width` **[Number][18]** width of the kernel in pixels.
|
- `kernel.width` **[Number][41]** width of the kernel in pixels.
|
||||||
- `kernel.height` **[Number][18]** width of the kernel in pixels.
|
- `kernel.height` **[Number][41]** width of the kernel in pixels.
|
||||||
- `kernel.kernel` **[Array][22]<[Number][18]>** 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][18]** 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][18]** 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)
|
||||||
@@ -281,7 +318,7 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][19]** Invalid parameters
|
- Throws **[Error][42]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -289,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][18]** 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][20]?**
|
- `options` **[Object][43]?**
|
||||||
- `options.greyscale` **[Boolean][21]** convert to single channel greyscale. (optional, default `true`)
|
- `options.greyscale` **[Boolean][44]** convert to single channel greyscale. (optional, default `true`)
|
||||||
- `options.grayscale` **[Boolean][21]** alternative spelling for greyscale. (optional, default `true`)
|
- `options.grayscale` **[Boolean][44]** alternative spelling for greyscale. (optional, default `true`)
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][19]** Invalid parameters
|
- Throws **[Error][42]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -308,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][23] \| [String][24])** 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][24]** 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][20]?**
|
- `options` **[Object][43]?**
|
||||||
- `options.raw` **[Object][20]?** describes operand when using raw pixel data.
|
- `options.raw` **[Object][43]?** describes operand when using raw pixel data.
|
||||||
- `options.raw.width` **[Number][18]?**
|
- `options.raw.width` **[Number][41]?**
|
||||||
- `options.raw.height` **[Number][18]?**
|
- `options.raw.height` **[Number][41]?**
|
||||||
- `options.raw.channels` **[Number][18]?**
|
- `options.raw.channels` **[Number][41]?**
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][19]** Invalid parameters
|
- Throws **[Error][42]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -327,60 +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][18]** multiplier (optional, default `1.0`)
|
- `a` **[Number][41]** multiplier (optional, default `1.0`)
|
||||||
- `b` **[Number][18]** offset (optional, default `0.0`)
|
- `b` **[Number][41]** offset (optional, default `0.0`)
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][19]** 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]: #blur
|
[6]: #examples-1
|
||||||
|
|
||||||
[7]: #extend
|
[7]: #flip
|
||||||
|
|
||||||
[8]: #flatten
|
[8]: #parameters-2
|
||||||
|
|
||||||
[9]: #trim
|
[9]: #flop
|
||||||
|
|
||||||
[10]: #gamma
|
[10]: #parameters-3
|
||||||
|
|
||||||
[11]: #negate
|
[11]: #sharpen
|
||||||
|
|
||||||
[12]: #normalise
|
[12]: #parameters-4
|
||||||
|
|
||||||
[13]: #normalize
|
[13]: #median
|
||||||
|
|
||||||
[14]: #convolve
|
[14]: #parameters-5
|
||||||
|
|
||||||
[15]: #threshold
|
[15]: #blur
|
||||||
|
|
||||||
[16]: #boolean
|
[16]: #parameters-6
|
||||||
|
|
||||||
[17]: #linear
|
[17]: #extend
|
||||||
|
|
||||||
[18]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
[18]: #parameters-7
|
||||||
|
|
||||||
[19]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
[19]: #examples-2
|
||||||
|
|
||||||
[20]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
[20]: #flatten
|
||||||
|
|
||||||
[21]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
[21]: #parameters-8
|
||||||
|
|
||||||
[22]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
[22]: #trim
|
||||||
|
|
||||||
[23]: https://nodejs.org/api/buffer.html
|
[23]: #parameters-9
|
||||||
|
|
||||||
[24]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
[24]: #gamma
|
||||||
|
|
||||||
|
[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
|
||||||
|
|||||||
@@ -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,18 +42,31 @@ 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
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid parameters
|
```javascript
|
||||||
|
sharp(input)
|
||||||
|
.toFile('output.png', (err, info) => { ... });
|
||||||
|
```
|
||||||
|
|
||||||
Returns **[Promise][14]<[Object][15]>** when no callback is provided
|
```javascript
|
||||||
|
sharp(input)
|
||||||
|
.toFile('output.png')
|
||||||
|
.then(info => { ... })
|
||||||
|
.catch(err => { ... });
|
||||||
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][32]** Invalid parameters
|
||||||
|
|
||||||
|
Returns **[Promise][33]<[Object][34]>** when no callback is provided
|
||||||
|
|
||||||
## toBuffer
|
## toBuffer
|
||||||
|
|
||||||
@@ -52,13 +84,34 @@ 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]?**
|
||||||
|
|
||||||
Returns **[Promise][14]<[Buffer][17]>** when no callback is provided
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
sharp(input)
|
||||||
|
.toBuffer((err, data, info) => { ... });
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
sharp(input)
|
||||||
|
.toBuffer()
|
||||||
|
.then(data => { ... })
|
||||||
|
.catch(err => { ... });
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
sharp(input)
|
||||||
|
.toBuffer({ resolveWithObject: true })
|
||||||
|
.then(({ data, info }) => { ... })
|
||||||
|
.catch(err => { ... });
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns **[Promise][33]<[Buffer][36]>** when no callback is provided
|
||||||
|
|
||||||
## withMetadata
|
## withMetadata
|
||||||
|
|
||||||
@@ -66,13 +119,21 @@ 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
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid parameters
|
```javascript
|
||||||
|
sharp('input.jpg')
|
||||||
|
.withMetadata()
|
||||||
|
.toFile('output-with-metadata.jpg')
|
||||||
|
.then(info => { ... });
|
||||||
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][32]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -80,20 +141,31 @@ 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
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid options
|
```javascript
|
||||||
|
// Convert any input to very high quality JPEG output
|
||||||
|
const data = await sharp(input)
|
||||||
|
.jpeg({
|
||||||
|
quality: 100,
|
||||||
|
chromaSubsampling: '4:4:4'
|
||||||
|
})
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][32]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -101,16 +173,27 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Use these PNG options for output image.
|
Use these PNG options for output image.
|
||||||
|
|
||||||
**Parameters**
|
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.
|
||||||
|
|
||||||
- `options` **[Object][15]?**
|
### Parameters
|
||||||
- `options.progressive` **[Boolean][16]** use progressive (interlace) scan (optional, default `false`)
|
|
||||||
- `options.compressionLevel` **[Number][18]** zlib compression level, 0-9 (optional, default `9`)
|
|
||||||
- `options.adaptiveFiltering` **[Boolean][16]** use adaptive row filtering (optional, default `false`)
|
|
||||||
- `options.force` **[Boolean][16]** force PNG output, otherwise attempt to use input format (optional, default `true`)
|
|
||||||
|
|
||||||
|
- `options` **[Object][34]?**
|
||||||
|
- `options.progressive` **[Boolean][35]** use progressive (interlace) scan (optional, default `false`)
|
||||||
|
- `options.compressionLevel` **[Number][37]** zlib compression level, 0-9 (optional, default `9`)
|
||||||
|
- `options.adaptiveFiltering` **[Boolean][35]** use adaptive row filtering (optional, default `false`)
|
||||||
|
- `options.force` **[Boolean][35]** force PNG output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid options
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Convert any input to PNG output
|
||||||
|
const data = await sharp(input)
|
||||||
|
.png()
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][32]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -118,17 +201,25 @@ 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
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid options
|
```javascript
|
||||||
|
// Convert any input to lossless WebP output
|
||||||
|
const data = await sharp(input)
|
||||||
|
.webp({ lossless: true })
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][32]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -136,19 +227,31 @@ 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 (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
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid options
|
```javascript
|
||||||
|
// Convert SVG input to LZW-compressed, 1 bit per pixel TIFF output
|
||||||
|
sharp('input.svg')
|
||||||
|
.tiff({
|
||||||
|
compression: 'lzw',
|
||||||
|
squash: true
|
||||||
|
})
|
||||||
|
.toFile('1-bpp-output.tiff')
|
||||||
|
.then(info => { ... });
|
||||||
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][32]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -156,19 +259,36 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Force output to be raw, uncompressed uint8 pixel data.
|
Force output to be raw, uncompressed uint8 pixel data.
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Extract raw RGB pixel data from JPEG input
|
||||||
|
const { data, info } = await sharp('input.jpg')
|
||||||
|
.raw()
|
||||||
|
.toBuffer({ resolveWithObject: true });
|
||||||
|
```
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
## toFormat
|
## toFormat
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
- Throws **[Error][13]** unsupported format or options
|
```javascript
|
||||||
|
// Convert any input to PNG output
|
||||||
|
const data = await sharp(input)
|
||||||
|
.toFormat('png')
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
- Throws **[Error][32]** unsupported format or options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -178,16 +298,18 @@ 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.
|
||||||
Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed archive file format.
|
Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed archive file format.
|
||||||
|
|
||||||
**Parameters**
|
Warning: multiple sharp instances concurrently producing tile output can expose a possible race condition in some versions of libgsf.
|
||||||
|
|
||||||
- `tile` **[Object][15]?**
|
### Parameters
|
||||||
- `tile.size` **[Number][18]** 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.angle` **[Number][18]** 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.layout` **[String][11]** filesystem layout, possible values are `dz`, `zoomify` or `google`. (optional, default `'dz'`)
|
|
||||||
|
|
||||||
**Examples**
|
- `tile` **[Object][34]?**
|
||||||
|
- `tile.size` **[Number][37]** tile size in pixels, a value between 1 and 8192. (optional, default `256`)
|
||||||
|
- `tile.overlap` **[Number][37]** tile overlap in pixels, a value between 0 and 8192. (optional, default `0`)
|
||||||
|
- `tile.angle` **[Number][37]** tile angle of rotation, must be a multiple of 90. (optional, default `0`)
|
||||||
|
- `tile.container` **[String][30]** tile container, with value `fs` (filesystem) or `zip` (compressed file). (optional, default `'fs'`)
|
||||||
|
- `tile.layout` **[String][30]** filesystem layout, possible values are `dz`, `zoomify` or `google`. (optional, default `'dz'`)
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp('input.tiff')
|
sharp('input.tiff')
|
||||||
@@ -201,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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -4,6 +4,53 @@
|
|||||||
|
|
||||||
Requires libvips v8.6.1.
|
Requires libvips v8.6.1.
|
||||||
|
|
||||||
|
#### v0.20.4 - 20<sup>th</sup> June 2018
|
||||||
|
|
||||||
|
* Prevent possible rounding error when using shrink-on-load and 90/270 degree rotation.
|
||||||
|
[#1241](https://github.com/lovell/sharp/issues/1241)
|
||||||
|
[@anahit42](https://github.com/anahit42)
|
||||||
|
|
||||||
|
* Ensure extractChannel sets correct single-channel colour space interpretation.
|
||||||
|
[#1257](https://github.com/lovell/sharp/issues/1257)
|
||||||
|
[@jeremychone](https://github.com/jeremychone)
|
||||||
|
|
||||||
|
#### v0.20.3 - 29<sup>th</sup> May 2018
|
||||||
|
|
||||||
|
* Fix tint operation by ensuring LAB interpretation and allowing negative values.
|
||||||
|
[#1235](https://github.com/lovell/sharp/issues/1235)
|
||||||
|
[@wezside](https://github.com/wezside)
|
||||||
|
|
||||||
|
#### v0.20.2 - 28<sup>th</sup> April 2018
|
||||||
|
|
||||||
|
* Add tint operation to set image chroma.
|
||||||
|
[#825](https://github.com/lovell/sharp/pull/825)
|
||||||
|
[@rikh42](https://github.com/rikh42)
|
||||||
|
|
||||||
|
* Add environment variable to ignore globally-installed libvips.
|
||||||
|
[#1165](https://github.com/lovell/sharp/pull/1165)
|
||||||
|
[@oncletom](https://github.com/oncletom)
|
||||||
|
|
||||||
|
* Add support for page selection with multi-page input (GIF/TIFF).
|
||||||
|
[#1204](https://github.com/lovell/sharp/pull/1204)
|
||||||
|
[@woolite64](https://github.com/woolite64)
|
||||||
|
|
||||||
|
* Add support for Group4 (CCITTFAX4) compression with TIFF output.
|
||||||
|
[#1208](https://github.com/lovell/sharp/pull/1208)
|
||||||
|
[@woolite64](https://github.com/woolite64)
|
||||||
|
|
||||||
|
#### v0.20.1 - 17<sup>th</sup> March 2018
|
||||||
|
|
||||||
|
* Improve installation experience when a globally-installed libvips below the minimum required version is found.
|
||||||
|
[#1148](https://github.com/lovell/sharp/issues/1148)
|
||||||
|
|
||||||
|
* Prevent smartcrop error when cumulative rounding is below target size.
|
||||||
|
[#1154](https://github.com/lovell/sharp/issues/1154)
|
||||||
|
[@ralrom](https://github.com/ralrom)
|
||||||
|
|
||||||
|
* Expose libvips' median filter operation.
|
||||||
|
[#1161](https://github.com/lovell/sharp/pull/1161)
|
||||||
|
[@BiancoA](https://github.com/BiancoA)
|
||||||
|
|
||||||
#### v0.20.0 - 5<sup>th</sup> March 2018
|
#### v0.20.0 - 5<sup>th</sup> March 2018
|
||||||
|
|
||||||
* Add support for prebuilt sharp binaries on common platforms.
|
* Add support for prebuilt sharp binaries on common platforms.
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ As well as image resizing, operations such as
|
|||||||
rotation, extraction, compositing and gamma correction are available.
|
rotation, extraction, compositing and gamma correction are available.
|
||||||
|
|
||||||
Most 64-bit OS X, Windows and Linux (glibc) systems running
|
Most 64-bit OS X, Windows and Linux (glibc) systems running
|
||||||
Node versions 4, 6, 8 and 9
|
Node versions 4, 6, 8 and 10
|
||||||
do not require any additional install or runtime dependencies.
|
do not require any additional install or runtime dependencies.
|
||||||
|
|
||||||
[](https://coveralls.io/r/lovell/sharp?branch=master)
|
[](https://coveralls.io/r/lovell/sharp?branch=master)
|
||||||
@@ -109,6 +109,9 @@ the help and code contributions of the following people:
|
|||||||
* [Oleh Aleinyk](https://github.com/oaleynik)
|
* [Oleh Aleinyk](https://github.com/oaleynik)
|
||||||
* [Marcel Bretschneider](https://github.com/3epnm)
|
* [Marcel Bretschneider](https://github.com/3epnm)
|
||||||
* [Andrea Bianco](https://github.com/BiancoA)
|
* [Andrea Bianco](https://github.com/BiancoA)
|
||||||
|
* [Rik Heywood](https://github.com/rikh42)
|
||||||
|
* [Thomas Parisot](https://github.com/oncletom)
|
||||||
|
* [Nathan Graves](https://github.com/woolite64)
|
||||||
|
|
||||||
Thank you!
|
Thank you!
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ yarn add sharp
|
|||||||
### Building from source
|
### Building from source
|
||||||
|
|
||||||
Pre-compiled binaries for sharp are provided for use with
|
Pre-compiled binaries for sharp are provided for use with
|
||||||
Node versions 4, 6, 8 and 9 on
|
Node versions 4, 6, 8 and 10 on
|
||||||
64-bit Windows, OS X and Linux platforms.
|
64-bit Windows, OS X and Linux platforms.
|
||||||
|
|
||||||
Sharp will be built from source at install time when:
|
Sharp will be built from source at install time when:
|
||||||
@@ -54,7 +54,7 @@ To use a globally-installed version of libvips instead of the provided binaries,
|
|||||||
make sure it is at least the version listed under `config.libvips` in the `package.json` file
|
make sure it is at least the version listed under `config.libvips` in the `package.json` file
|
||||||
and that it can be located using `pkg-config --modversion vips-cpp`.
|
and that it can be located using `pkg-config --modversion vips-cpp`.
|
||||||
|
|
||||||
If you are using non-stadard paths (anything other than `/usr` or `/usr/local`),
|
If you are using non-standard paths (anything other than `/usr` or `/usr/local`),
|
||||||
you might need to set `PKG_CONFIG_PATH` during `npm install`
|
you might need to set `PKG_CONFIG_PATH` during `npm install`
|
||||||
and `LD_LIBRARY_PATH` at runtime.
|
and `LD_LIBRARY_PATH` at runtime.
|
||||||
|
|
||||||
@@ -161,6 +161,18 @@ Set the Lambda runtime to Node.js 6.10.
|
|||||||
|
|
||||||
To get the best performance select the largest memory available. A 1536 MB function provides ~12x more CPU time than a 128 MB function.
|
To get the best performance select the largest memory available. A 1536 MB function provides ~12x more CPU time than a 128 MB function.
|
||||||
|
|
||||||
|
### NW.js
|
||||||
|
|
||||||
|
Run the `nw-gyp` tool after installation.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cd node-modules/sharp
|
||||||
|
nw-gyp rebuild --arch=x64 --target=[your nw version]
|
||||||
|
node node_modules/sharp/install/dll-copy
|
||||||
|
```
|
||||||
|
|
||||||
|
See also http://docs.nwjs.io/en/latest/For%20Users/Advanced/Use%20Native%20Node%20Modules/
|
||||||
|
|
||||||
### Build tools
|
### Build tools
|
||||||
|
|
||||||
* [gulp-responsive](https://www.npmjs.com/package/gulp-responsive)
|
* [gulp-responsive](https://www.npmjs.com/package/gulp-responsive)
|
||||||
@@ -211,10 +223,17 @@ to the directory containing the `policy.xml` file.
|
|||||||
|
|
||||||
### Pre-compiled libvips binaries
|
### Pre-compiled libvips binaries
|
||||||
|
|
||||||
If a global installation of libvips that meets the
|
This module will attempt to download a pre-compiled bundle of libvips
|
||||||
minimum version requirement cannot be found,
|
and its dependencies on Linux and Windows machines under either of these
|
||||||
this module will attempt to download a pre-compiled bundle of libvips
|
conditions:
|
||||||
and its dependencies on Linux and Windows machines.
|
|
||||||
|
1. If a global installation of libvips that meets the
|
||||||
|
minimum version requirement cannot be found;
|
||||||
|
1. If `SHARP_IGNORE_GLOBAL_LIBVIPS` environment variable is set.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install sharp
|
||||||
|
```
|
||||||
|
|
||||||
Should you need to manually download and inspect these files,
|
Should you need to manually download and inspect these files,
|
||||||
you can do so via https://github.com/lovell/sharp-libvips/releases
|
you can do so via https://github.com/lovell/sharp-libvips/releases
|
||||||
|
|||||||
@@ -18,8 +18,9 @@ const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
|
|||||||
const distBaseUrl = process.env.SHARP_DIST_BASE_URL || `https://github.com/lovell/sharp-libvips/releases/download/v${minimumLibvipsVersion}/`;
|
const distBaseUrl = process.env.SHARP_DIST_BASE_URL || `https://github.com/lovell/sharp-libvips/releases/download/v${minimumLibvipsVersion}/`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const globalLibvipsVersion = libvips.globalLibvipsVersion();
|
const useGlobalLibvips = libvips.useGlobalLibvips();
|
||||||
if (globalLibvipsVersion) {
|
if (useGlobalLibvips) {
|
||||||
|
const globalLibvipsVersion = libvips.globalLibvipsVersion();
|
||||||
npmLog.info('sharp', `Detected globally-installed libvips v${globalLibvipsVersion}`);
|
npmLog.info('sharp', `Detected globally-installed libvips v${globalLibvipsVersion}`);
|
||||||
npmLog.info('sharp', 'Building from source via node-gyp');
|
npmLog.info('sharp', 'Building from source via node-gyp');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
@@ -28,6 +29,9 @@ try {
|
|||||||
} else {
|
} else {
|
||||||
// Is this arch/platform supported?
|
// Is this arch/platform supported?
|
||||||
const arch = process.env.npm_config_arch || process.arch;
|
const arch = process.env.npm_config_arch || process.arch;
|
||||||
|
if (platform() === 'win32-ia32') {
|
||||||
|
throw new Error('Windows x86 (32-bit) node.exe is not supported');
|
||||||
|
}
|
||||||
if (arch === 'ia32') {
|
if (arch === 'ia32') {
|
||||||
throw new Error(`Intel Architecture 32-bit systems require manual installation of libvips >= ${minimumLibvipsVersion}\n`);
|
throw new Error(`Intel Architecture 32-bit systems require manual installation of libvips >= ${minimumLibvipsVersion}\n`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,21 @@ function background (rgba) {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @param {String|Object} rgb - parsed by the [color](https://www.npmjs.org/package/color) module to extract chroma values.
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameter
|
||||||
|
*/
|
||||||
|
function tint (rgb) {
|
||||||
|
const colour = color(rgb);
|
||||||
|
this.options.tintA = colour.a();
|
||||||
|
this.options.tintB = colour.b();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
@@ -95,6 +110,7 @@ module.exports = function (Sharp) {
|
|||||||
// Public instance functions
|
// Public instance functions
|
||||||
[
|
[
|
||||||
background,
|
background,
|
||||||
|
tint,
|
||||||
greyscale,
|
greyscale,
|
||||||
grayscale,
|
grayscale,
|
||||||
toColourspace,
|
toColourspace,
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ const debuglog = util.debuglog('sharp');
|
|||||||
* 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.
|
* if you'd rather halt processing and raise an error when loading invalid images.
|
||||||
* @param {Number} [options.density=72] - integral number representing the DPI for vector images.
|
* @param {Number} [options.density=72] - integral number representing the DPI for vector images.
|
||||||
|
* @param {Number} [options.page=0] - page number to extract for multi-page input (GIF, TIFF)
|
||||||
* @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
|
* @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
|
||||||
* @param {Number} [options.raw.width]
|
* @param {Number} [options.raw.width]
|
||||||
* @param {Number} [options.raw.height]
|
* @param {Number} [options.raw.height]
|
||||||
@@ -151,8 +152,11 @@ const Sharp = function (input, options) {
|
|||||||
fastShrinkOnLoad: true,
|
fastShrinkOnLoad: true,
|
||||||
// operations
|
// operations
|
||||||
background: [0, 0, 0, 255],
|
background: [0, 0, 0, 255],
|
||||||
|
tintA: 128,
|
||||||
|
tintB: 128,
|
||||||
flatten: false,
|
flatten: false,
|
||||||
negate: false,
|
negate: false,
|
||||||
|
medianSize: 0,
|
||||||
blurSigma: 0,
|
blurSigma: 0,
|
||||||
sharpenSigma: 0,
|
sharpenSigma: 0,
|
||||||
sharpenFlat: 1,
|
sharpenFlat: 1,
|
||||||
|
|||||||
@@ -57,6 +57,12 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
|||||||
throw new Error('Expected width, height and channels for raw pixel input');
|
throw new Error('Expected width, height and channels for raw pixel input');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Page input for multi-page TIFF
|
||||||
|
if (is.defined(inputOptions.page)) {
|
||||||
|
if (is.integer(inputOptions.page) && is.inRange(inputOptions.page, 0, 100000)) {
|
||||||
|
inputDescriptor.page = inputOptions.page;
|
||||||
|
}
|
||||||
|
}
|
||||||
// Create new image
|
// Create new image
|
||||||
if (is.defined(inputOptions.create)) {
|
if (is.defined(inputOptions.create)) {
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ const pkgConfigPath = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const useGlobalLibvips = function () {
|
const useGlobalLibvips = function () {
|
||||||
|
if (Boolean(process.env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const globalVipsVersion = globalLibvipsVersion();
|
const globalVipsVersion = globalLibvipsVersion();
|
||||||
return !!globalVipsVersion && semver.gte(globalVipsVersion, minimumLibvipsVersion);
|
return !!globalVipsVersion && semver.gte(globalVipsVersion, minimumLibvipsVersion);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -156,6 +156,26 @@ function sharpen (sigma, flat, jagged) {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply median filter.
|
||||||
|
* When used without parameters the default window is 3x3.
|
||||||
|
* @param {Number} [size=3] square mask size: size x size
|
||||||
|
* @returns {Sharp}
|
||||||
|
* @throws {Error} Invalid parameters
|
||||||
|
*/
|
||||||
|
function median (size) {
|
||||||
|
if (!is.defined(size)) {
|
||||||
|
// No arguments: default to 3x3
|
||||||
|
this.options.medianSize = 3;
|
||||||
|
} else if (is.integer(size) && is.inRange(size, 1, 1000)) {
|
||||||
|
// Numeric argument: specific sigma
|
||||||
|
this.options.medianSize = size;
|
||||||
|
} else {
|
||||||
|
throw new Error('Invalid median size ' + size);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blur the image.
|
* 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.
|
||||||
@@ -444,6 +464,7 @@ module.exports = function (Sharp) {
|
|||||||
flip,
|
flip,
|
||||||
flop,
|
flop,
|
||||||
sharpen,
|
sharpen,
|
||||||
|
median,
|
||||||
blur,
|
blur,
|
||||||
extend,
|
extend,
|
||||||
flatten,
|
flatten,
|
||||||
|
|||||||
@@ -12,6 +12,16 @@ const sharp = require('../build/Release/sharp.node');
|
|||||||
*
|
*
|
||||||
* A `Promise` is returned when `callback` is not provided.
|
* A `Promise` is returned when `callback` is not provided.
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
|
* sharp(input)
|
||||||
|
* .toFile('output.png', (err, info) => { ... });
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* sharp(input)
|
||||||
|
* .toFile('output.png')
|
||||||
|
* .then(info => { ... })
|
||||||
|
* .catch(err => { ... });
|
||||||
|
*
|
||||||
* @param {String} fileOut - the path to write the image data to.
|
* @param {String} fileOut - the path to write the image data to.
|
||||||
* @param {Function} [callback] - called on completion with two arguments `(err, info)`.
|
* @param {Function} [callback] - 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`,
|
||||||
@@ -58,6 +68,22 @@ function toFile (fileOut, callback) {
|
|||||||
*
|
*
|
||||||
* A `Promise` is returned when `callback` is not provided.
|
* A `Promise` is returned when `callback` is not provided.
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
|
* sharp(input)
|
||||||
|
* .toBuffer((err, data, info) => { ... });
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* sharp(input)
|
||||||
|
* .toBuffer()
|
||||||
|
* .then(data => { ... })
|
||||||
|
* .catch(err => { ... });
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* sharp(input)
|
||||||
|
* .toBuffer({ resolveWithObject: true })
|
||||||
|
* .then(({ data, info }) => { ... })
|
||||||
|
* .catch(err => { ... });
|
||||||
|
*
|
||||||
* @param {Object} [options]
|
* @param {Object} [options]
|
||||||
* @param {Boolean} [options.resolveWithObject] Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
* @param {Boolean} [options.resolveWithObject] Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
||||||
* @param {Function} [callback]
|
* @param {Function} [callback]
|
||||||
@@ -76,6 +102,13 @@ function toBuffer (options, callback) {
|
|||||||
* 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.
|
||||||
* 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.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* sharp('input.jpg')
|
||||||
|
* .withMetadata()
|
||||||
|
* .toFile('output-with-metadata.jpg')
|
||||||
|
* .then(info => { ... });
|
||||||
|
*
|
||||||
* @param {Object} [withMetadata]
|
* @param {Object} [withMetadata]
|
||||||
* @param {Number} [withMetadata.orientation] value between 1 and 8, used to update the EXIF `Orientation` tag.
|
* @param {Number} [withMetadata.orientation] value between 1 and 8, used to update the EXIF `Orientation` tag.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
@@ -97,6 +130,16 @@ function withMetadata (withMetadata) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Use these JPEG options for output image.
|
* Use these JPEG options for output image.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Convert any input to very high quality JPEG output
|
||||||
|
* const data = await sharp(input)
|
||||||
|
* .jpeg({
|
||||||
|
* quality: 100,
|
||||||
|
* chromaSubsampling: '4:4:4'
|
||||||
|
* })
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
* @param {Object} [options] - output options
|
* @param {Object} [options] - output options
|
||||||
* @param {Number} [options.quality=80] - quality, integer 1-100
|
* @param {Number} [options.quality=80] - quality, integer 1-100
|
||||||
* @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
|
* @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
|
||||||
@@ -148,6 +191,16 @@ function jpeg (options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Use these PNG options for output image.
|
* Use these PNG options for output image.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Convert any input to PNG output
|
||||||
|
* const data = await sharp(input)
|
||||||
|
* .png()
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
* @param {Object} [options]
|
* @param {Object} [options]
|
||||||
* @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
|
* @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
|
||||||
* @param {Number} [options.compressionLevel=9] - zlib compression level, 0-9
|
* @param {Number} [options.compressionLevel=9] - zlib compression level, 0-9
|
||||||
@@ -177,6 +230,13 @@ function png (options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Use these WebP options for output image.
|
* Use these WebP options for output image.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Convert any input to lossless WebP output
|
||||||
|
* const data = await sharp(input)
|
||||||
|
* .webp({ lossless: true })
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
* @param {Object} [options] - output options
|
* @param {Object} [options] - output options
|
||||||
* @param {Number} [options.quality=80] - quality, integer 1-100
|
* @param {Number} [options.quality=80] - quality, integer 1-100
|
||||||
* @param {Number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100
|
* @param {Number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100
|
||||||
@@ -212,10 +272,21 @@ function webp (options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Use these TIFF options for output image.
|
* Use these TIFF options for output image.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Convert SVG input to LZW-compressed, 1 bit per pixel TIFF output
|
||||||
|
* sharp('input.svg')
|
||||||
|
* .tiff({
|
||||||
|
* compression: 'lzw',
|
||||||
|
* squash: true
|
||||||
|
* })
|
||||||
|
* .toFile('1-bpp-output.tiff')
|
||||||
|
* .then(info => { ... });
|
||||||
|
*
|
||||||
* @param {Object} [options] - output options
|
* @param {Object} [options] - output options
|
||||||
* @param {Number} [options.quality=80] - quality, integer 1-100
|
* @param {Number} [options.quality=80] - quality, integer 1-100
|
||||||
* @param {Boolean} [options.force=true] - force TIFF output, otherwise attempt to use input format
|
* @param {Boolean} [options.force=true] - force TIFF output, otherwise attempt to use input format
|
||||||
* @param {Boolean} [options.compression='jpeg'] - compression options: lzw, deflate, jpeg
|
* @param {Boolean} [options.compression='jpeg'] - compression options: lzw, deflate, jpeg, ccittfax4
|
||||||
* @param {Boolean} [options.predictor='horizontal'] - compression predictor options: none, horizontal, float
|
* @param {Boolean} [options.predictor='horizontal'] - compression predictor options: none, horizontal, float
|
||||||
* @param {Number} [options.xres=1.0] - horizontal resolution in pixels/mm
|
* @param {Number} [options.xres=1.0] - horizontal resolution in pixels/mm
|
||||||
* @param {Number} [options.yres=1.0] - vertical resolution in pixels/mm
|
* @param {Number} [options.yres=1.0] - vertical resolution in pixels/mm
|
||||||
@@ -255,10 +326,10 @@ function tiff (options) {
|
|||||||
}
|
}
|
||||||
// compression
|
// compression
|
||||||
if (is.defined(options) && is.defined(options.compression)) {
|
if (is.defined(options) && is.defined(options.compression)) {
|
||||||
if (is.string(options.compression) && is.inArray(options.compression, ['lzw', 'deflate', 'jpeg', 'none'])) {
|
if (is.string(options.compression) && is.inArray(options.compression, ['lzw', 'deflate', 'jpeg', 'ccittfax4', 'none'])) {
|
||||||
this.options.tiffCompression = options.compression;
|
this.options.tiffCompression = options.compression;
|
||||||
} else {
|
} else {
|
||||||
const message = `Invalid compression option "${options.compression}". Should be one of: lzw, deflate, jpeg, none`;
|
const message = `Invalid compression option "${options.compression}". Should be one of: lzw, deflate, jpeg, ccittfax4, none`;
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -276,6 +347,13 @@ function tiff (options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Force output to be raw, uncompressed uint8 pixel data.
|
* Force output to be raw, uncompressed uint8 pixel data.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Extract raw RGB pixel data from JPEG input
|
||||||
|
* const { data, info } = await sharp('input.jpg')
|
||||||
|
* .raw()
|
||||||
|
* .toBuffer({ resolveWithObject: true });
|
||||||
|
*
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
*/
|
*/
|
||||||
function raw () {
|
function raw () {
|
||||||
@@ -284,6 +362,13 @@ function raw () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Force output to a given format.
|
* Force output to a given format.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Convert any input to PNG output
|
||||||
|
* const data = await sharp(input)
|
||||||
|
* .toFormat('png')
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
* @param {(String|Object)} format - as a String or an Object with an 'id' attribute
|
* @param {(String|Object)} format - as a String or an Object with an 'id' attribute
|
||||||
* @param {Object} options - output options
|
* @param {Object} options - output options
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
@@ -305,6 +390,8 @@ function toFormat (format, options) {
|
|||||||
* 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.
|
||||||
* Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed archive file format.
|
* Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed archive file format.
|
||||||
*
|
*
|
||||||
|
* Warning: multiple sharp instances concurrently producing tile output can expose a possible race condition in some versions of libgsf.
|
||||||
|
*
|
||||||
* @example
|
* @example
|
||||||
* sharp('input.tiff')
|
* sharp('input.tiff')
|
||||||
* .png()
|
* .png()
|
||||||
|
|||||||
33
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "sharp",
|
"name": "sharp",
|
||||||
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP and TIFF images",
|
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP and TIFF images",
|
||||||
"version": "0.20.0",
|
"version": "0.20.4",
|
||||||
"author": "Lovell Fuller <npm@lovell.info>",
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
"homepage": "https://github.com/lovell/sharp",
|
"homepage": "https://github.com/lovell/sharp",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
@@ -45,7 +45,10 @@
|
|||||||
"Kenric D'Souza <kenric.dsouza@gmail.com>",
|
"Kenric D'Souza <kenric.dsouza@gmail.com>",
|
||||||
"Oleh Aleinyk <oleg.aleynik@gmail.com>",
|
"Oleh Aleinyk <oleg.aleynik@gmail.com>",
|
||||||
"Marcel Bretschneider <marcel.bretschneider@gmail.com>",
|
"Marcel Bretschneider <marcel.bretschneider@gmail.com>",
|
||||||
"Andrea Bianco <andrea.bianco@unibas.ch>"
|
"Andrea Bianco <andrea.bianco@unibas.ch>",
|
||||||
|
"Rik Heywood <rik@rik.org>",
|
||||||
|
"Thomas Parisot <hi@oncletom.io>",
|
||||||
|
"Nathan Graves <nathanrgraves+github@gmail.com>"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)",
|
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)",
|
||||||
@@ -79,28 +82,28 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"color": "^3.0.0",
|
"color": "^3.0.0",
|
||||||
"detect-libc": "^1.0.3",
|
"detect-libc": "^1.0.3",
|
||||||
"nan": "^2.9.2",
|
"nan": "^2.10.0",
|
||||||
"fs-copy-file-sync": "^1.0.1",
|
"fs-copy-file-sync": "^1.1.1",
|
||||||
"npmlog": "^4.1.2",
|
"npmlog": "^4.1.2",
|
||||||
"prebuild-install": "^2.5.1",
|
"prebuild-install": "^4.0.0",
|
||||||
"semver": "^5.5.0",
|
"semver": "^5.5.0",
|
||||||
"simple-get": "^2.7.0",
|
"simple-get": "^2.8.1",
|
||||||
"tar": "^4.4.0",
|
"tar": "^4.4.4",
|
||||||
"tunnel-agent": "^0.6.0"
|
"tunnel-agent": "^0.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^2.6.0",
|
"async": "^2.6.1",
|
||||||
"cc": "^1.0.1",
|
"cc": "^1.0.2",
|
||||||
"documentation": "^6.0.0",
|
"decompress-zip": "^0.3.1",
|
||||||
|
"documentation": "^8.0.0",
|
||||||
"exif-reader": "^1.0.2",
|
"exif-reader": "^1.0.2",
|
||||||
"icc": "^1.0.0",
|
"icc": "^1.0.0",
|
||||||
"mocha": "^5.0.1",
|
"mocha": "^5.2.0",
|
||||||
"nyc": "^11.5.0",
|
"nyc": "^12.0.2",
|
||||||
"prebuild": "^7.4.0",
|
"prebuild": "^7.6.0",
|
||||||
"prebuild-ci": "^2.2.3",
|
"prebuild-ci": "^2.2.3",
|
||||||
"rimraf": "^2.6.2",
|
"rimraf": "^2.6.2",
|
||||||
"semistandard": "^12.0.1",
|
"semistandard": "^12.0.1"
|
||||||
"unzip": "^0.1.11"
|
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"config": {
|
"config": {
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ namespace sharp {
|
|||||||
descriptor->rawWidth = AttrTo<uint32_t>(input, "rawWidth");
|
descriptor->rawWidth = AttrTo<uint32_t>(input, "rawWidth");
|
||||||
descriptor->rawHeight = AttrTo<uint32_t>(input, "rawHeight");
|
descriptor->rawHeight = AttrTo<uint32_t>(input, "rawHeight");
|
||||||
}
|
}
|
||||||
|
// Page input for multi-page TIFF
|
||||||
|
if (HasAttr(input, "page")) {
|
||||||
|
descriptor->page = AttrTo<uint32_t>(input, "page");
|
||||||
|
}
|
||||||
// Create new image
|
// Create new image
|
||||||
if (HasAttr(input, "createChannels")) {
|
if (HasAttr(input, "createChannels")) {
|
||||||
descriptor->createChannels = AttrTo<uint32_t>(input, "createChannels");
|
descriptor->createChannels = AttrTo<uint32_t>(input, "createChannels");
|
||||||
@@ -229,6 +233,9 @@ namespace sharp {
|
|||||||
if (imageType == ImageType::MAGICK) {
|
if (imageType == ImageType::MAGICK) {
|
||||||
option->set("density", std::to_string(descriptor->density).data());
|
option->set("density", std::to_string(descriptor->density).data());
|
||||||
}
|
}
|
||||||
|
if (imageType == ImageType::TIFF) {
|
||||||
|
option->set("page", descriptor->page);
|
||||||
|
}
|
||||||
image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);
|
image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);
|
||||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
||||||
SetDensity(image, descriptor->density);
|
SetDensity(image, descriptor->density);
|
||||||
@@ -268,6 +275,9 @@ namespace sharp {
|
|||||||
if (imageType == ImageType::MAGICK) {
|
if (imageType == ImageType::MAGICK) {
|
||||||
option->set("density", std::to_string(descriptor->density).data());
|
option->set("density", std::to_string(descriptor->density).data());
|
||||||
}
|
}
|
||||||
|
if (imageType == ImageType::TIFF) {
|
||||||
|
option->set("page", descriptor->page);
|
||||||
|
}
|
||||||
image = VImage::new_from_file(descriptor->file.data(), option);
|
image = VImage::new_from_file(descriptor->file.data(), option);
|
||||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
||||||
SetDensity(image, descriptor->density);
|
SetDensity(image, descriptor->density);
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ namespace sharp {
|
|||||||
int rawChannels;
|
int rawChannels;
|
||||||
int rawWidth;
|
int rawWidth;
|
||||||
int rawHeight;
|
int rawHeight;
|
||||||
|
int page;
|
||||||
int createChannels;
|
int createChannels;
|
||||||
int createWidth;
|
int createWidth;
|
||||||
int createHeight;
|
int createHeight;
|
||||||
@@ -66,6 +67,7 @@ namespace sharp {
|
|||||||
rawChannels(0),
|
rawChannels(0),
|
||||||
rawWidth(0),
|
rawWidth(0),
|
||||||
rawHeight(0),
|
rawHeight(0),
|
||||||
|
page(0),
|
||||||
createChannels(0),
|
createChannels(0),
|
||||||
createWidth(0),
|
createWidth(0),
|
||||||
createHeight(0) {
|
createHeight(0) {
|
||||||
|
|||||||
@@ -83,9 +83,9 @@ class MetadataWorker : public Nan::AsyncWorker {
|
|||||||
baton->iccLength = iccLength;
|
baton->iccLength = iccLength;
|
||||||
}
|
}
|
||||||
// IPTC
|
// IPTC
|
||||||
if (image.get_typeof(VIPS_META_IPCT_NAME) == VIPS_TYPE_BLOB) {
|
if (image.get_typeof(VIPS_META_IPTC_NAME) == VIPS_TYPE_BLOB) {
|
||||||
size_t iptcLength;
|
size_t iptcLength;
|
||||||
void const *iptc = image.get_blob(VIPS_META_IPCT_NAME, &iptcLength);
|
void const *iptc = image.get_blob(VIPS_META_IPTC_NAME, &iptcLength);
|
||||||
baton->iptc = static_cast<char *>(g_malloc(iptcLength));
|
baton->iptc = static_cast<char *>(g_malloc(iptcLength));
|
||||||
memcpy(baton->iptc, iptc, iptcLength);
|
memcpy(baton->iptc, iptc, iptcLength);
|
||||||
baton->iptcLength = iptcLength;
|
baton->iptcLength = iptcLength;
|
||||||
|
|||||||
@@ -152,6 +152,33 @@ namespace sharp {
|
|||||||
return dst.bandjoin(mask.cast(dst.format()));
|
return dst.bandjoin(mask.cast(dst.format()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tint an image using the specified chroma, preserving the original image luminance
|
||||||
|
*/
|
||||||
|
VImage Tint(VImage image, double const a, double const b) {
|
||||||
|
// Get original colourspace
|
||||||
|
VipsInterpretation typeBeforeTint = image.interpretation();
|
||||||
|
if (typeBeforeTint == VIPS_INTERPRETATION_RGB) {
|
||||||
|
typeBeforeTint = VIPS_INTERPRETATION_sRGB;
|
||||||
|
}
|
||||||
|
// Extract luminance
|
||||||
|
VImage luminance = image.colourspace(VIPS_INTERPRETATION_LAB)[0];
|
||||||
|
// Create the tinted version by combining the L from the original and the chroma from the tint
|
||||||
|
std::vector<double> chroma {a, b};
|
||||||
|
VImage tinted = luminance
|
||||||
|
.bandjoin(chroma)
|
||||||
|
.copy(VImage::option()->set("interpretation", VIPS_INTERPRETATION_LAB))
|
||||||
|
.colourspace(typeBeforeTint);
|
||||||
|
// Attach original alpha channel, if any
|
||||||
|
if (HasAlpha(image)) {
|
||||||
|
// Extract original alpha channel
|
||||||
|
VImage alpha = image[image.bands() - 1];
|
||||||
|
// Join alpha channel to normalised image
|
||||||
|
tinted = tinted.bandjoin(alpha);
|
||||||
|
}
|
||||||
|
return tinted;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stretch luminance to cover full dynamic range.
|
* Stretch luminance to cover full dynamic range.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -46,6 +46,11 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
VImage Cutout(VImage src, VImage dst, const int gravity);
|
VImage Cutout(VImage src, VImage dst, const int gravity);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tint an image using the specified chroma, preserving the original image luminance
|
||||||
|
*/
|
||||||
|
VImage Tint(VImage image, double const a, double const b);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stretch luminance to cover full dynamic range.
|
* Stretch luminance to cover full dynamic range.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -281,15 +281,17 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Recalculate integral shrink and double residual
|
// Recalculate integral shrink and double residual
|
||||||
int shrunkOnLoadWidth = image.width();
|
int const shrunkOnLoadWidth = image.width();
|
||||||
int shrunkOnLoadHeight = image.height();
|
int const shrunkOnLoadHeight = image.height();
|
||||||
if (!baton->rotateBeforePreExtract &&
|
if (!baton->rotateBeforePreExtract &&
|
||||||
(rotation == VIPS_ANGLE_D90 || rotation == VIPS_ANGLE_D270)) {
|
(rotation == VIPS_ANGLE_D90 || rotation == VIPS_ANGLE_D270)) {
|
||||||
// Swap input output width and height when rotating by 90 or 270 degrees
|
// Swap when rotating by 90 or 270 degrees
|
||||||
std::swap(shrunkOnLoadWidth, shrunkOnLoadHeight);
|
xfactor = static_cast<double>(shrunkOnLoadWidth) / static_cast<double>(targetResizeHeight);
|
||||||
|
yfactor = static_cast<double>(shrunkOnLoadHeight) / static_cast<double>(targetResizeWidth);
|
||||||
|
} else {
|
||||||
|
xfactor = static_cast<double>(shrunkOnLoadWidth) / static_cast<double>(targetResizeWidth);
|
||||||
|
yfactor = static_cast<double>(shrunkOnLoadHeight) / static_cast<double>(targetResizeHeight);
|
||||||
}
|
}
|
||||||
xfactor = static_cast<double>(shrunkOnLoadWidth) / static_cast<double>(targetResizeWidth);
|
|
||||||
yfactor = static_cast<double>(shrunkOnLoadHeight) / static_cast<double>(targetResizeHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we're using a device-independent colour space
|
// Ensure we're using a device-independent colour space
|
||||||
@@ -359,6 +361,8 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
bool const shouldBlur = baton->blurSigma != 0.0;
|
bool const shouldBlur = baton->blurSigma != 0.0;
|
||||||
bool const shouldConv = baton->convKernelWidth * baton->convKernelHeight > 0;
|
bool const shouldConv = baton->convKernelWidth * baton->convKernelHeight > 0;
|
||||||
bool const shouldSharpen = baton->sharpenSigma != 0.0;
|
bool const shouldSharpen = baton->sharpenSigma != 0.0;
|
||||||
|
bool const shouldApplyMedian = baton->medianSize > 0;
|
||||||
|
|
||||||
bool const shouldPremultiplyAlpha = HasAlpha(image) &&
|
bool const shouldPremultiplyAlpha = HasAlpha(image) &&
|
||||||
(shouldResize || shouldBlur || shouldConv || shouldSharpen || shouldOverlayWithAlpha);
|
(shouldResize || shouldBlur || shouldConv || shouldSharpen || shouldOverlayWithAlpha);
|
||||||
|
|
||||||
@@ -379,7 +383,6 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
) {
|
) {
|
||||||
throw vips::VError("Unknown kernel");
|
throw vips::VError("Unknown kernel");
|
||||||
}
|
}
|
||||||
|
|
||||||
image = image.resize(1.0 / xfactor, VImage::option()
|
image = image.resize(1.0 / xfactor, VImage::option()
|
||||||
->set("vscale", 1.0 / yfactor)
|
->set("vscale", 1.0 / yfactor)
|
||||||
->set("kernel", kernel));
|
->set("kernel", kernel));
|
||||||
@@ -482,6 +485,12 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
image = image.extract_area(left, top, width, height);
|
image = image.extract_area(left, top, width, height);
|
||||||
} else {
|
} else {
|
||||||
// Attention-based or Entropy-based crop
|
// Attention-based or Entropy-based crop
|
||||||
|
if (baton->width > image.width()) {
|
||||||
|
baton->width = image.width();
|
||||||
|
}
|
||||||
|
if (baton->height > image.height()) {
|
||||||
|
baton->height = image.height();
|
||||||
|
}
|
||||||
image = image.tilecache(VImage::option()
|
image = image.tilecache(VImage::option()
|
||||||
->set("access", baton->accessMethod)
|
->set("access", baton->accessMethod)
|
||||||
->set("threaded", TRUE));
|
->set("threaded", TRUE));
|
||||||
@@ -538,7 +547,10 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
image = image.embed(baton->extendLeft, baton->extendTop, baton->width, baton->height,
|
image = image.embed(baton->extendLeft, baton->extendTop, baton->width, baton->height,
|
||||||
VImage::option()->set("extend", VIPS_EXTEND_BACKGROUND)->set("background", background));
|
VImage::option()->set("extend", VIPS_EXTEND_BACKGROUND)->set("background", background));
|
||||||
}
|
}
|
||||||
|
// Median - must happen before blurring, due to the utility of blurring after thresholding
|
||||||
|
if (shouldApplyMedian) {
|
||||||
|
image = image.median(baton->medianSize);
|
||||||
|
}
|
||||||
// Threshold - must happen before blurring, due to the utility of blurring after thresholding
|
// Threshold - must happen before blurring, due to the utility of blurring after thresholding
|
||||||
if (baton->threshold != 0) {
|
if (baton->threshold != 0) {
|
||||||
image = sharp::Threshold(image, baton->threshold, baton->thresholdGrayscale);
|
image = sharp::Threshold(image, baton->threshold, baton->thresholdGrayscale);
|
||||||
@@ -671,13 +683,20 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
image = sharp::Bandbool(image, baton->bandBoolOp);
|
image = sharp::Bandbool(image, baton->bandBoolOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tint the image
|
||||||
|
if (baton->tintA < 128.0 || baton->tintB < 128.0) {
|
||||||
|
image = sharp::Tint(image, baton->tintA, baton->tintB);
|
||||||
|
}
|
||||||
|
|
||||||
// Extract an image channel (aka vips band)
|
// Extract an image channel (aka vips band)
|
||||||
if (baton->extractChannel > -1) {
|
if (baton->extractChannel > -1) {
|
||||||
if (baton->extractChannel >= image.bands()) {
|
if (baton->extractChannel >= image.bands()) {
|
||||||
(baton->err).append("Cannot extract channel from image. Too few channels in image.");
|
(baton->err).append("Cannot extract channel from image. Too few channels in image.");
|
||||||
return Error();
|
return Error();
|
||||||
}
|
}
|
||||||
image = image.extract_band(baton->extractChannel);
|
image = image
|
||||||
|
.extract_band(baton->extractChannel)
|
||||||
|
.copy(VImage::option()->set("interpretation", VIPS_INTERPRETATION_B_W));
|
||||||
}
|
}
|
||||||
// Convert image to sRGB, if not already
|
// Convert image to sRGB, if not already
|
||||||
if (sharp::Is16Bit(image.interpretation())) {
|
if (sharp::Is16Bit(image.interpretation())) {
|
||||||
@@ -1156,6 +1175,9 @@ NAN_METHOD(pipeline) {
|
|||||||
for (unsigned int i = 0; i < 4; i++) {
|
for (unsigned int i = 0; i < 4; i++) {
|
||||||
baton->background[i] = AttrTo<double>(background, i);
|
baton->background[i] = AttrTo<double>(background, i);
|
||||||
}
|
}
|
||||||
|
// Tint chroma
|
||||||
|
baton->tintA = AttrTo<double>(options, "tintA");
|
||||||
|
baton->tintB = AttrTo<double>(options, "tintB");
|
||||||
// Overlay options
|
// Overlay options
|
||||||
if (HasAttr(options, "overlay")) {
|
if (HasAttr(options, "overlay")) {
|
||||||
baton->overlay = CreateInputDescriptor(AttrAs<v8::Object>(options, "overlay"), buffersToPersist);
|
baton->overlay = CreateInputDescriptor(AttrAs<v8::Object>(options, "overlay"), buffersToPersist);
|
||||||
@@ -1188,6 +1210,7 @@ NAN_METHOD(pipeline) {
|
|||||||
baton->flatten = AttrTo<bool>(options, "flatten");
|
baton->flatten = AttrTo<bool>(options, "flatten");
|
||||||
baton->negate = AttrTo<bool>(options, "negate");
|
baton->negate = AttrTo<bool>(options, "negate");
|
||||||
baton->blurSigma = AttrTo<double>(options, "blurSigma");
|
baton->blurSigma = AttrTo<double>(options, "blurSigma");
|
||||||
|
baton->medianSize = AttrTo<uint32_t>(options, "medianSize");
|
||||||
baton->sharpenSigma = AttrTo<double>(options, "sharpenSigma");
|
baton->sharpenSigma = AttrTo<double>(options, "sharpenSigma");
|
||||||
baton->sharpenFlat = AttrTo<double>(options, "sharpenFlat");
|
baton->sharpenFlat = AttrTo<double>(options, "sharpenFlat");
|
||||||
baton->sharpenJagged = AttrTo<double>(options, "sharpenJagged");
|
baton->sharpenJagged = AttrTo<double>(options, "sharpenJagged");
|
||||||
|
|||||||
@@ -70,9 +70,12 @@ struct PipelineBaton {
|
|||||||
std::string kernel;
|
std::string kernel;
|
||||||
bool fastShrinkOnLoad;
|
bool fastShrinkOnLoad;
|
||||||
double background[4];
|
double background[4];
|
||||||
|
double tintA;
|
||||||
|
double tintB;
|
||||||
bool flatten;
|
bool flatten;
|
||||||
bool negate;
|
bool negate;
|
||||||
double blurSigma;
|
double blurSigma;
|
||||||
|
int medianSize;
|
||||||
double sharpenSigma;
|
double sharpenSigma;
|
||||||
double sharpenFlat;
|
double sharpenFlat;
|
||||||
double sharpenJagged;
|
double sharpenJagged;
|
||||||
@@ -154,9 +157,12 @@ struct PipelineBaton {
|
|||||||
cropOffsetLeft(0),
|
cropOffsetLeft(0),
|
||||||
cropOffsetTop(0),
|
cropOffsetTop(0),
|
||||||
premultiplied(false),
|
premultiplied(false),
|
||||||
|
tintA(128.0),
|
||||||
|
tintB(128.0),
|
||||||
flatten(false),
|
flatten(false),
|
||||||
negate(false),
|
negate(false),
|
||||||
blurSigma(0.0),
|
blurSigma(0.0),
|
||||||
|
medianSize(0),
|
||||||
sharpenSigma(0.0),
|
sharpenSigma(0.0),
|
||||||
sharpenFlat(1.0),
|
sharpenFlat(1.0),
|
||||||
sharpenJagged(2.0),
|
sharpenJagged(2.0),
|
||||||
|
|||||||
BIN
test/fixtures/2569067123_aca715a2ee_o.png
vendored
Normal file
|
After Width: | Height: | Size: 6.8 MiB |
BIN
test/fixtures/G31D_MULTI.TIF
vendored
Normal file
BIN
test/fixtures/expected/extract-lch.jpg
vendored
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
test/fixtures/expected/median_1.jpg
vendored
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
test/fixtures/expected/median_3.jpg
vendored
Normal file
|
After Width: | Height: | Size: 833 B |
BIN
test/fixtures/expected/median_5.jpg
vendored
Normal file
|
After Width: | Height: | Size: 640 B |
BIN
test/fixtures/expected/median_color.jpg
vendored
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
test/fixtures/expected/tint-alpha.png
vendored
Normal file
|
After Width: | Height: | Size: 142 KiB |
BIN
test/fixtures/expected/tint-blue.jpg
vendored
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
test/fixtures/expected/tint-cmyk.jpg
vendored
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
test/fixtures/expected/tint-green.jpg
vendored
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
test/fixtures/expected/tint-red.jpg
vendored
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
test/fixtures/expected/tint-sepia.jpg
vendored
Normal file
|
After Width: | Height: | Size: 14 KiB |
4
test/fixtures/index.js
vendored
@@ -69,6 +69,8 @@ module.exports = {
|
|||||||
inputJpgOverlayLayer2: getPath('alpha-layer-2-ink.jpg'),
|
inputJpgOverlayLayer2: getPath('alpha-layer-2-ink.jpg'),
|
||||||
inputJpgTruncated: getPath('truncated.jpg'), // head -c 10000 2569067123_aca715a2ee_o.jpg > truncated.jpg
|
inputJpgTruncated: getPath('truncated.jpg'), // head -c 10000 2569067123_aca715a2ee_o.jpg > truncated.jpg
|
||||||
inputJpgCenteredImage: getPath('centered_image.jpeg'),
|
inputJpgCenteredImage: getPath('centered_image.jpeg'),
|
||||||
|
inputJpgRandom: getPath('random.jpg'), // convert -size 200x200 xc: +noise Random random.jpg
|
||||||
|
inputJpgThRandom: getPath('thRandom.jpg'), // convert random.jpg -channel G -threshold 5% -separate +channel -negate thRandom.jpg
|
||||||
|
|
||||||
inputPng: getPath('50020484-00001.png'), // http://c.searspartsdirect.com/lis_png/PLDM/50020484-00001.png
|
inputPng: getPath('50020484-00001.png'), // http://c.searspartsdirect.com/lis_png/PLDM/50020484-00001.png
|
||||||
inputPngWithTransparency: getPath('blackbug.png'), // public domain
|
inputPngWithTransparency: getPath('blackbug.png'), // public domain
|
||||||
@@ -87,10 +89,12 @@ module.exports = {
|
|||||||
inputPngTestJoinChannel: getPath('testJoinChannel.png'),
|
inputPngTestJoinChannel: getPath('testJoinChannel.png'),
|
||||||
inputPngTruncated: getPath('truncated.png'), // gm convert 2569067123_aca715a2ee_o.jpg -resize 320x240 saw.png ; head -c 10000 saw.png > truncated.png
|
inputPngTruncated: getPath('truncated.png'), // gm convert 2569067123_aca715a2ee_o.jpg -resize 320x240 saw.png ; head -c 10000 saw.png > truncated.png
|
||||||
inputPngEmbed: getPath('embedgravitybird.png'), // Released to sharp under a CC BY 4.0
|
inputPngEmbed: getPath('embedgravitybird.png'), // Released to sharp under a CC BY 4.0
|
||||||
|
inputPngRGBWithAlpha: getPath('2569067123_aca715a2ee_o.png'), // http://www.flickr.com/photos/grizdave/2569067123/ (same as inputJpg)
|
||||||
|
|
||||||
inputWebP: getPath('4.webp'), // http://www.gstatic.com/webp/gallery/4.webp
|
inputWebP: getPath('4.webp'), // http://www.gstatic.com/webp/gallery/4.webp
|
||||||
inputWebPWithTransparency: getPath('5_webp_a.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp
|
inputWebPWithTransparency: getPath('5_webp_a.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp
|
||||||
inputTiff: getPath('G31D.TIF'), // http://www.fileformat.info/format/tiff/sample/e6c9a6e5253348f4aef6d17b534360ab/index.htm
|
inputTiff: getPath('G31D.TIF'), // http://www.fileformat.info/format/tiff/sample/e6c9a6e5253348f4aef6d17b534360ab/index.htm
|
||||||
|
inputTiffMultipage: getPath('G31D_MULTI.TIF'), // gm convert G31D.TIF -resize 50% G31D_2.TIF ; tiffcp G31D.TIF G31D_2.TIF G31D_MULTI.TIF
|
||||||
inputTiffCielab: getPath('cielab-dagams.tiff'), // https://github.com/lovell/sharp/issues/646
|
inputTiffCielab: getPath('cielab-dagams.tiff'), // https://github.com/lovell/sharp/issues/646
|
||||||
inputTiffUncompressed: getPath('uncompressed_tiff.tiff'), // https://code.google.com/archive/p/imagetestsuite/wikis/TIFFTestSuite.wiki file: 0c84d07e1b22b76f24cccc70d8788e4a.tif
|
inputTiffUncompressed: getPath('uncompressed_tiff.tiff'), // https://code.google.com/archive/p/imagetestsuite/wikis/TIFFTestSuite.wiki file: 0c84d07e1b22b76f24cccc70d8788e4a.tif
|
||||||
inputTiff8BitDepth: getPath('8bit_depth.tiff'),
|
inputTiff8BitDepth: getPath('8bit_depth.tiff'),
|
||||||
|
|||||||
BIN
test/fixtures/random.jpg
vendored
Normal file
|
After Width: | Height: | Size: 68 KiB |
BIN
test/fixtures/thRandom.jpg
vendored
Normal file
|
After Width: | Height: | Size: 26 KiB |
@@ -159,7 +159,7 @@ describe('Crop', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Skip crop when post-resize dimensions are at or below target dimensions', function () {
|
it('Skip crop when post-resize dimensions are at target', function () {
|
||||||
return sharp(fixtures.inputJpg)
|
return sharp(fixtures.inputJpg)
|
||||||
.resize(1600, 1200)
|
.resize(1600, 1200)
|
||||||
.toBuffer()
|
.toBuffer()
|
||||||
|
|||||||
@@ -54,6 +54,21 @@ describe('Image channel extraction', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('With colorspace conversion', function (done) {
|
||||||
|
const output = fixtures.path('output.extract-lch.jpg');
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.toColourspace('lch')
|
||||||
|
.extractChannel(1)
|
||||||
|
.resize(320, 240)
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(320, info.width);
|
||||||
|
assert.strictEqual(240, info.height);
|
||||||
|
fixtures.assertMaxColourDistance(output, fixtures.expected('extract-lch.jpg'));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Invalid channel number', function () {
|
it('Invalid channel number', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
|
|||||||
@@ -528,6 +528,22 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('TIFF file input with invalid page fails gracefully', function (done) {
|
||||||
|
sharp(fixtures.inputTiffMultipage, { page: 2 })
|
||||||
|
.toBuffer(function (err) {
|
||||||
|
assert.strictEqual(true, !!err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('TIFF buffer input with invalid page fails gracefully', function (done) {
|
||||||
|
sharp(fs.readFileSync(fixtures.inputTiffMultipage), { page: 2 })
|
||||||
|
.toBuffer(function (err) {
|
||||||
|
assert.strictEqual(true, !!err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Output filename with unknown extension', function () {
|
describe('Output filename with unknown extension', function () {
|
||||||
it('Match JPEG input', function (done) {
|
it('Match JPEG input', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@@ -880,6 +896,53 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Load multi-page TIFF\'s from file', function (done) {
|
||||||
|
sharp(fixtures.inputTiffMultipage) // defaults to page 0
|
||||||
|
.jpeg()
|
||||||
|
.toBuffer(function (err, defaultData, defaultInfo) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, defaultData.length > 0);
|
||||||
|
assert.strictEqual(defaultData.length, defaultInfo.size);
|
||||||
|
assert.strictEqual('jpeg', defaultInfo.format);
|
||||||
|
|
||||||
|
sharp(fixtures.inputTiffMultipage, { page: 1 }) // 50%-scale copy of page 0
|
||||||
|
.jpeg()
|
||||||
|
.toBuffer(function (err, scaledData, scaledInfo) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, scaledData.length > 0);
|
||||||
|
assert.strictEqual(scaledData.length, scaledInfo.size);
|
||||||
|
assert.strictEqual('jpeg', scaledInfo.format);
|
||||||
|
assert.strictEqual(defaultInfo.width, scaledInfo.width * 2);
|
||||||
|
assert.strictEqual(defaultInfo.height, scaledInfo.height * 2);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Load multi-page TIFF\'s from Buffer', function (done) {
|
||||||
|
const inputTiffBuffer = fs.readFileSync(fixtures.inputTiffMultipage);
|
||||||
|
sharp(inputTiffBuffer) // defaults to page 0
|
||||||
|
.jpeg()
|
||||||
|
.toBuffer(function (err, defaultData, defaultInfo) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, defaultData.length > 0);
|
||||||
|
assert.strictEqual(defaultData.length, defaultInfo.size);
|
||||||
|
assert.strictEqual('jpeg', defaultInfo.format);
|
||||||
|
|
||||||
|
sharp(inputTiffBuffer, { page: 1 }) // 50%-scale copy of page 0
|
||||||
|
.jpeg()
|
||||||
|
.toBuffer(function (err, scaledData, scaledInfo) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, scaledData.length > 0);
|
||||||
|
assert.strictEqual(scaledData.length, scaledInfo.size);
|
||||||
|
assert.strictEqual('jpeg', scaledInfo.format);
|
||||||
|
assert.strictEqual(defaultInfo.width, scaledInfo.width * 2);
|
||||||
|
assert.strictEqual(defaultInfo.height, scaledInfo.height * 2);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Save TIFF to Buffer', function (done) {
|
it('Save TIFF to Buffer', function (done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@@ -1020,6 +1083,22 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('TIFF ccittfax4 compression shrinks b-w test file', function (done) {
|
||||||
|
const startSize = fs.statSync(fixtures.inputTiff).size;
|
||||||
|
sharp(fixtures.inputTiff)
|
||||||
|
.toColourspace('b-w')
|
||||||
|
.tiff({
|
||||||
|
squash: true,
|
||||||
|
compression: 'ccittfax4'
|
||||||
|
})
|
||||||
|
.toFile(fixtures.outputTiff, (err, info) => {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('tiff', info.format);
|
||||||
|
assert(info.size < startSize);
|
||||||
|
fs.unlink(fixtures.outputTiff, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('TIFF deflate compression with horizontal predictor shrinks test file', function (done) {
|
it('TIFF deflate compression with horizontal predictor shrinks test file', function (done) {
|
||||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||||
sharp(fixtures.inputTiffUncompressed)
|
sharp(fixtures.inputTiffUncompressed)
|
||||||
|
|||||||
@@ -58,5 +58,13 @@ describe('libvips binaries', function () {
|
|||||||
const hasVendoredLibvips = libvips.hasVendoredLibvips();
|
const hasVendoredLibvips = libvips.hasVendoredLibvips();
|
||||||
assert.strictEqual('boolean', typeof hasVendoredLibvips);
|
assert.strictEqual('boolean', typeof hasVendoredLibvips);
|
||||||
});
|
});
|
||||||
|
it('useGlobalLibvips can be ignored via an env var', function () {
|
||||||
|
process.env.SHARP_IGNORE_GLOBAL_LIBVIPS = 1;
|
||||||
|
|
||||||
|
const useGlobalLibvips = libvips.useGlobalLibvips();
|
||||||
|
assert.strictEqual(false, useGlobalLibvips);
|
||||||
|
|
||||||
|
delete process.env.SHARP_IGNORE_GLOBAL_LIBVIPS;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
72
test/unit/median.js
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const sharp = require('../../');
|
||||||
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
|
describe('Median filter', function () {
|
||||||
|
it('1x1 window', function (done) {
|
||||||
|
sharp(fixtures.inputJpgThRandom)
|
||||||
|
.median(1)
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(200, info.width);
|
||||||
|
assert.strictEqual(200, info.height);
|
||||||
|
fixtures.assertSimilar(fixtures.expected('median_1.jpg'), data, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('3x3 window', function (done) {
|
||||||
|
sharp(fixtures.inputJpgThRandom)
|
||||||
|
.median(3)
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(200, info.width);
|
||||||
|
assert.strictEqual(200, info.height);
|
||||||
|
fixtures.assertSimilar(fixtures.expected('median_3.jpg'), data, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('5x5 window', function (done) {
|
||||||
|
sharp(fixtures.inputJpgThRandom)
|
||||||
|
.median(5)
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(200, info.width);
|
||||||
|
assert.strictEqual(200, info.height);
|
||||||
|
fixtures.assertSimilar(fixtures.expected('median_5.jpg'), data, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('color image', function (done) {
|
||||||
|
sharp(fixtures.inputJpgRandom)
|
||||||
|
.median(5)
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(200, info.width);
|
||||||
|
assert.strictEqual(200, info.height);
|
||||||
|
fixtures.assertSimilar(fixtures.expected('median_color.jpg'), data, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('no windows size', function (done) {
|
||||||
|
sharp(fixtures.inputJpgThRandom)
|
||||||
|
.median()
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('jpeg', info.format);
|
||||||
|
assert.strictEqual(200, info.width);
|
||||||
|
assert.strictEqual(200, info.height);
|
||||||
|
fixtures.assertSimilar(fixtures.expected('median_3.jpg'), data, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('invalid radius', function () {
|
||||||
|
assert.throws(function () {
|
||||||
|
sharp(fixtures.inputJpg).median(0.1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -130,6 +130,25 @@ describe('Resize dimensions', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('JPEG shrink-on-load with 90 degree rotation, ensure recalculation is correct', function (done) {
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.resize(1920, 1280)
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(1920, info.width);
|
||||||
|
assert.strictEqual(1280, info.height);
|
||||||
|
sharp(data)
|
||||||
|
.rotate(90)
|
||||||
|
.resize(533, 800)
|
||||||
|
.toBuffer(function (err, data, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(533, info.width);
|
||||||
|
assert.strictEqual(800, info.height);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('TIFF embed known to cause rounding errors', function (done) {
|
it('TIFF embed known to cause rounding errors', function (done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.resize(240, 320)
|
.resize(240, 320)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const assert = require('assert');
|
|||||||
|
|
||||||
const eachLimit = require('async/eachLimit');
|
const eachLimit = require('async/eachLimit');
|
||||||
const rimraf = require('rimraf');
|
const rimraf = require('rimraf');
|
||||||
const unzip = require('unzip');
|
const DecompressZip = require('decompress-zip');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
@@ -427,16 +427,14 @@ describe('Tile', function () {
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, stat.isFile());
|
assert.strictEqual(true, stat.isFile());
|
||||||
assert.strictEqual(true, stat.size > 0);
|
assert.strictEqual(true, stat.size > 0);
|
||||||
fs.createReadStream(container)
|
new DecompressZip(container)
|
||||||
.pipe(unzip.Extract({
|
.on('extract', function () {
|
||||||
path: path.dirname(extractTo)
|
assertDeepZoomTiles(directory, 256, 13, done);
|
||||||
}))
|
})
|
||||||
.on('error', function (err) {
|
.on('error', function (err) {
|
||||||
throw err;
|
throw err;
|
||||||
})
|
})
|
||||||
.on('close', function () {
|
.extract({ path: path.dirname(extractTo) });
|
||||||
assertDeepZoomTiles(directory, 256, 13, done);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -463,16 +461,14 @@ describe('Tile', function () {
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, stat.isFile());
|
assert.strictEqual(true, stat.isFile());
|
||||||
assert.strictEqual(true, stat.size > 0);
|
assert.strictEqual(true, stat.size > 0);
|
||||||
fs.createReadStream(container)
|
new DecompressZip(container)
|
||||||
.pipe(unzip.Extract({
|
.on('extract', function () {
|
||||||
path: path.dirname(extractTo)
|
assertDeepZoomTiles(directory, 256, 13, done);
|
||||||
}))
|
})
|
||||||
.on('error', function (err) {
|
.on('error', function (err) {
|
||||||
throw err;
|
throw err;
|
||||||
})
|
})
|
||||||
.on('close', function () {
|
.extract({ path: path.dirname(extractTo) });
|
||||||
assertDeepZoomTiles(directory, 256, 13, done);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
102
test/unit/tint.js
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const sharp = require('../../');
|
||||||
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
|
describe('Tint', function () {
|
||||||
|
it('tints rgb image red', function (done) {
|
||||||
|
const output = fixtures.path('output.tint-red.jpg');
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.tint('#FF0000')
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, info.size > 0);
|
||||||
|
fixtures.assertMaxColourDistance(output, fixtures.expected('tint-red.jpg'), 10);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tints rgb image green', function (done) {
|
||||||
|
const output = fixtures.path('output.tint-green.jpg');
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.tint('#00FF00')
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, info.size > 0);
|
||||||
|
fixtures.assertMaxColourDistance(output, fixtures.expected('tint-green.jpg'), 10);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tints rgb image blue', function (done) {
|
||||||
|
const output = fixtures.path('output.tint-blue.jpg');
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.tint('#0000FF')
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, info.size > 0);
|
||||||
|
fixtures.assertMaxColourDistance(output, fixtures.expected('tint-blue.jpg'), 10);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tints rgb image with sepia tone', function (done) {
|
||||||
|
const output = fixtures.path('output.tint-sepia.jpg');
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.tint('#704214')
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(320, info.width);
|
||||||
|
assert.strictEqual(240, info.height);
|
||||||
|
fixtures.assertMaxColourDistance(output, fixtures.expected('tint-sepia.jpg'), 10);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tints rgb image with sepia tone with rgb colour', function (done) {
|
||||||
|
const output = fixtures.path('output.tint-sepia.jpg');
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.tint([112, 66, 20])
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(320, info.width);
|
||||||
|
assert.strictEqual(240, info.height);
|
||||||
|
fixtures.assertMaxColourDistance(output, fixtures.expected('tint-sepia.jpg'), 10);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tints rgb image with alpha channel', function (done) {
|
||||||
|
const output = fixtures.path('output.tint-alpha.png');
|
||||||
|
sharp(fixtures.inputPngRGBWithAlpha)
|
||||||
|
.resize(320, 240)
|
||||||
|
.tint('#704214')
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(320, info.width);
|
||||||
|
assert.strictEqual(240, info.height);
|
||||||
|
fixtures.assertMaxColourDistance(output, fixtures.expected('tint-alpha.png'), 10);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tints cmyk image red', function (done) {
|
||||||
|
const output = fixtures.path('output.tint-cmyk.jpg');
|
||||||
|
sharp(fixtures.inputJpgWithCmykProfile)
|
||||||
|
.resize(320, 240)
|
||||||
|
.tint('#FF0000')
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, info.size > 0);
|
||||||
|
fixtures.assertMaxColourDistance(output, fixtures.expected('tint-cmyk.jpg'), 10);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||