mirror of
https://github.com/lovell/sharp.git
synced 2026-02-04 13:46:19 +01:00
Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5bed3a7d52 | ||
|
|
ece111280b | ||
|
|
a15a9b956b | ||
|
|
42860c2f83 | ||
|
|
b5b95e5ae1 | ||
|
|
d705cffdd6 | ||
|
|
23a4bc103e | ||
|
|
c14434f9e7 | ||
|
|
25bd2cea3e | ||
|
|
532de4ecab | ||
|
|
bfdd27eeef | ||
|
|
bd9f238ab4 | ||
|
|
75556bb57c | ||
|
|
2de062a34a | ||
|
|
4589b15dea | ||
|
|
8b75ce6786 | ||
|
|
7bbc5176a1 | ||
|
|
5cb35485f1 | ||
|
|
80189ed689 | ||
|
|
3d7e8ef432 | ||
|
|
1999c7103c | ||
|
|
9c20ae383e | ||
|
|
76c41eaf05 | ||
|
|
873aa6700f | ||
|
|
0d9590a9a0 | ||
|
|
94607b585a | ||
|
|
da0b0348a2 |
@@ -8,6 +8,7 @@ test
|
|||||||
.travis.yml
|
.travis.yml
|
||||||
appveyor.yml
|
appveyor.yml
|
||||||
mkdocs.yml
|
mkdocs.yml
|
||||||
|
docs/css/
|
||||||
vendor
|
vendor
|
||||||
.prebuildrc
|
.prebuildrc
|
||||||
.nyc_output
|
.nyc_output
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ sharp('input.jpg')
|
|||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const roundedCorners = new Buffer(
|
const roundedCorners = Buffer.from(
|
||||||
'<svg><rect x="0" y="0" width="200" height="200" rx="50" ry="50"/></svg>'
|
'<svg><rect x="0" y="0" width="200" height="200" rx="50" ry="50"/></svg>'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,30 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||||
|
|
||||||
### Table of Contents
|
## removeAlpha
|
||||||
|
|
||||||
- [extractChannel][1]
|
Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
|
||||||
- [joinChannel][2]
|
|
||||||
- [bandbool][3]
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
sharp('rgba.png')
|
||||||
|
.removeAlpha()
|
||||||
|
.toFile('rgb.png', function(err, info) {
|
||||||
|
// rgb.png is a 3 channel image without an alpha channel
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns **Sharp**
|
||||||
|
|
||||||
## 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][1] \| [String][2])** 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 +35,7 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][6]** Invalid channel
|
- Throws **[Error][3]** Invalid channel
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -42,13 +52,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][4]<([String][2] \| [Buffer][5])> | [String][2] \| [Buffer][5])** one or more images (file paths, Buffers).
|
||||||
- `options` **[Object][9]** image options, see `sharp()` constructor.
|
- `options` **[Object][6]** image options, see `sharp()` constructor.
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][6]** Invalid parameters
|
- Throws **[Error][3]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -56,11 +66,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][2]** 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 +82,18 @@ sharp('3-channel-rgb-input.png')
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][6]** Invalid parameters
|
- Throws **[Error][3]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
[1]: #extractchannel
|
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
[2]: #joinchannel
|
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
[3]: #bandbool
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
||||||
|
|
||||||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
[5]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
||||||
|
|
||||||
[8]: https://nodejs.org/api/buffer.html
|
|
||||||
|
|
||||||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
|||||||
@@ -1,14 +1,5 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||||
|
|
||||||
### Table of Contents
|
|
||||||
|
|
||||||
- [background][1]
|
|
||||||
- [tint][2]
|
|
||||||
- [greyscale][3]
|
|
||||||
- [grayscale][4]
|
|
||||||
- [toColourspace][5]
|
|
||||||
- [toColorspace][6]
|
|
||||||
|
|
||||||
## background
|
## background
|
||||||
|
|
||||||
Set the background for the `embed`, `flatten` and `extend` operations.
|
Set the background for the `embed`, `flatten` and `extend` operations.
|
||||||
@@ -18,12 +9,12 @@ Delegates to the _color_ module, which can throw an Error
|
|||||||
but is liberal in what it accepts, clipping values to sensible min/max.
|
but is liberal in what it accepts, clipping values to sensible min/max.
|
||||||
The alpha value is a float between `0` (transparent) and `1` (opaque).
|
The alpha value is a float between `0` (transparent) and `1` (opaque).
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `rgba` **([String][7] \| [Object][8])** parsed by the [color][9] module to extract values for red, green, blue and alpha.
|
- `rgba` **([String][1] \| [Object][2])** parsed by the [color][3] module to extract values for red, green, blue and alpha.
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][10]** Invalid parameter
|
- Throws **[Error][4]** Invalid parameter
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -32,12 +23,12 @@ Returns **Sharp**
|
|||||||
Tint the image using the provided chroma while preserving the image luminance.
|
Tint the image using the provided chroma while preserving the image luminance.
|
||||||
An alpha channel may be present and will be unchanged by the operation.
|
An alpha channel may be present and will be unchanged by the operation.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `rgb` **([String][7] \| [Object][8])** parsed by the [color][9] module to extract chroma values.
|
- `rgb` **([String][1] \| [Object][2])** parsed by the [color][3] module to extract chroma values.
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][10]** Invalid parameter
|
- Throws **[Error][4]** Invalid parameter
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -50,9 +41,9 @@ This may be overridden by other sharp operations such as `toColourspace('b-w')`,
|
|||||||
which will produce an output image containing one color channel.
|
which will produce an output image containing one color channel.
|
||||||
An alpha channel may be present, and will be unchanged by the operation.
|
An alpha channel may be present, and will be unchanged by the operation.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `greyscale` **[Boolean][11]** (optional, default `true`)
|
- `greyscale` **[Boolean][5]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -60,9 +51,9 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Alternative spelling of `greyscale`.
|
Alternative spelling of `greyscale`.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `grayscale` **[Boolean][11]** (optional, default `true`)
|
- `grayscale` **[Boolean][5]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -71,12 +62,12 @@ Returns **Sharp**
|
|||||||
Set the output colourspace.
|
Set the output colourspace.
|
||||||
By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
|
By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `colourspace` **[String][7]?** output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][12]
|
- `colourspace` **[String][1]?** output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][6]
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][10]** Invalid parameters
|
- Throws **[Error][4]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -84,35 +75,23 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Alternative spelling of `toColourspace`.
|
Alternative spelling of `toColourspace`.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `colorspace` **[String][7]?** output colorspace.
|
- `colorspace` **[String][1]?** output colorspace.
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][10]** Invalid parameters
|
- Throws **[Error][4]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
[1]: #background
|
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
[2]: #tint
|
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
[3]: #greyscale
|
[3]: https://www.npmjs.org/package/color
|
||||||
|
|
||||||
[4]: #grayscale
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
[5]: #tocolourspace
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
[6]: #tocolorspace
|
[6]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L568
|
||||||
|
|
||||||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
||||||
|
|
||||||
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
|
||||||
[9]: https://www.npmjs.org/package/color
|
|
||||||
|
|
||||||
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
||||||
|
|
||||||
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
||||||
|
|
||||||
[12]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L568
|
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||||
|
|
||||||
### Table of Contents
|
|
||||||
|
|
||||||
- [overlayWith][1]
|
|
||||||
|
|
||||||
## overlayWith
|
## overlayWith
|
||||||
|
|
||||||
Overlay (composite) an image over the processed (resized, extracted etc.) image.
|
Overlay (composite) an image over the processed (resized, extracted etc.) image.
|
||||||
@@ -13,27 +9,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][1] \| [String][2])** Buffer containing image data or String containing the path to an image file.
|
||||||
- `options` **[Object][4]?**
|
- `options` **[Object][3]?**
|
||||||
- `options.gravity` **[String][3]** gravity at which to place the overlay. (optional, default `'centre'`)
|
- `options.gravity` **[String][2]** gravity at which to place the overlay. (optional, default `'centre'`)
|
||||||
- `options.top` **[Number][5]?** the pixel offset from the top edge.
|
- `options.top` **[Number][4]?** the pixel offset from the top edge.
|
||||||
- `options.left` **[Number][5]?** the pixel offset from the left edge.
|
- `options.left` **[Number][4]?** 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][5]** 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][5]** 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][4]** 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][3]?** describes overlay when using raw pixel data.
|
||||||
- `options.raw.width` **[Number][5]?**
|
- `options.raw.width` **[Number][4]?**
|
||||||
- `options.raw.height` **[Number][5]?**
|
- `options.raw.height` **[Number][4]?**
|
||||||
- `options.raw.channels` **[Number][5]?**
|
- `options.raw.channels` **[Number][4]?**
|
||||||
- `options.create` **[Object][4]?** describes a blank overlay to be created.
|
- `options.create` **[Object][3]?** describes a blank overlay to be created.
|
||||||
- `options.create.width` **[Number][5]?**
|
- `options.create.width` **[Number][4]?**
|
||||||
- `options.create.height` **[Number][5]?**
|
- `options.create.height` **[Number][4]?**
|
||||||
- `options.create.channels` **[Number][5]?** 3-4
|
- `options.create.channels` **[Number][4]?** 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][2] \| [Object][3])?** parsed by the [color][6] module to extract values for red, green, blue and alpha.
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp('input.png')
|
sharp('input.png')
|
||||||
@@ -44,8 +40,7 @@ sharp('input.png')
|
|||||||
.overlayWith('overlay.png', { gravity: sharp.gravity.southeast } )
|
.overlayWith('overlay.png', { gravity: sharp.gravity.southeast } )
|
||||||
.sharpen()
|
.sharpen()
|
||||||
.withMetadata()
|
.withMetadata()
|
||||||
.quality(90)
|
.webp( { quality: 90 } )
|
||||||
.webp()
|
|
||||||
.toBuffer()
|
.toBuffer()
|
||||||
.then(function(outputBuffer) {
|
.then(function(outputBuffer) {
|
||||||
// outputBuffer contains upside down, 300px wide, alpha channel flattened
|
// outputBuffer contains upside down, 300px wide, alpha channel flattened
|
||||||
@@ -54,22 +49,20 @@ sharp('input.png')
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][8]** Invalid parameters
|
- Throws **[Error][7]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
[1]: #overlaywith
|
[1]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
[2]: https://nodejs.org/api/buffer.html
|
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
[6]: https://www.npmjs.org/package/color
|
||||||
|
|
||||||
[7]: https://www.npmjs.org/package/color
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
||||||
|
|||||||
@@ -1,37 +1,30 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||||
|
|
||||||
### Table of Contents
|
|
||||||
|
|
||||||
- [Sharp][1]
|
|
||||||
- [format][2]
|
|
||||||
- [versions][3]
|
|
||||||
- [queue][4]
|
|
||||||
|
|
||||||
## Sharp
|
## Sharp
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `input` **([Buffer][5] \| [String][6])?** if present, can be
|
- `input` **([Buffer][1] \| [String][2])?** 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][3]?** if present, is an Object with optional attributes.
|
||||||
- `options.failOnError` **[Boolean][8]** by default apply a "best effort"
|
- `options.failOnError` **[Boolean][4]** 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][5]** integral number representing the DPI for vector images. (optional, default `72`)
|
||||||
- `options.page` **[Number][9]** page number to extract for multi-page input (GIF, TIFF) (optional, default `0`)
|
- `options.page` **[Number][5]** page number to extract for multi-page input (GIF, TIFF) (optional, default `0`)
|
||||||
- `options.raw` **[Object][7]?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
- `options.raw` **[Object][3]?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
||||||
- `options.raw.width` **[Number][9]?**
|
- `options.raw.width` **[Number][5]?**
|
||||||
- `options.raw.height` **[Number][9]?**
|
- `options.raw.height` **[Number][5]?**
|
||||||
- `options.raw.channels` **[Number][9]?** 1-4
|
- `options.raw.channels` **[Number][5]?** 1-4
|
||||||
- `options.create` **[Object][7]?** describes a new image to be created.
|
- `options.create` **[Object][3]?** describes a new image to be created.
|
||||||
- `options.create.width` **[Number][9]?**
|
- `options.create.width` **[Number][5]?**
|
||||||
- `options.create.height` **[Number][9]?**
|
- `options.create.height` **[Number][5]?**
|
||||||
- `options.create.channels` **[Number][9]?** 3-4
|
- `options.create.channels` **[Number][5]?** 3-4
|
||||||
- `options.create.background` **([String][6] \| [Object][7])?** parsed by the [color][10] module to extract values for red, green, blue and alpha.
|
- `options.create.background` **([String][2] \| [Object][3])?** parsed by the [color][6] module to extract values for red, green, blue and alpha.
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp('input.jpg')
|
sharp('input.jpg')
|
||||||
@@ -62,7 +55,7 @@ sharp({
|
|||||||
width: 300,
|
width: 300,
|
||||||
height: 200,
|
height: 200,
|
||||||
channels: 4,
|
channels: 4,
|
||||||
background: { r: 255, g: 0, b: 0, alpha: 128 }
|
background: { r: 255, g: 0, b: 0, alpha: 0.5 }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.png()
|
.png()
|
||||||
@@ -70,27 +63,27 @@ sharp({
|
|||||||
.then( ... );
|
.then( ... );
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][11]** Invalid parameters
|
- Throws **[Error][7]** Invalid parameters
|
||||||
|
|
||||||
Returns **[Sharp][12]**
|
Returns **[Sharp][8]**
|
||||||
|
|
||||||
### 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][3]**
|
||||||
|
|
||||||
### versions
|
### versions
|
||||||
|
|
||||||
An Object containing the version numbers of libvips and its dependencies.
|
An Object containing the version numbers of libvips and its dependencies.
|
||||||
|
|
||||||
**Examples**
|
#### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
console.log(sharp.versions);
|
console.log(sharp.versions);
|
||||||
@@ -103,7 +96,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) {
|
||||||
@@ -111,26 +104,18 @@ sharp.queue.on('change', function(queueLength) {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
[1]: #sharp
|
[1]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
[2]: #format
|
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
[3]: #versions
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
[4]: #queue
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
[5]: https://nodejs.org/api/buffer.html
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
[6]: https://www.npmjs.org/package/color
|
||||||
|
|
||||||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
[8]: #sharp
|
||||||
|
|
||||||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
||||||
|
|
||||||
[10]: https://www.npmjs.org/package/color
|
|
||||||
|
|
||||||
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
||||||
|
|
||||||
[12]: #sharp
|
|
||||||
|
|||||||
@@ -1,20 +1,12 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||||
|
|
||||||
### Table of Contents
|
|
||||||
|
|
||||||
- [clone][1]
|
|
||||||
- [metadata][2]
|
|
||||||
- [stats][3]
|
|
||||||
- [limitInputPixels][4]
|
|
||||||
- [sequentialRead][5]
|
|
||||||
|
|
||||||
## clone
|
## clone
|
||||||
|
|
||||||
Take a "snapshot" of the Sharp instance, returning a new instance.
|
Take a "snapshot" of the Sharp instance, returning a new instance.
|
||||||
Cloned instances inherit the input of their parent instance.
|
Cloned instances inherit the input of their parent instance.
|
||||||
This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream.
|
This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream.
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const pipeline = sharp().rotate();
|
const pipeline = sharp().rotate();
|
||||||
@@ -35,23 +27,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` [...][1]
|
||||||
- `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` [...][2]
|
||||||
- `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][3] 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][4]?** called with the arguments `(err, metadata)`
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const image = sharp(inputJpg);
|
const image = sharp(inputJpg);
|
||||||
@@ -68,7 +60,7 @@ image
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **([Promise][10]<[Object][11]> | Sharp)**
|
Returns **([Promise][5]<[Object][6]> | Sharp)**
|
||||||
|
|
||||||
## stats
|
## stats
|
||||||
|
|
||||||
@@ -87,12 +79,13 @@ A Promise is returned when `callback` is not provided.
|
|||||||
- `maxX` (x-coordinate of one of the pixel where the maximum lies)
|
- `maxX` (x-coordinate of one of the pixel where the maximum lies)
|
||||||
- `maxY` (y-coordinate of one of the pixel where the maximum lies)
|
- `maxY` (y-coordinate of one of the pixel where the maximum lies)
|
||||||
- `isOpaque`: 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
|
||||||
|
- `entropy`: Histogram-based estimation of greyscale entropy, discarding alpha channel if any (experimental)
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `callback` **[Function][9]?** called with the arguments `(err, stats)`
|
- `callback` **[Function][4]?** called with the arguments `(err, stats)`
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const image = sharp(inputJpg);
|
const image = sharp(inputJpg);
|
||||||
@@ -103,7 +96,7 @@ image
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Promise][10]<[Object][11]>**
|
Returns **[Promise][5]<[Object][6]>**
|
||||||
|
|
||||||
## limitInputPixels
|
## limitInputPixels
|
||||||
|
|
||||||
@@ -111,12 +104,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][7] \| [Boolean][8])** an integral Number of pixels, zero or false to remove limit, true to use default limit.
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][14]** Invalid limit
|
- Throws **[Error][9]** Invalid limit
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -127,36 +120,26 @@ 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][8]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
[1]: #clone
|
[1]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L636
|
||||||
|
|
||||||
[2]: #metadata
|
[2]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L672
|
||||||
|
|
||||||
[3]: #stats
|
[3]: https://www.npmjs.com/package/icc
|
||||||
|
|
||||||
[4]: #limitinputpixels
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
|
||||||
|
|
||||||
[5]: #sequentialread
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
||||||
|
|
||||||
[6]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L636
|
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
[7]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L672
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
[8]: https://www.npmjs.com/package/icc
|
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
|
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
|
||||||
|
|
||||||
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
|
||||||
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
||||||
|
|
||||||
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
||||||
|
|
||||||
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
||||||
|
|||||||
@@ -1,26 +1,5 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||||
|
|
||||||
### Table of Contents
|
|
||||||
|
|
||||||
- [rotate][1]
|
|
||||||
- [extract][2]
|
|
||||||
- [flip][3]
|
|
||||||
- [flop][4]
|
|
||||||
- [sharpen][5]
|
|
||||||
- [median][6]
|
|
||||||
- [blur][7]
|
|
||||||
- [extend][8]
|
|
||||||
- [flatten][9]
|
|
||||||
- [trim][10]
|
|
||||||
- [gamma][11]
|
|
||||||
- [negate][12]
|
|
||||||
- [normalise][13]
|
|
||||||
- [normalize][14]
|
|
||||||
- [convolve][15]
|
|
||||||
- [threshold][16]
|
|
||||||
- [boolean][17]
|
|
||||||
- [linear][18]
|
|
||||||
|
|
||||||
## rotate
|
## rotate
|
||||||
|
|
||||||
Rotate the output image by either an explicit angle
|
Rotate the output image by either an explicit angle
|
||||||
@@ -37,11 +16,11 @@ The use of `rotate` implies the removal of the EXIF `Orientation` tag, if any.
|
|||||||
Method order is important when both rotating and extracting regions,
|
Method order is important when both rotating and extracting regions,
|
||||||
for example `rotate(x).extract(y)` will produce a different result to `extract(y).rotate(x)`.
|
for example `rotate(x).extract(y)` will produce a different result to `extract(y).rotate(x)`.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `angle` **[Number][19]** angle of rotation, must be a multiple of 90. (optional, default `auto`)
|
- `angle` **[Number][1]** angle of rotation, must be a multiple of 90. (optional, default `auto`)
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const pipeline = sharp()
|
const pipeline = sharp()
|
||||||
@@ -55,7 +34,7 @@ const pipeline = sharp()
|
|||||||
readableStream.pipe(pipeline);
|
readableStream.pipe(pipeline);
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][20]** Invalid parameters
|
- Throws **[Error][2]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -67,15 +46,15 @@ Extract a region of the image.
|
|||||||
- Use `extract` after `resize` for post-resize extraction.
|
- Use `extract` after `resize` for post-resize extraction.
|
||||||
- Use `extract` before and after for both.
|
- Use `extract` before and after for both.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][21]**
|
- `options` **[Object][3]**
|
||||||
- `options.left` **[Number][19]** zero-indexed offset from left edge
|
- `options.left` **[Number][1]** zero-indexed offset from left edge
|
||||||
- `options.top` **[Number][19]** zero-indexed offset from top edge
|
- `options.top` **[Number][1]** zero-indexed offset from top edge
|
||||||
- `options.width` **[Number][19]** dimension of extracted image
|
- `options.width` **[Number][1]** dimension of extracted image
|
||||||
- `options.height` **[Number][19]** dimension of extracted image
|
- `options.height` **[Number][1]** dimension of extracted image
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp(input)
|
sharp(input)
|
||||||
@@ -95,7 +74,7 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][20]** Invalid parameters
|
- Throws **[Error][2]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -104,9 +83,9 @@ Returns **Sharp**
|
|||||||
Flip the image about the vertical Y axis. This always occurs after rotation, if any.
|
Flip the image about the vertical Y axis. This always occurs after rotation, if any.
|
||||||
The use of `flip` implies the removal of the EXIF `Orientation` tag, if any.
|
The use of `flip` implies the removal of the EXIF `Orientation` tag, if any.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `flip` **[Boolean][22]** (optional, default `true`)
|
- `flip` **[Boolean][4]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -115,9 +94,9 @@ Returns **Sharp**
|
|||||||
Flop the image about the horizontal X axis. This always occurs after rotation, if any.
|
Flop the image about the horizontal X axis. This always occurs after rotation, if any.
|
||||||
The use of `flop` implies the removal of the EXIF `Orientation` tag, if any.
|
The use of `flop` implies the removal of the EXIF `Orientation` tag, if any.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `flop` **[Boolean][22]** (optional, default `true`)
|
- `flop` **[Boolean][4]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -128,14 +107,14 @@ When used without parameters, performs a fast, mild sharpen of the output image.
|
|||||||
When a `sigma` is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.
|
When a `sigma` is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.
|
||||||
Separate control over the level of sharpening in "flat" and "jagged" areas is available.
|
Separate control over the level of sharpening in "flat" and "jagged" areas is available.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `sigma` **[Number][19]?** the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
- `sigma` **[Number][1]?** the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
||||||
- `flat` **[Number][19]** the level of sharpening to apply to "flat" areas. (optional, default `1.0`)
|
- `flat` **[Number][1]** the level of sharpening to apply to "flat" areas. (optional, default `1.0`)
|
||||||
- `jagged` **[Number][19]** the level of sharpening to apply to "jagged" areas. (optional, default `2.0`)
|
- `jagged` **[Number][1]** the level of sharpening to apply to "jagged" areas. (optional, default `2.0`)
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][20]** Invalid parameters
|
- Throws **[Error][2]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -144,12 +123,12 @@ Returns **Sharp**
|
|||||||
Apply median filter.
|
Apply median filter.
|
||||||
When used without parameters the default window is 3x3.
|
When used without parameters the default window is 3x3.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `size` **[Number][19]** square mask size: size x size (optional, default `3`)
|
- `size` **[Number][1]** square mask size: size x size (optional, default `3`)
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][20]** Invalid parameters
|
- Throws **[Error][2]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -159,12 +138,12 @@ Blur the image.
|
|||||||
When used without parameters, performs a fast, mild blur of the output image.
|
When used without parameters, performs a fast, mild blur of the output image.
|
||||||
When a `sigma` is provided, performs a slower, more accurate Gaussian blur.
|
When a `sigma` is provided, performs a slower, more accurate Gaussian blur.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `sigma` **[Number][19]?** a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
- `sigma` **[Number][1]?** a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][20]** Invalid parameters
|
- Throws **[Error][2]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -173,15 +152,15 @@ Returns **Sharp**
|
|||||||
Extends/pads the edges of the image with the colour provided to the `background` method.
|
Extends/pads the edges of the image with the colour provided to the `background` method.
|
||||||
This operation will always occur after resizing and extraction, if any.
|
This operation will always occur after resizing and extraction, if any.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `extend` **([Number][19] \| [Object][21])** single pixel count to add to all edges or an Object with per-edge counts
|
- `extend` **([Number][1] \| [Object][3])** single pixel count to add to all edges or an Object with per-edge counts
|
||||||
- `extend.top` **[Number][19]?**
|
- `extend.top` **[Number][1]?**
|
||||||
- `extend.left` **[Number][19]?**
|
- `extend.left` **[Number][1]?**
|
||||||
- `extend.bottom` **[Number][19]?**
|
- `extend.bottom` **[Number][1]?**
|
||||||
- `extend.right` **[Number][19]?**
|
- `extend.right` **[Number][1]?**
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Resize to 140 pixels wide, then add 10 transparent pixels
|
// Resize to 140 pixels wide, then add 10 transparent pixels
|
||||||
@@ -193,7 +172,7 @@ sharp(input)
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][20]** Invalid parameters
|
- Throws **[Error][2]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -201,9 +180,9 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Merge alpha transparency channel, if any, with `background`.
|
Merge alpha transparency channel, if any, with `background`.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `flatten` **[Boolean][22]** (optional, default `true`)
|
- `flatten` **[Boolean][4]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -211,12 +190,12 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Trim "boring" pixels from all edges that contain values within a percentage similarity of the top-left pixel.
|
Trim "boring" pixels from all edges that contain values within a percentage similarity of the top-left pixel.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `tolerance` **[Number][19]** value between 1 and 99 representing the percentage similarity. (optional, default `10`)
|
- `tolerance` **[Number][1]** value between 1 and 99 representing the percentage similarity. (optional, default `10`)
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][20]** Invalid parameters
|
- Throws **[Error][2]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -228,12 +207,12 @@ This can improve the perceived brightness of a resized image in non-linear colou
|
|||||||
JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation
|
JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation
|
||||||
when applying a gamma correction.
|
when applying a gamma correction.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `gamma` **[Number][19]** value between 1.0 and 3.0. (optional, default `2.2`)
|
- `gamma` **[Number][1]** value between 1.0 and 3.0. (optional, default `2.2`)
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][20]** Invalid parameters
|
- Throws **[Error][2]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -241,9 +220,9 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Produce the "negative" of the image.
|
Produce the "negative" of the image.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `negate` **[Boolean][22]** (optional, default `true`)
|
- `negate` **[Boolean][4]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -251,9 +230,9 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Enhance output image contrast by stretching its luminance to cover the full dynamic range.
|
Enhance output image contrast by stretching its luminance to cover the full dynamic range.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `normalise` **[Boolean][22]** (optional, default `true`)
|
- `normalise` **[Boolean][4]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -261,9 +240,9 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Alternative spelling of normalise.
|
Alternative spelling of normalise.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `normalize` **[Boolean][22]** (optional, default `true`)
|
- `normalize` **[Boolean][4]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -271,16 +250,16 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Convolve the image with the specified kernel.
|
Convolve the image with the specified kernel.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `kernel` **[Object][21]**
|
- `kernel` **[Object][3]**
|
||||||
- `kernel.width` **[Number][19]** width of the kernel in pixels.
|
- `kernel.width` **[Number][1]** width of the kernel in pixels.
|
||||||
- `kernel.height` **[Number][19]** width of the kernel in pixels.
|
- `kernel.height` **[Number][1]** width of the kernel in pixels.
|
||||||
- `kernel.kernel` **[Array][23]<[Number][19]>** Array of length `width*height` containing the kernel values.
|
- `kernel.kernel` **[Array][5]<[Number][1]>** Array of length `width*height` containing the kernel values.
|
||||||
- `kernel.scale` **[Number][19]** the scale of the kernel in pixels. (optional, default `sum`)
|
- `kernel.scale` **[Number][1]** the scale of the kernel in pixels. (optional, default `sum`)
|
||||||
- `kernel.offset` **[Number][19]** the offset of the kernel in pixels. (optional, default `0`)
|
- `kernel.offset` **[Number][1]** the offset of the kernel in pixels. (optional, default `0`)
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp(input)
|
sharp(input)
|
||||||
@@ -296,7 +275,7 @@ sharp(input)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][20]** Invalid parameters
|
- Throws **[Error][2]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -304,15 +283,15 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Any pixel value greather than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
|
Any pixel value greather than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `threshold` **[Number][19]** a value in the range 0-255 representing the level at which the threshold will be applied. (optional, default `128`)
|
- `threshold` **[Number][1]** a value in the range 0-255 representing the level at which the threshold will be applied. (optional, default `128`)
|
||||||
- `options` **[Object][21]?**
|
- `options` **[Object][3]?**
|
||||||
- `options.greyscale` **[Boolean][22]** convert to single channel greyscale. (optional, default `true`)
|
- `options.greyscale` **[Boolean][4]** convert to single channel greyscale. (optional, default `true`)
|
||||||
- `options.grayscale` **[Boolean][22]** alternative spelling for greyscale. (optional, default `true`)
|
- `options.grayscale` **[Boolean][4]** alternative spelling for greyscale. (optional, default `true`)
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][20]** Invalid parameters
|
- Throws **[Error][2]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -323,18 +302,18 @@ Perform a bitwise boolean operation with operand image.
|
|||||||
This operation creates an output image where each pixel is the result of
|
This operation creates an output image where each pixel is the result of
|
||||||
the selected bitwise boolean `operation` between the corresponding pixels of the input images.
|
the selected bitwise boolean `operation` between the corresponding pixels of the input images.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `operand` **([Buffer][24] \| [String][25])** Buffer containing image data or String containing the path to an image file.
|
- `operand` **([Buffer][6] \| [String][7])** Buffer containing image data or String containing the path to an image file.
|
||||||
- `operator` **[String][25]** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
- `operator` **[String][7]** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
||||||
- `options` **[Object][21]?**
|
- `options` **[Object][3]?**
|
||||||
- `options.raw` **[Object][21]?** describes operand when using raw pixel data.
|
- `options.raw` **[Object][3]?** describes operand when using raw pixel data.
|
||||||
- `options.raw.width` **[Number][19]?**
|
- `options.raw.width` **[Number][1]?**
|
||||||
- `options.raw.height` **[Number][19]?**
|
- `options.raw.height` **[Number][1]?**
|
||||||
- `options.raw.channels` **[Number][19]?**
|
- `options.raw.channels` **[Number][1]?**
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][20]** Invalid parameters
|
- Throws **[Error][2]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -342,62 +321,26 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Apply the linear formula a \* input + b to the image (levels adjustment)
|
Apply the linear formula a \* input + b to the image (levels adjustment)
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `a` **[Number][19]** multiplier (optional, default `1.0`)
|
- `a` **[Number][1]** multiplier (optional, default `1.0`)
|
||||||
- `b` **[Number][19]** offset (optional, default `0.0`)
|
- `b` **[Number][1]** offset (optional, default `0.0`)
|
||||||
|
|
||||||
|
|
||||||
- Throws **[Error][20]** Invalid parameters
|
- Throws **[Error][2]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
[1]: #rotate
|
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
[2]: #extract
|
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
[3]: #flip
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
[4]: #flop
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
[5]: #sharpen
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
||||||
|
|
||||||
[6]: #median
|
[6]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
[7]: #blur
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
[8]: #extend
|
|
||||||
|
|
||||||
[9]: #flatten
|
|
||||||
|
|
||||||
[10]: #trim
|
|
||||||
|
|
||||||
[11]: #gamma
|
|
||||||
|
|
||||||
[12]: #negate
|
|
||||||
|
|
||||||
[13]: #normalise
|
|
||||||
|
|
||||||
[14]: #normalize
|
|
||||||
|
|
||||||
[15]: #convolve
|
|
||||||
|
|
||||||
[16]: #threshold
|
|
||||||
|
|
||||||
[17]: #boolean
|
|
||||||
|
|
||||||
[18]: #linear
|
|
||||||
|
|
||||||
[19]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
||||||
|
|
||||||
[20]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
||||||
|
|
||||||
[21]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
|
||||||
[22]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
||||||
|
|
||||||
[23]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
||||||
|
|
||||||
[24]: https://nodejs.org/api/buffer.html
|
|
||||||
|
|
||||||
[25]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||||
|
|
||||||
### Table of Contents
|
|
||||||
|
|
||||||
- [toFile][1]
|
|
||||||
- [toBuffer][2]
|
|
||||||
- [withMetadata][3]
|
|
||||||
- [jpeg][4]
|
|
||||||
- [png][5]
|
|
||||||
- [webp][6]
|
|
||||||
- [tiff][7]
|
|
||||||
- [raw][8]
|
|
||||||
- [toFormat][9]
|
|
||||||
- [tile][10]
|
|
||||||
|
|
||||||
## toFile
|
## toFile
|
||||||
|
|
||||||
Write output image data to a file.
|
Write output image data to a file.
|
||||||
@@ -23,15 +10,15 @@ Note that raw pixel data is only supported for buffer output.
|
|||||||
|
|
||||||
A `Promise` is returned when `callback` is not provided.
|
A `Promise` is returned when `callback` is not provided.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `fileOut` **[String][11]** the path to write the image data to.
|
- `fileOut` **[String][1]** the path to write the image data to.
|
||||||
- `callback` **[Function][12]?** called on completion with two arguments `(err, info)`.
|
- `callback` **[Function][2]?** called on completion with two arguments `(err, info)`.
|
||||||
`info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
`info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
||||||
`channels` and `premultiplied` (indicating if premultiplication was used).
|
`channels` and `premultiplied` (indicating if premultiplication was used).
|
||||||
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp(input)
|
sharp(input)
|
||||||
@@ -45,9 +32,9 @@ sharp(input)
|
|||||||
.catch(err => { ... });
|
.catch(err => { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid parameters
|
- Throws **[Error][3]** Invalid parameters
|
||||||
|
|
||||||
Returns **[Promise][14]<[Object][15]>** when no callback is provided
|
Returns **[Promise][4]<[Object][5]>** when no callback is provided
|
||||||
|
|
||||||
## toBuffer
|
## toBuffer
|
||||||
|
|
||||||
@@ -65,13 +52,13 @@ By default, the format will match the input image, except GIF and SVG input whic
|
|||||||
|
|
||||||
A `Promise` is returned when `callback` is not provided.
|
A `Promise` is returned when `callback` is not provided.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][15]?**
|
- `options` **[Object][5]?**
|
||||||
- `options.resolveWithObject` **[Boolean][16]?** Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
- `options.resolveWithObject` **[Boolean][6]?** Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
||||||
- `callback` **[Function][12]?**
|
- `callback` **[Function][2]?**
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp(input)
|
sharp(input)
|
||||||
@@ -92,7 +79,7 @@ sharp(input)
|
|||||||
.catch(err => { ... });
|
.catch(err => { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Promise][14]<[Buffer][17]>** when no callback is provided
|
Returns **[Promise][4]<[Buffer][7]>** when no callback is provided
|
||||||
|
|
||||||
## withMetadata
|
## withMetadata
|
||||||
|
|
||||||
@@ -100,12 +87,12 @@ Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
|
|||||||
The default behaviour, when `withMetadata` is not used, is to strip all metadata and convert to the device-independent sRGB colour space.
|
The default behaviour, when `withMetadata` is not used, is to strip all metadata and convert to the device-independent sRGB colour space.
|
||||||
This will also convert to and add a web-friendly sRGB ICC profile.
|
This will also convert to and add a web-friendly sRGB ICC profile.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `withMetadata` **[Object][15]?**
|
- `withMetadata` **[Object][5]?**
|
||||||
- `withMetadata.orientation` **[Number][18]?** value between 1 and 8, used to update the EXIF `Orientation` tag.
|
- `withMetadata.orientation` **[Number][8]?** value between 1 and 8, used to update the EXIF `Orientation` tag.
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp('input.jpg')
|
sharp('input.jpg')
|
||||||
@@ -114,7 +101,7 @@ sharp('input.jpg')
|
|||||||
.then(info => { ... });
|
.then(info => { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid parameters
|
- Throws **[Error][3]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -122,19 +109,23 @@ 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][5]?** output options
|
||||||
- `options.quality` **[Number][18]** quality, integer 1-100 (optional, default `80`)
|
- `options.quality` **[Number][8]** quality, integer 1-100 (optional, default `80`)
|
||||||
- `options.progressive` **[Boolean][16]** use progressive (interlace) scan (optional, default `false`)
|
- `options.progressive` **[Boolean][6]** 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][1]** 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][6]** apply trellis quantisation, requires mozjpeg (optional, default `false`)
|
||||||
- `options.overshootDeringing` **[Boolean][16]** apply overshoot deringing, requires mozjpeg (optional, default `false`)
|
- `options.overshootDeringing` **[Boolean][6]** 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][6]** optimise progressive scans, forces progressive, requires mozjpeg (optional, default `false`)
|
||||||
- `options.optimizeScans` **[Boolean][16]** alternative spelling of optimiseScans (optional, default `false`)
|
- `options.optimizeScans` **[Boolean][6]** alternative spelling of optimiseScans (optional, default `false`)
|
||||||
- `options.force` **[Boolean][16]** force JPEG output, otherwise attempt to use input format (optional, default `true`)
|
- `options.optimiseCoding` **[Boolean][6]** optimise Huffman coding tables (optional, default `true`)
|
||||||
|
- `options.optimizeCoding` **[Boolean][6]** alternative spelling of optimiseCoding (optional, default `true`)
|
||||||
|
- `options.quantisationTable` **[Number][8]** quantization table to use, integer 0-8, requires mozjpeg (optional, default `0`)
|
||||||
|
- `options.quantizationTable` **[Number][8]** alternative spelling of quantisationTable (optional, default `0`)
|
||||||
|
- `options.force` **[Boolean][6]** force JPEG output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Convert any input to very high quality JPEG output
|
// Convert any input to very high quality JPEG output
|
||||||
@@ -146,7 +137,7 @@ const data = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid options
|
- Throws **[Error][3]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -157,15 +148,15 @@ Use these PNG options for output image.
|
|||||||
PNG output is always full colour at 8 or 16 bits per pixel.
|
PNG output is always full colour at 8 or 16 bits per pixel.
|
||||||
Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][15]?**
|
- `options` **[Object][5]?**
|
||||||
- `options.progressive` **[Boolean][16]** use progressive (interlace) scan (optional, default `false`)
|
- `options.progressive` **[Boolean][6]** use progressive (interlace) scan (optional, default `false`)
|
||||||
- `options.compressionLevel` **[Number][18]** zlib compression level, 0-9 (optional, default `9`)
|
- `options.compressionLevel` **[Number][8]** zlib compression level, 0-9 (optional, default `9`)
|
||||||
- `options.adaptiveFiltering` **[Boolean][16]** use adaptive row filtering (optional, default `false`)
|
- `options.adaptiveFiltering` **[Boolean][6]** use adaptive row filtering (optional, default `false`)
|
||||||
- `options.force` **[Boolean][16]** force PNG output, otherwise attempt to use input format (optional, default `true`)
|
- `options.force` **[Boolean][6]** force PNG output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Convert any input to PNG output
|
// Convert any input to PNG output
|
||||||
@@ -174,7 +165,7 @@ const data = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid options
|
- Throws **[Error][3]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -182,16 +173,16 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Use these WebP options for output image.
|
Use these WebP options for output image.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][15]?** output options
|
- `options` **[Object][5]?** output options
|
||||||
- `options.quality` **[Number][18]** quality, integer 1-100 (optional, default `80`)
|
- `options.quality` **[Number][8]** quality, integer 1-100 (optional, default `80`)
|
||||||
- `options.alphaQuality` **[Number][18]** quality of alpha layer, integer 0-100 (optional, default `100`)
|
- `options.alphaQuality` **[Number][8]** quality of alpha layer, integer 0-100 (optional, default `100`)
|
||||||
- `options.lossless` **[Boolean][16]** use lossless compression mode (optional, default `false`)
|
- `options.lossless` **[Boolean][6]** use lossless compression mode (optional, default `false`)
|
||||||
- `options.nearLossless` **[Boolean][16]** use near_lossless compression mode (optional, default `false`)
|
- `options.nearLossless` **[Boolean][6]** 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][6]** force WebP output, otherwise attempt to use input format (optional, default `true`)
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Convert any input to lossless WebP output
|
// Convert any input to lossless WebP output
|
||||||
@@ -200,7 +191,7 @@ const data = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid options
|
- Throws **[Error][3]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -208,18 +199,18 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Use these TIFF options for output image.
|
Use these TIFF options for output image.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][15]?** output options
|
- `options` **[Object][5]?** output options
|
||||||
- `options.quality` **[Number][18]** quality, integer 1-100 (optional, default `80`)
|
- `options.quality` **[Number][8]** 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][6]** force TIFF output, otherwise attempt to use input format (optional, default `true`)
|
||||||
- `options.compression` **[Boolean][16]** compression options: lzw, deflate, jpeg, ccittfax4 (optional, default `'jpeg'`)
|
- `options.compression` **[Boolean][6]** 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][6]** 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][8]** 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][8]** 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][6]** squash 8-bit images down to 1 bit (optional, default `false`)
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Convert SVG input to LZW-compressed, 1 bit per pixel TIFF output
|
// Convert SVG input to LZW-compressed, 1 bit per pixel TIFF output
|
||||||
@@ -232,7 +223,7 @@ sharp('input.svg')
|
|||||||
.then(info => { ... });
|
.then(info => { ... });
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid options
|
- Throws **[Error][3]** Invalid options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -240,7 +231,7 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Force output to be raw, uncompressed uint8 pixel data.
|
Force output to be raw, uncompressed uint8 pixel data.
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Extract raw RGB pixel data from JPEG input
|
// Extract raw RGB pixel data from JPEG input
|
||||||
@@ -255,12 +246,12 @@ Returns **Sharp**
|
|||||||
|
|
||||||
Force output to a given format.
|
Force output to a given format.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `format` **([String][11] \| [Object][15])** as a String or an Object with an 'id' attribute
|
- `format` **([String][1] \| [Object][5])** as a String or an Object with an 'id' attribute
|
||||||
- `options` **[Object][15]** output options
|
- `options` **[Object][5]** output options
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Convert any input to PNG output
|
// Convert any input to PNG output
|
||||||
@@ -269,7 +260,7 @@ const data = await sharp(input)
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][13]** unsupported format or options
|
- Throws **[Error][3]** unsupported format or options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -281,16 +272,17 @@ Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed arc
|
|||||||
|
|
||||||
Warning: multiple sharp instances concurrently producing tile output can expose a possible race condition in some versions of libgsf.
|
Warning: multiple sharp instances concurrently producing tile output can expose a possible race condition in some versions of libgsf.
|
||||||
|
|
||||||
**Parameters**
|
### Parameters
|
||||||
|
|
||||||
- `tile` **[Object][15]?**
|
- `tile` **[Object][5]?**
|
||||||
- `tile.size` **[Number][18]** tile size in pixels, a value between 1 and 8192. (optional, default `256`)
|
- `tile.size` **[Number][8]** tile size in pixels, a value between 1 and 8192. (optional, default `256`)
|
||||||
- `tile.overlap` **[Number][18]** tile overlap in pixels, a value between 0 and 8192. (optional, default `0`)
|
- `tile.overlap` **[Number][8]** tile overlap in pixels, a value between 0 and 8192. (optional, default `0`)
|
||||||
- `tile.angle` **[Number][18]** tile angle of rotation, must be a multiple of 90. (optional, default `0`)
|
- `tile.angle` **[Number][8]** 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.depth` **[String][1]?** how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
||||||
- `tile.layout` **[String][11]** filesystem layout, possible values are `dz`, `zoomify` or `google`. (optional, default `'dz'`)
|
- `tile.container` **[String][1]** tile container, with value `fs` (filesystem) or `zip` (compressed file). (optional, default `'fs'`)
|
||||||
|
- `tile.layout` **[String][1]** filesystem layout, possible values are `dz`, `zoomify` or `google`. (optional, default `'dz'`)
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp('input.tiff')
|
sharp('input.tiff')
|
||||||
@@ -304,42 +296,22 @@ sharp('input.tiff')
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][13]** Invalid parameters
|
- Throws **[Error][3]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
[1]: #tofile
|
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
[2]: #tobuffer
|
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
|
||||||
|
|
||||||
[3]: #withmetadata
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
[4]: #jpeg
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
||||||
|
|
||||||
[5]: #png
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
[6]: #webp
|
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
[7]: #tiff
|
[7]: https://nodejs.org/api/buffer.html
|
||||||
|
|
||||||
[8]: #raw
|
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
[9]: #toformat
|
|
||||||
|
|
||||||
[10]: #tile
|
|
||||||
|
|
||||||
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
||||||
|
|
||||||
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
|
|
||||||
|
|
||||||
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
||||||
|
|
||||||
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
|
||||||
|
|
||||||
[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
|
||||||
[16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
||||||
|
|
||||||
[17]: https://nodejs.org/api/buffer.html
|
|
||||||
|
|
||||||
[18]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
||||||
|
|||||||
@@ -1,15 +1,5 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||||
|
|
||||||
### Table of Contents
|
|
||||||
|
|
||||||
- [resize][1]
|
|
||||||
- [crop][2]
|
|
||||||
- [embed][3]
|
|
||||||
- [max][4]
|
|
||||||
- [min][5]
|
|
||||||
- [ignoreAspectRatio][6]
|
|
||||||
- [withoutEnlargement][7]
|
|
||||||
|
|
||||||
## resize
|
## resize
|
||||||
|
|
||||||
Resize image to `width` x `height`.
|
Resize image to `width` x `height`.
|
||||||
@@ -17,20 +7,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][1].
|
||||||
- `cubic`: Use a [Catmull-Rom spline][9].
|
- `cubic`: Use a [Catmull-Rom spline][2].
|
||||||
- `lanczos2`: Use a [Lanczos kernel][10] with `a=2`.
|
- `lanczos2`: Use a [Lanczos kernel][3] 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][4]?** 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][4]?** 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][5]?**
|
||||||
- `options.kernel` **[String][13]** the kernel to use for image reduction. (optional, default `'lanczos3'`)
|
- `options.kernel` **[String][6]** 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][7]** 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 +37,7 @@ sharp(inputBuffer)
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][15]** Invalid parameters
|
- Throws **[Error][8]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -61,14 +51,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][9].
|
||||||
- `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][6]** 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 +72,7 @@ const transformer = sharp()
|
|||||||
readableStream.pipe(transformer).pipe(writableStream);
|
readableStream.pipe(transformer).pipe(writableStream);
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][15]** Invalid parameters
|
- Throws **[Error][8]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -94,11 +84,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][6]** 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 +105,7 @@ sharp('input.gif')
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
- Throws **[Error][15]** Invalid parameters
|
- Throws **[Error][8]** Invalid parameters
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
@@ -126,7 +116,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 +157,26 @@ 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][7]** (optional, default `true`)
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
[1]: #resize
|
[1]: http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation
|
||||||
|
|
||||||
[2]: #crop
|
[2]: https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline
|
||||||
|
|
||||||
[3]: #embed
|
[3]: https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel
|
||||||
|
|
||||||
[4]: #max
|
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
[5]: #min
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
[6]: #ignoreaspectratio
|
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
[7]: #withoutenlargement
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
[8]: http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation
|
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
||||||
|
|
||||||
[9]: https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline
|
[9]: https://en.wikipedia.org/wiki/Entropy_%28information_theory%29
|
||||||
|
|
||||||
[10]: https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel
|
|
||||||
|
|
||||||
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
||||||
|
|
||||||
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
|
||||||
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
||||||
|
|
||||||
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
||||||
|
|
||||||
[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
||||||
|
|
||||||
[16]: https://en.wikipedia.org/wiki/Entropy_%28information_theory%29
|
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||||
|
|
||||||
### Table of Contents
|
|
||||||
|
|
||||||
- [cache][1]
|
|
||||||
- [concurrency][2]
|
|
||||||
- [counters][3]
|
|
||||||
- [simd][4]
|
|
||||||
|
|
||||||
## cache
|
## cache
|
||||||
|
|
||||||
Gets or, when options are provided, sets the limits of _libvips'_ operation cache.
|
Gets or, when options are provided, sets the limits of _libvips'_ operation cache.
|
||||||
@@ -14,14 +7,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][1] \| [Boolean][2])** 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][3]** 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][3]** 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][3]** 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 +26,7 @@ sharp.cache( { files: 0 } );
|
|||||||
sharp.cache(false);
|
sharp.cache(false);
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Object][5]**
|
Returns **[Object][1]**
|
||||||
|
|
||||||
## concurrency
|
## concurrency
|
||||||
|
|
||||||
@@ -47,11 +40,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][3]?**
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const threads = sharp.concurrency(); // 4
|
const threads = sharp.concurrency(); // 4
|
||||||
@@ -59,7 +52,7 @@ sharp.concurrency(2); // 2
|
|||||||
sharp.concurrency(0); // 4
|
sharp.concurrency(0); // 4
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[Number][7]** concurrency
|
Returns **[Number][3]** concurrency
|
||||||
|
|
||||||
## counters
|
## counters
|
||||||
|
|
||||||
@@ -68,13 +61,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][1]**
|
||||||
|
|
||||||
## simd
|
## simd
|
||||||
|
|
||||||
@@ -87,11 +80,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][2]** (optional, default `false`)
|
||||||
|
|
||||||
**Examples**
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const simd = sharp.simd();
|
const simd = sharp.simd();
|
||||||
@@ -103,18 +96,10 @@ 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][2]**
|
||||||
|
|
||||||
[1]: #cache
|
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
[2]: #concurrency
|
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||||
|
|
||||||
[3]: #counters
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
||||||
[4]: #simd
|
|
||||||
|
|
||||||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
||||||
|
|
||||||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
||||||
|
|
||||||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
||||||
|
|||||||
@@ -4,6 +4,58 @@
|
|||||||
|
|
||||||
Requires libvips v8.6.1.
|
Requires libvips v8.6.1.
|
||||||
|
|
||||||
|
#### v0.20.7 - 21<sup>st</sup> August 2018
|
||||||
|
|
||||||
|
* Use copy+unlink if rename operation fails during installation.
|
||||||
|
[#1345](https://github.com/lovell/sharp/issues/1345)
|
||||||
|
|
||||||
|
#### v0.20.6 - 20<sup>th</sup> August 2018
|
||||||
|
|
||||||
|
* Add removeAlpha operation to remove alpha channel, if any.
|
||||||
|
[#1248](https://github.com/lovell/sharp/issues/1248)
|
||||||
|
|
||||||
|
* Expose mozjpeg quant_table flag.
|
||||||
|
[#1285](https://github.com/lovell/sharp/pull/1285)
|
||||||
|
[@rexxars](https://github.com/rexxars)
|
||||||
|
|
||||||
|
* Allow full WebP alphaQuality range of 0-100.
|
||||||
|
[#1290](https://github.com/lovell/sharp/pull/1290)
|
||||||
|
[@sylvaindumont](https://github.com/sylvaindumont)
|
||||||
|
|
||||||
|
* Cache libvips binaries to reduce re-install time.
|
||||||
|
[#1301](https://github.com/lovell/sharp/issues/1301)
|
||||||
|
|
||||||
|
* Ensure vendor platform mismatch throws error at install time.
|
||||||
|
[#1303](https://github.com/lovell/sharp/issues/1303)
|
||||||
|
|
||||||
|
* Improve install time error messages for FreeBSD users.
|
||||||
|
[#1310](https://github.com/lovell/sharp/issues/1310)
|
||||||
|
|
||||||
|
* Ensure extractChannel works with 16-bit images.
|
||||||
|
[#1330](https://github.com/lovell/sharp/issues/1330)
|
||||||
|
|
||||||
|
* Expose depth option for tile-based output.
|
||||||
|
[#1342](https://github.com/lovell/sharp/pull/1342)
|
||||||
|
[@alundavies](https://github.com/alundavies)
|
||||||
|
|
||||||
|
* Add experimental entropy field to stats response.
|
||||||
|
|
||||||
|
#### v0.20.5 - 27<sup>th</sup> June 2018
|
||||||
|
|
||||||
|
* Expose libjpeg optimize_coding flag.
|
||||||
|
[#1265](https://github.com/lovell/sharp/pull/1265)
|
||||||
|
[@tomlokhorst](https://github.com/tomlokhorst)
|
||||||
|
|
||||||
|
#### 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
|
#### v0.20.3 - 29<sup>th</sup> May 2018
|
||||||
|
|
||||||
* Fix tint operation by ensuring LAB interpretation and allowing negative values.
|
* Fix tint operation by ensuring LAB interpretation and allowing negative values.
|
||||||
|
|||||||
5
docs/css/extra.css
Normal file
5
docs/css/extra.css
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
/* Nest document subheadings in navigation */
|
||||||
|
ul.subnav ul:not(.subnav) {
|
||||||
|
padding-left: 2em;
|
||||||
|
font-size: 80%;
|
||||||
|
}
|
||||||
@@ -112,6 +112,10 @@ the help and code contributions of the following people:
|
|||||||
* [Rik Heywood](https://github.com/rikh42)
|
* [Rik Heywood](https://github.com/rikh42)
|
||||||
* [Thomas Parisot](https://github.com/oncletom)
|
* [Thomas Parisot](https://github.com/oncletom)
|
||||||
* [Nathan Graves](https://github.com/woolite64)
|
* [Nathan Graves](https://github.com/woolite64)
|
||||||
|
* [Tom Lokhorst](https://github.com/tomlokhorst)
|
||||||
|
* [Espen Hovlandsdal](https://github.com/rexxars)
|
||||||
|
* [Sylvain Dumont](https://github.com/sylvaindumont)
|
||||||
|
* [Alun Davies](https://github.com/alundavies)
|
||||||
|
|
||||||
Thank you!
|
Thank you!
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const npmLog = require('npmlog');
|
|||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
const simpleGet = require('simple-get');
|
const simpleGet = require('simple-get');
|
||||||
const tar = require('tar');
|
const tar = require('tar');
|
||||||
|
const copyFileSync = require('fs-copy-file-sync');
|
||||||
|
|
||||||
const agent = require('../lib/agent');
|
const agent = require('../lib/agent');
|
||||||
const libvips = require('../lib/libvips');
|
const libvips = require('../lib/libvips');
|
||||||
@@ -17,6 +18,22 @@ const platform = require('../lib/platform');
|
|||||||
const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
|
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}/`;
|
||||||
|
|
||||||
|
const extractTarball = function (tarPath) {
|
||||||
|
const vendorPath = path.join(__dirname, '..', 'vendor');
|
||||||
|
if (!fs.existsSync(vendorPath)) {
|
||||||
|
fs.mkdirSync(vendorPath);
|
||||||
|
}
|
||||||
|
tar
|
||||||
|
.extract({
|
||||||
|
file: tarPath,
|
||||||
|
cwd: vendorPath,
|
||||||
|
strict: true
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const useGlobalLibvips = libvips.useGlobalLibvips();
|
const useGlobalLibvips = libvips.useGlobalLibvips();
|
||||||
if (useGlobalLibvips) {
|
if (useGlobalLibvips) {
|
||||||
@@ -29,11 +46,15 @@ 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') {
|
const platformAndArch = platform();
|
||||||
|
if (platformAndArch === 'win32-ia32') {
|
||||||
throw new Error('Windows x86 (32-bit) node.exe is not supported');
|
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}`);
|
||||||
|
}
|
||||||
|
if (platformAndArch === 'freebsd-x64') {
|
||||||
|
throw new Error(`FreeBSD systems require manual installation of libvips >= ${minimumLibvipsVersion}`);
|
||||||
}
|
}
|
||||||
if (detectLibc.isNonGlibcLinux) {
|
if (detectLibc.isNonGlibcLinux) {
|
||||||
throw new Error(`Use with ${detectLibc.family} libc requires manual installation of libvips >= ${minimumLibvipsVersion}`);
|
throw new Error(`Use with ${detectLibc.family} libc requires manual installation of libvips >= ${minimumLibvipsVersion}`);
|
||||||
@@ -42,38 +63,37 @@ try {
|
|||||||
throw new Error(`Use with glibc version ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`);
|
throw new Error(`Use with glibc version ${detectLibc.version} requires manual installation of libvips >= ${minimumLibvipsVersion}`);
|
||||||
}
|
}
|
||||||
// Download to per-process temporary file
|
// Download to per-process temporary file
|
||||||
const tarFilename = ['libvips', minimumLibvipsVersion, platform()].join('-') + '.tar.gz';
|
const tarFilename = ['libvips', minimumLibvipsVersion, platformAndArch].join('-') + '.tar.gz';
|
||||||
const tarPathTemp = path.join(os.tmpdir(), `${process.pid}-${tarFilename}`);
|
const tarPathCache = path.join(libvips.cachePath(), tarFilename);
|
||||||
const tmpFile = fs.createWriteStream(tarPathTemp);
|
if (fs.existsSync(tarPathCache)) {
|
||||||
const url = distBaseUrl + tarFilename;
|
npmLog.info('sharp', `Using cached ${tarPathCache}`);
|
||||||
npmLog.info('sharp', `Downloading ${url}`);
|
extractTarball(tarPathCache);
|
||||||
simpleGet({ url: url, agent: agent() }, function (err, response) {
|
} else {
|
||||||
if (err) {
|
const tarPathTemp = path.join(os.tmpdir(), `${process.pid}-${tarFilename}`);
|
||||||
throw err;
|
const tmpFile = fs.createWriteStream(tarPathTemp);
|
||||||
}
|
const url = distBaseUrl + tarFilename;
|
||||||
if (response.statusCode !== 200) {
|
npmLog.info('sharp', `Downloading ${url}`);
|
||||||
throw new Error(`Status ${response.statusCode}`);
|
simpleGet({ url: url, agent: agent() }, function (err, response) {
|
||||||
}
|
if (err) {
|
||||||
response.pipe(tmpFile);
|
|
||||||
});
|
|
||||||
tmpFile.on('close', function () {
|
|
||||||
const vendorPath = path.join(__dirname, '..', 'vendor');
|
|
||||||
fs.mkdirSync(vendorPath);
|
|
||||||
tar
|
|
||||||
.extract({
|
|
||||||
file: tarPathTemp,
|
|
||||||
cwd: vendorPath,
|
|
||||||
strict: true
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
try {
|
|
||||||
fs.unlinkSync(tarPathTemp);
|
|
||||||
} catch (err) {}
|
|
||||||
})
|
|
||||||
.catch(function (err) {
|
|
||||||
throw err;
|
throw err;
|
||||||
});
|
}
|
||||||
});
|
if (response.statusCode !== 200) {
|
||||||
|
throw new Error(`Status ${response.statusCode}`);
|
||||||
|
}
|
||||||
|
response.pipe(tmpFile);
|
||||||
|
});
|
||||||
|
tmpFile.on('close', function () {
|
||||||
|
try {
|
||||||
|
// Attempt to rename
|
||||||
|
fs.renameSync(tarPathTemp, tarPathCache);
|
||||||
|
} catch (err) {
|
||||||
|
// Fall back to copy and unlink
|
||||||
|
copyFileSync(tarPathTemp, tarPathCache);
|
||||||
|
fs.unlinkSync(tarPathTemp);
|
||||||
|
}
|
||||||
|
extractTarball(tarPathCache);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
npmLog.error('sharp', err.message);
|
npmLog.error('sharp', err.message);
|
||||||
|
|||||||
@@ -12,6 +12,23 @@ const bool = {
|
|||||||
eor: 'eor'
|
eor: 'eor'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* sharp('rgba.png')
|
||||||
|
* .removeAlpha()
|
||||||
|
* .toFile('rgb.png', function(err, info) {
|
||||||
|
* // rgb.png is a 3 channel image without an alpha channel
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* @returns {Sharp}
|
||||||
|
*/
|
||||||
|
function removeAlpha () {
|
||||||
|
this.options.removeAlpha = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract a single channel from a multi-channel image.
|
* Extract a single channel from a multi-channel image.
|
||||||
*
|
*
|
||||||
@@ -102,6 +119,7 @@ function bandbool (boolOp) {
|
|||||||
module.exports = function (Sharp) {
|
module.exports = function (Sharp) {
|
||||||
// Public instance functions
|
// Public instance functions
|
||||||
[
|
[
|
||||||
|
removeAlpha,
|
||||||
extractChannel,
|
extractChannel,
|
||||||
joinChannel,
|
joinChannel,
|
||||||
bandbool
|
bandbool
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ const is = require('./is');
|
|||||||
* .overlayWith('overlay.png', { gravity: sharp.gravity.southeast } )
|
* .overlayWith('overlay.png', { gravity: sharp.gravity.southeast } )
|
||||||
* .sharpen()
|
* .sharpen()
|
||||||
* .withMetadata()
|
* .withMetadata()
|
||||||
* .quality(90)
|
* .webp( { quality: 90 } )
|
||||||
* .webp()
|
|
||||||
* .toBuffer()
|
* .toBuffer()
|
||||||
* .then(function(outputBuffer) {
|
* .then(function(outputBuffer) {
|
||||||
* // outputBuffer contains upside down, 300px wide, alpha channel flattened
|
* // outputBuffer contains upside down, 300px wide, alpha channel flattened
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ const debuglog = util.debuglog('sharp');
|
|||||||
* width: 300,
|
* width: 300,
|
||||||
* height: 200,
|
* height: 200,
|
||||||
* channels: 4,
|
* channels: 4,
|
||||||
* background: { r: 255, g: 0, b: 0, alpha: 128 }
|
* background: { r: 255, g: 0, b: 0, alpha: 0.5 }
|
||||||
* }
|
* }
|
||||||
* })
|
* })
|
||||||
* .png()
|
* .png()
|
||||||
@@ -171,6 +171,7 @@ const Sharp = function (input, options) {
|
|||||||
booleanFileIn: '',
|
booleanFileIn: '',
|
||||||
joinChannelIn: [],
|
joinChannelIn: [],
|
||||||
extractChannel: -1,
|
extractChannel: -1,
|
||||||
|
removeAlpha: false,
|
||||||
colourspace: 'srgb',
|
colourspace: 'srgb',
|
||||||
// overlay
|
// overlay
|
||||||
overlayGravity: 0,
|
overlayGravity: 0,
|
||||||
@@ -192,6 +193,8 @@ const Sharp = function (input, options) {
|
|||||||
jpegTrellisQuantisation: false,
|
jpegTrellisQuantisation: false,
|
||||||
jpegOvershootDeringing: false,
|
jpegOvershootDeringing: false,
|
||||||
jpegOptimiseScans: false,
|
jpegOptimiseScans: false,
|
||||||
|
jpegOptimiseCoding: true,
|
||||||
|
jpegQuantisationTable: 0,
|
||||||
pngProgressive: false,
|
pngProgressive: false,
|
||||||
pngCompressionLevel: 9,
|
pngCompressionLevel: 9,
|
||||||
pngAdaptiveFiltering: false,
|
pngAdaptiveFiltering: false,
|
||||||
|
|||||||
@@ -264,6 +264,7 @@ function metadata (callback) {
|
|||||||
* - `maxX` (x-coordinate of one of the pixel where the maximum lies)
|
* - `maxX` (x-coordinate of one of the pixel where the maximum lies)
|
||||||
* - `maxY` (y-coordinate of one of the pixel where the maximum lies)
|
* - `maxY` (y-coordinate of one of the pixel where the maximum lies)
|
||||||
* - `isOpaque`: 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
|
||||||
|
* - `entropy`: Histogram-based estimation of greyscale entropy, discarding alpha channel if any (experimental)
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const image = sharp(inputJpg);
|
* const image = sharp(inputJpg);
|
||||||
|
|||||||
@@ -1,17 +1,32 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const spawnSync = require('child_process').spawnSync;
|
const spawnSync = require('child_process').spawnSync;
|
||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
const platform = require('./platform');
|
const platform = require('./platform');
|
||||||
|
|
||||||
const minimumLibvipsVersion = process.env.npm_package_config_libvips || require('../package.json').config.libvips;
|
const env = process.env;
|
||||||
|
const minimumLibvipsVersion = env.npm_package_config_libvips || require('../package.json').config.libvips;
|
||||||
|
|
||||||
const spawnSyncOptions = {
|
const spawnSyncOptions = {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
shell: true
|
shell: true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const cachePath = function () {
|
||||||
|
const npmCachePath = env.npm_config_cache || (env.APPDATA ? path.join(env.APPDATA, 'npm-cache') : path.join(os.homedir(), '.npm'));
|
||||||
|
if (!fs.existsSync(npmCachePath)) {
|
||||||
|
fs.mkdirSync(npmCachePath);
|
||||||
|
}
|
||||||
|
const libvipsCachePath = path.join(npmCachePath, '_libvips');
|
||||||
|
if (!fs.existsSync(libvipsCachePath)) {
|
||||||
|
fs.mkdirSync(libvipsCachePath);
|
||||||
|
}
|
||||||
|
return libvipsCachePath;
|
||||||
|
};
|
||||||
|
|
||||||
const globalLibvipsVersion = function () {
|
const globalLibvipsVersion = function () {
|
||||||
if (process.platform !== 'win32') {
|
if (process.platform !== 'win32') {
|
||||||
const globalLibvipsVersion = spawnSync(`PKG_CONFIG_PATH="${pkgConfigPath()}" pkg-config --modversion vips-cpp`, spawnSyncOptions).stdout || '';
|
const globalLibvipsVersion = spawnSync(`PKG_CONFIG_PATH="${pkgConfigPath()}" pkg-config --modversion vips-cpp`, spawnSyncOptions).stdout || '';
|
||||||
@@ -23,21 +38,24 @@ const globalLibvipsVersion = function () {
|
|||||||
|
|
||||||
const hasVendoredLibvips = function () {
|
const hasVendoredLibvips = function () {
|
||||||
const currentPlatformId = platform();
|
const currentPlatformId = platform();
|
||||||
|
let vendorPlatformId;
|
||||||
try {
|
try {
|
||||||
const vendorPlatformId = require(path.join(__dirname, '..', 'vendor', 'platform.json'));
|
vendorPlatformId = require(path.join(__dirname, '..', 'vendor', 'platform.json'));
|
||||||
|
} catch (err) {}
|
||||||
|
if (vendorPlatformId) {
|
||||||
if (currentPlatformId === vendorPlatformId) {
|
if (currentPlatformId === vendorPlatformId) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`'${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.`);
|
throw new Error(`'${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.`);
|
||||||
}
|
}
|
||||||
} catch (err) {}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const pkgConfigPath = function () {
|
const pkgConfigPath = function () {
|
||||||
if (process.platform !== 'win32') {
|
if (process.platform !== 'win32') {
|
||||||
const brewPkgConfigPath = spawnSync('which brew >/dev/null 2>&1 && eval $(brew --env) && echo $PKG_CONFIG_LIBDIR', spawnSyncOptions).stdout || '';
|
const brewPkgConfigPath = spawnSync('which brew >/dev/null 2>&1 && eval $(brew --env) && echo $PKG_CONFIG_LIBDIR', spawnSyncOptions).stdout || '';
|
||||||
return [brewPkgConfigPath.trim(), process.env.PKG_CONFIG_PATH, '/usr/local/lib/pkgconfig', '/usr/lib/pkgconfig']
|
return [brewPkgConfigPath.trim(), env.PKG_CONFIG_PATH, '/usr/local/lib/pkgconfig', '/usr/lib/pkgconfig']
|
||||||
.filter(function (p) { return !!p; })
|
.filter(function (p) { return !!p; })
|
||||||
.join(':');
|
.join(':');
|
||||||
} else {
|
} else {
|
||||||
@@ -46,7 +64,7 @@ const pkgConfigPath = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const useGlobalLibvips = function () {
|
const useGlobalLibvips = function () {
|
||||||
if (Boolean(process.env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
|
if (Boolean(env.SHARP_IGNORE_GLOBAL_LIBVIPS) === true) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +74,7 @@ const useGlobalLibvips = function () {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
minimumLibvipsVersion: minimumLibvipsVersion,
|
minimumLibvipsVersion: minimumLibvipsVersion,
|
||||||
|
cachePath: cachePath,
|
||||||
globalLibvipsVersion: globalLibvipsVersion,
|
globalLibvipsVersion: globalLibvipsVersion,
|
||||||
hasVendoredLibvips: hasVendoredLibvips,
|
hasVendoredLibvips: hasVendoredLibvips,
|
||||||
pkgConfigPath: pkgConfigPath,
|
pkgConfigPath: pkgConfigPath,
|
||||||
|
|||||||
@@ -148,6 +148,10 @@ function withMetadata (withMetadata) {
|
|||||||
* @param {Boolean} [options.overshootDeringing=false] - apply overshoot deringing, requires mozjpeg
|
* @param {Boolean} [options.overshootDeringing=false] - apply overshoot deringing, requires mozjpeg
|
||||||
* @param {Boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive, requires mozjpeg
|
* @param {Boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive, requires mozjpeg
|
||||||
* @param {Boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans
|
* @param {Boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans
|
||||||
|
* @param {Boolean} [options.optimiseCoding=true] - optimise Huffman coding tables
|
||||||
|
* @param {Boolean} [options.optimizeCoding=true] - alternative spelling of optimiseCoding
|
||||||
|
* @param {Number} [options.quantisationTable=0] - quantization table to use, integer 0-8, requires mozjpeg
|
||||||
|
* @param {Number} [options.quantizationTable=0] - alternative spelling of quantisationTable
|
||||||
* @param {Boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format
|
* @param {Boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid options
|
* @throws {Error} Invalid options
|
||||||
@@ -185,6 +189,18 @@ function jpeg (options) {
|
|||||||
this.options.jpegProgressive = true;
|
this.options.jpegProgressive = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
options.optimiseCoding = is.bool(options.optimizeCoding) ? options.optimizeCoding : options.optimiseCoding;
|
||||||
|
if (is.defined(options.optimiseCoding)) {
|
||||||
|
this._setBooleanOption('jpegOptimiseCoding', options.optimiseCoding);
|
||||||
|
}
|
||||||
|
options.quantisationTable = is.number(options.quantizationTable) ? options.quantizationTable : options.quantisationTable;
|
||||||
|
if (is.defined(options.quantisationTable)) {
|
||||||
|
if (is.integer(options.quantisationTable) && is.inRange(options.quantisationTable, 0, 8)) {
|
||||||
|
this.options.jpegQuantisationTable = options.quantisationTable;
|
||||||
|
} else {
|
||||||
|
throw new Error('Invalid quantisation table (integer, 0-8) ' + options.quantisationTable);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return this._updateFormatOut('jpeg', options);
|
return this._updateFormatOut('jpeg', options);
|
||||||
}
|
}
|
||||||
@@ -255,10 +271,10 @@ function webp (options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.object(options) && is.defined(options.alphaQuality)) {
|
if (is.object(options) && is.defined(options.alphaQuality)) {
|
||||||
if (is.integer(options.alphaQuality) && is.inRange(options.alphaQuality, 1, 100)) {
|
if (is.integer(options.alphaQuality) && is.inRange(options.alphaQuality, 0, 100)) {
|
||||||
this.options.webpAlphaQuality = options.alphaQuality;
|
this.options.webpAlphaQuality = options.alphaQuality;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid webp alpha quality (integer, 1-100) ' + options.alphaQuality);
|
throw new Error('Invalid webp alpha quality (integer, 0-100) ' + options.alphaQuality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is.object(options) && is.defined(options.lossless)) {
|
if (is.object(options) && is.defined(options.lossless)) {
|
||||||
@@ -407,6 +423,7 @@ function toFormat (format, options) {
|
|||||||
* @param {Number} [tile.size=256] tile size in pixels, a value between 1 and 8192.
|
* @param {Number} [tile.size=256] tile size in pixels, a value between 1 and 8192.
|
||||||
* @param {Number} [tile.overlap=0] tile overlap in pixels, a value between 0 and 8192.
|
* @param {Number} [tile.overlap=0] tile overlap in pixels, a value between 0 and 8192.
|
||||||
* @param {Number} [tile.angle=0] tile angle of rotation, must be a multiple of 90.
|
* @param {Number} [tile.angle=0] tile angle of rotation, must be a multiple of 90.
|
||||||
|
* @param {String} [tile.depth] how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
||||||
* @param {String} [tile.container='fs'] tile container, with value `fs` (filesystem) or `zip` (compressed file).
|
* @param {String} [tile.container='fs'] tile container, with value `fs` (filesystem) or `zip` (compressed file).
|
||||||
* @param {String} [tile.layout='dz'] filesystem layout, possible values are `dz`, `zoomify` or `google`.
|
* @param {String} [tile.layout='dz'] filesystem layout, possible values are `dz`, `zoomify` or `google`.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
@@ -458,6 +475,15 @@ function tile (tile) {
|
|||||||
throw new Error('Unsupported angle: angle must be a positive/negative multiple of 90 ' + tile.angle);
|
throw new Error('Unsupported angle: angle must be a positive/negative multiple of 90 ' + tile.angle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Depth of tiles
|
||||||
|
if (is.defined(tile.depth)) {
|
||||||
|
if (is.string(tile.depth) && is.inArray(tile.depth, ['onepixel', 'onetile', 'one'])) {
|
||||||
|
this.options.tileDepth = tile.depth;
|
||||||
|
} else {
|
||||||
|
throw new Error("Invalid tile depth '" + tile.depth + "', should be one of 'onepixel', 'onetile' or 'one'");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Format
|
// Format
|
||||||
if (is.inArray(this.options.formatOut, ['jpeg', 'png', 'webp'])) {
|
if (is.inArray(this.options.formatOut, ['jpeg', 'png', 'webp'])) {
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ site_description: High performance Node.js image processing, the fastest module
|
|||||||
copyright: <a href="https://pixelplumbing.com/">pixelplumbing.com</a>
|
copyright: <a href="https://pixelplumbing.com/">pixelplumbing.com</a>
|
||||||
google_analytics: ['UA-13034748-12', 'sharp.pixelplumbing.com']
|
google_analytics: ['UA-13034748-12', 'sharp.pixelplumbing.com']
|
||||||
theme: readthedocs
|
theme: readthedocs
|
||||||
|
extra_css:
|
||||||
|
- css/extra.css
|
||||||
markdown_extensions:
|
markdown_extensions:
|
||||||
- toc:
|
- toc:
|
||||||
permalink: True
|
permalink: True
|
||||||
|
|||||||
20
package.json
20
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.3",
|
"version": "0.20.7",
|
||||||
"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": [
|
||||||
@@ -48,7 +48,11 @@
|
|||||||
"Andrea Bianco <andrea.bianco@unibas.ch>",
|
"Andrea Bianco <andrea.bianco@unibas.ch>",
|
||||||
"Rik Heywood <rik@rik.org>",
|
"Rik Heywood <rik@rik.org>",
|
||||||
"Thomas Parisot <hi@oncletom.io>",
|
"Thomas Parisot <hi@oncletom.io>",
|
||||||
"Nathan Graves <nathanrgraves+github@gmail.com>"
|
"Nathan Graves <nathanrgraves+github@gmail.com>",
|
||||||
|
"Tom Lokhorst <tom@lokhorst.eu>",
|
||||||
|
"Espen Hovlandsdal <espen@hovlandsdal.com>",
|
||||||
|
"Sylvain Dumont <sylvain.dumont35@gmail.com>",
|
||||||
|
"Alun Davies <alun.owain.davies@googlemail.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)",
|
||||||
@@ -56,7 +60,7 @@
|
|||||||
"test": "semistandard && cc && nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js && prebuild-ci",
|
"test": "semistandard && cc && nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js && prebuild-ci",
|
||||||
"coverage": "./test/coverage/report.sh",
|
"coverage": "./test/coverage/report.sh",
|
||||||
"test-leak": "./test/leak/leak.sh",
|
"test-leak": "./test/leak/leak.sh",
|
||||||
"docs": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md lib/$m.js >docs/api-$m.md; done"
|
"docs": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md --markdown-toc=false lib/$m.js >docs/api-$m.md; done"
|
||||||
},
|
},
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -86,21 +90,21 @@
|
|||||||
"fs-copy-file-sync": "^1.1.1",
|
"fs-copy-file-sync": "^1.1.1",
|
||||||
"npmlog": "^4.1.2",
|
"npmlog": "^4.1.2",
|
||||||
"prebuild-install": "^4.0.0",
|
"prebuild-install": "^4.0.0",
|
||||||
"semver": "^5.5.0",
|
"semver": "^5.5.1",
|
||||||
"simple-get": "^2.8.1",
|
"simple-get": "^2.8.1",
|
||||||
"tar": "^4.4.4",
|
"tar": "^4.4.6",
|
||||||
"tunnel-agent": "^0.6.0"
|
"tunnel-agent": "^0.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^2.6.1",
|
"async": "^2.6.1",
|
||||||
"cc": "^1.0.2",
|
"cc": "^1.0.2",
|
||||||
"decompress-zip": "^0.3.1",
|
"decompress-zip": "^0.3.1",
|
||||||
"documentation": "^7.1.0",
|
"documentation": "^8.1.1",
|
||||||
"exif-reader": "^1.0.2",
|
"exif-reader": "^1.0.2",
|
||||||
"icc": "^1.0.0",
|
"icc": "^1.0.0",
|
||||||
"mocha": "^5.2.0",
|
"mocha": "^5.2.0",
|
||||||
"nyc": "^11.8.0",
|
"nyc": "^12.0.2",
|
||||||
"prebuild": "^7.6.0",
|
"prebuild": "^7.6.2",
|
||||||
"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"
|
||||||
|
|||||||
@@ -28,6 +28,16 @@ using vips::VError;
|
|||||||
|
|
||||||
namespace sharp {
|
namespace sharp {
|
||||||
|
|
||||||
|
/*
|
||||||
|
Removes alpha channel, if any.
|
||||||
|
*/
|
||||||
|
VImage RemoveAlpha(VImage image) {
|
||||||
|
if (HasAlpha(image)) {
|
||||||
|
image = image.extract_band(0, VImage::option()->set("n", image.bands() - 1));
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Composite overlayImage over image at given position
|
Composite overlayImage over image at given position
|
||||||
Assumes alpha channels are already premultiplied and will be unpremultiplied after
|
Assumes alpha channels are already premultiplied and will be unpremultiplied after
|
||||||
@@ -223,10 +233,8 @@ namespace sharp {
|
|||||||
VImage Gamma(VImage image, double const exponent) {
|
VImage Gamma(VImage image, double const exponent) {
|
||||||
if (HasAlpha(image)) {
|
if (HasAlpha(image)) {
|
||||||
// Separate alpha channel
|
// Separate alpha channel
|
||||||
VImage imageWithoutAlpha = image.extract_band(0,
|
|
||||||
VImage::option()->set("n", image.bands() - 1));
|
|
||||||
VImage alpha = image[image.bands() - 1];
|
VImage alpha = image[image.bands() - 1];
|
||||||
return imageWithoutAlpha.gamma(VImage::option()->set("exponent", exponent)).bandjoin(alpha);
|
return RemoveAlpha(image).gamma(VImage::option()->set("exponent", exponent)).bandjoin(alpha);
|
||||||
} else {
|
} else {
|
||||||
return image.gamma(VImage::option()->set("exponent", exponent));
|
return image.gamma(VImage::option()->set("exponent", exponent));
|
||||||
}
|
}
|
||||||
@@ -374,10 +382,8 @@ namespace sharp {
|
|||||||
VImage Linear(VImage image, double const a, double const b) {
|
VImage Linear(VImage image, double const a, double const b) {
|
||||||
if (HasAlpha(image)) {
|
if (HasAlpha(image)) {
|
||||||
// Separate alpha channel
|
// Separate alpha channel
|
||||||
VImage imageWithoutAlpha = image.extract_band(0,
|
|
||||||
VImage::option()->set("n", image.bands() - 1));
|
|
||||||
VImage alpha = image[image.bands() - 1];
|
VImage alpha = image[image.bands() - 1];
|
||||||
return imageWithoutAlpha.linear(a, b).bandjoin(alpha);
|
return RemoveAlpha(image).linear(a, b).bandjoin(alpha);
|
||||||
} else {
|
} else {
|
||||||
return image.linear(a, b);
|
return image.linear(a, b);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ using vips::VImage;
|
|||||||
|
|
||||||
namespace sharp {
|
namespace sharp {
|
||||||
|
|
||||||
|
/*
|
||||||
|
Removes alpha channel, if any.
|
||||||
|
*/
|
||||||
|
VImage RemoveAlpha(VImage image);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Alpha composite src over dst with given gravity.
|
Alpha composite src over dst with given gravity.
|
||||||
Assumes alpha channels are already premultiplied and will be unpremultiplied after.
|
Assumes alpha channels are already premultiplied and will be unpremultiplied after.
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -381,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));
|
||||||
@@ -693,8 +694,19 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
(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);
|
VipsInterpretation const interpretation = sharp::Is16Bit(image.interpretation())
|
||||||
|
? VIPS_INTERPRETATION_GREY16
|
||||||
|
: VIPS_INTERPRETATION_B_W;
|
||||||
|
image = image
|
||||||
|
.extract_band(baton->extractChannel)
|
||||||
|
.copy(VImage::option()->set("interpretation", interpretation));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove alpha channel, if any
|
||||||
|
if (baton->removeAlpha) {
|
||||||
|
image = sharp::RemoveAlpha(image);
|
||||||
|
}
|
||||||
|
|
||||||
// Convert image to sRGB, if not already
|
// Convert image to sRGB, if not already
|
||||||
if (sharp::Is16Bit(image.interpretation())) {
|
if (sharp::Is16Bit(image.interpretation())) {
|
||||||
image = image.cast(VIPS_FORMAT_USHORT);
|
image = image.cast(VIPS_FORMAT_USHORT);
|
||||||
@@ -730,9 +742,10 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("interlace", baton->jpegProgressive)
|
->set("interlace", baton->jpegProgressive)
|
||||||
->set("no_subsample", baton->jpegChromaSubsampling == "4:4:4")
|
->set("no_subsample", baton->jpegChromaSubsampling == "4:4:4")
|
||||||
->set("trellis_quant", baton->jpegTrellisQuantisation)
|
->set("trellis_quant", baton->jpegTrellisQuantisation)
|
||||||
|
->set("quant_table", baton->jpegQuantisationTable)
|
||||||
->set("overshoot_deringing", baton->jpegOvershootDeringing)
|
->set("overshoot_deringing", baton->jpegOvershootDeringing)
|
||||||
->set("optimize_scans", baton->jpegOptimiseScans)
|
->set("optimize_scans", baton->jpegOptimiseScans)
|
||||||
->set("optimize_coding", TRUE)));
|
->set("optimize_coding", baton->jpegOptimiseCoding)));
|
||||||
baton->bufferOut = static_cast<char*>(area->data);
|
baton->bufferOut = static_cast<char*>(area->data);
|
||||||
baton->bufferOutLength = area->length;
|
baton->bufferOutLength = area->length;
|
||||||
area->free_fn = nullptr;
|
area->free_fn = nullptr;
|
||||||
@@ -845,9 +858,10 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
->set("interlace", baton->jpegProgressive)
|
->set("interlace", baton->jpegProgressive)
|
||||||
->set("no_subsample", baton->jpegChromaSubsampling == "4:4:4")
|
->set("no_subsample", baton->jpegChromaSubsampling == "4:4:4")
|
||||||
->set("trellis_quant", baton->jpegTrellisQuantisation)
|
->set("trellis_quant", baton->jpegTrellisQuantisation)
|
||||||
|
->set("quant_table", baton->jpegQuantisationTable)
|
||||||
->set("overshoot_deringing", baton->jpegOvershootDeringing)
|
->set("overshoot_deringing", baton->jpegOvershootDeringing)
|
||||||
->set("optimize_scans", baton->jpegOptimiseScans)
|
->set("optimize_scans", baton->jpegOptimiseScans)
|
||||||
->set("optimize_coding", TRUE));
|
->set("optimize_coding", baton->jpegOptimiseCoding));
|
||||||
baton->formatOut = "jpeg";
|
baton->formatOut = "jpeg";
|
||||||
baton->channels = std::min(baton->channels, 3);
|
baton->channels = std::min(baton->channels, 3);
|
||||||
} else if (baton->formatOut == "png" || (mightMatchInput && isPng) || (willMatchInput &&
|
} else if (baton->formatOut == "png" || (mightMatchInput && isPng) || (willMatchInput &&
|
||||||
@@ -924,21 +938,30 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
{"interlace", baton->jpegProgressive ? "TRUE" : "FALSE"},
|
{"interlace", baton->jpegProgressive ? "TRUE" : "FALSE"},
|
||||||
{"no_subsample", baton->jpegChromaSubsampling == "4:4:4" ? "TRUE": "FALSE"},
|
{"no_subsample", baton->jpegChromaSubsampling == "4:4:4" ? "TRUE": "FALSE"},
|
||||||
{"trellis_quant", baton->jpegTrellisQuantisation ? "TRUE" : "FALSE"},
|
{"trellis_quant", baton->jpegTrellisQuantisation ? "TRUE" : "FALSE"},
|
||||||
|
{"quant_table", std::to_string(baton->jpegQuantisationTable)},
|
||||||
{"overshoot_deringing", baton->jpegOvershootDeringing ? "TRUE": "FALSE"},
|
{"overshoot_deringing", baton->jpegOvershootDeringing ? "TRUE": "FALSE"},
|
||||||
{"optimize_scans", baton->jpegOptimiseScans ? "TRUE": "FALSE"},
|
{"optimize_scans", baton->jpegOptimiseScans ? "TRUE": "FALSE"},
|
||||||
{"optimize_coding", "TRUE"}
|
{"optimize_coding", baton->jpegOptimiseCoding ? "TRUE": "FALSE"}
|
||||||
};
|
};
|
||||||
suffix = AssembleSuffixString(extname, options);
|
suffix = AssembleSuffixString(extname, options);
|
||||||
}
|
}
|
||||||
// Write DZ to file
|
// Write DZ to file
|
||||||
image.dzsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
vips::VOption *options = VImage::option()
|
||||||
->set("strip", !baton->withMetadata)
|
->set("strip", !baton->withMetadata)
|
||||||
->set("tile_size", baton->tileSize)
|
->set("tile_size", baton->tileSize)
|
||||||
->set("overlap", baton->tileOverlap)
|
->set("overlap", baton->tileOverlap)
|
||||||
->set("container", baton->tileContainer)
|
->set("container", baton->tileContainer)
|
||||||
->set("layout", baton->tileLayout)
|
->set("layout", baton->tileLayout)
|
||||||
->set("suffix", const_cast<char*>(suffix.data()))
|
->set("suffix", const_cast<char*>(suffix.data()))
|
||||||
->set("angle", CalculateAngleRotation(baton->tileAngle)));
|
->set("angle", CalculateAngleRotation(baton->tileAngle));
|
||||||
|
|
||||||
|
// libvips chooses a default depth based on layout. Instead of replicating that logic here by
|
||||||
|
// not passing anything - libvips will handle choice
|
||||||
|
if (baton->tileDepth < VIPS_FOREIGN_DZ_DEPTH_LAST) {
|
||||||
|
options->set("depth", baton->tileDepth);
|
||||||
|
}
|
||||||
|
|
||||||
|
image.dzsave(const_cast<char*>(baton->fileOut.data()), options);
|
||||||
baton->formatOut = "dz";
|
baton->formatOut = "dz";
|
||||||
} else if (baton->formatOut == "v" || (mightMatchInput && isV) ||
|
} else if (baton->formatOut == "v" || (mightMatchInput && isV) ||
|
||||||
(willMatchInput && inputImageType == ImageType::VIPS)) {
|
(willMatchInput && inputImageType == ImageType::VIPS)) {
|
||||||
@@ -1229,6 +1252,7 @@ NAN_METHOD(pipeline) {
|
|||||||
baton->extendLeft = AttrTo<int32_t>(options, "extendLeft");
|
baton->extendLeft = AttrTo<int32_t>(options, "extendLeft");
|
||||||
baton->extendRight = AttrTo<int32_t>(options, "extendRight");
|
baton->extendRight = AttrTo<int32_t>(options, "extendRight");
|
||||||
baton->extractChannel = AttrTo<int32_t>(options, "extractChannel");
|
baton->extractChannel = AttrTo<int32_t>(options, "extractChannel");
|
||||||
|
baton->removeAlpha = AttrTo<bool>(options, "removeAlpha");
|
||||||
if (HasAttr(options, "boolean")) {
|
if (HasAttr(options, "boolean")) {
|
||||||
baton->boolean = CreateInputDescriptor(AttrAs<v8::Object>(options, "boolean"), buffersToPersist);
|
baton->boolean = CreateInputDescriptor(AttrAs<v8::Object>(options, "boolean"), buffersToPersist);
|
||||||
baton->booleanOp = sharp::GetBooleanOperation(AttrAsStr(options, "booleanOp"));
|
baton->booleanOp = sharp::GetBooleanOperation(AttrAsStr(options, "booleanOp"));
|
||||||
@@ -1263,8 +1287,10 @@ NAN_METHOD(pipeline) {
|
|||||||
baton->jpegProgressive = AttrTo<bool>(options, "jpegProgressive");
|
baton->jpegProgressive = AttrTo<bool>(options, "jpegProgressive");
|
||||||
baton->jpegChromaSubsampling = AttrAsStr(options, "jpegChromaSubsampling");
|
baton->jpegChromaSubsampling = AttrAsStr(options, "jpegChromaSubsampling");
|
||||||
baton->jpegTrellisQuantisation = AttrTo<bool>(options, "jpegTrellisQuantisation");
|
baton->jpegTrellisQuantisation = AttrTo<bool>(options, "jpegTrellisQuantisation");
|
||||||
|
baton->jpegQuantisationTable = AttrTo<uint32_t>(options, "jpegQuantisationTable");
|
||||||
baton->jpegOvershootDeringing = AttrTo<bool>(options, "jpegOvershootDeringing");
|
baton->jpegOvershootDeringing = AttrTo<bool>(options, "jpegOvershootDeringing");
|
||||||
baton->jpegOptimiseScans = AttrTo<bool>(options, "jpegOptimiseScans");
|
baton->jpegOptimiseScans = AttrTo<bool>(options, "jpegOptimiseScans");
|
||||||
|
baton->jpegOptimiseCoding = AttrTo<bool>(options, "jpegOptimiseCoding");
|
||||||
baton->pngProgressive = AttrTo<bool>(options, "pngProgressive");
|
baton->pngProgressive = AttrTo<bool>(options, "pngProgressive");
|
||||||
baton->pngCompressionLevel = AttrTo<uint32_t>(options, "pngCompressionLevel");
|
baton->pngCompressionLevel = AttrTo<uint32_t>(options, "pngCompressionLevel");
|
||||||
baton->pngAdaptiveFiltering = AttrTo<bool>(options, "pngAdaptiveFiltering");
|
baton->pngAdaptiveFiltering = AttrTo<bool>(options, "pngAdaptiveFiltering");
|
||||||
@@ -1303,6 +1329,17 @@ NAN_METHOD(pipeline) {
|
|||||||
baton->tileLayout = VIPS_FOREIGN_DZ_LAYOUT_DZ;
|
baton->tileLayout = VIPS_FOREIGN_DZ_LAYOUT_DZ;
|
||||||
}
|
}
|
||||||
baton->tileFormat = AttrAsStr(options, "tileFormat");
|
baton->tileFormat = AttrAsStr(options, "tileFormat");
|
||||||
|
std::string tileDepth = AttrAsStr(options, "tileDepth");
|
||||||
|
if (tileDepth == "onetile") {
|
||||||
|
baton->tileDepth = VIPS_FOREIGN_DZ_DEPTH_ONETILE;
|
||||||
|
} else if (tileDepth == "one") {
|
||||||
|
baton->tileDepth = VIPS_FOREIGN_DZ_DEPTH_ONE;
|
||||||
|
} else if (tileDepth == "onepixel") {
|
||||||
|
baton->tileDepth = VIPS_FOREIGN_DZ_DEPTH_ONEPIXEL;
|
||||||
|
} else {
|
||||||
|
// signal that we do not want to pass any value to dzSave
|
||||||
|
baton->tileDepth = VIPS_FOREIGN_DZ_DEPTH_LAST;
|
||||||
|
}
|
||||||
// Force random access for certain operations
|
// Force random access for certain operations
|
||||||
if (baton->accessMethod == VIPS_ACCESS_SEQUENTIAL && (
|
if (baton->accessMethod == VIPS_ACCESS_SEQUENTIAL && (
|
||||||
baton->trimTolerance != 0 || baton->normalise ||
|
baton->trimTolerance != 0 || baton->normalise ||
|
||||||
|
|||||||
@@ -102,8 +102,10 @@ struct PipelineBaton {
|
|||||||
bool jpegProgressive;
|
bool jpegProgressive;
|
||||||
std::string jpegChromaSubsampling;
|
std::string jpegChromaSubsampling;
|
||||||
bool jpegTrellisQuantisation;
|
bool jpegTrellisQuantisation;
|
||||||
|
int jpegQuantisationTable;
|
||||||
bool jpegOvershootDeringing;
|
bool jpegOvershootDeringing;
|
||||||
bool jpegOptimiseScans;
|
bool jpegOptimiseScans;
|
||||||
|
bool jpegOptimiseCoding;
|
||||||
bool pngProgressive;
|
bool pngProgressive;
|
||||||
int pngCompressionLevel;
|
int pngCompressionLevel;
|
||||||
bool pngAdaptiveFiltering;
|
bool pngAdaptiveFiltering;
|
||||||
@@ -129,6 +131,7 @@ struct PipelineBaton {
|
|||||||
VipsOperationBoolean booleanOp;
|
VipsOperationBoolean booleanOp;
|
||||||
VipsOperationBoolean bandBoolOp;
|
VipsOperationBoolean bandBoolOp;
|
||||||
int extractChannel;
|
int extractChannel;
|
||||||
|
bool removeAlpha;
|
||||||
VipsInterpretation colourspace;
|
VipsInterpretation colourspace;
|
||||||
int tileSize;
|
int tileSize;
|
||||||
int tileOverlap;
|
int tileOverlap;
|
||||||
@@ -136,6 +139,7 @@ struct PipelineBaton {
|
|||||||
VipsForeignDzLayout tileLayout;
|
VipsForeignDzLayout tileLayout;
|
||||||
std::string tileFormat;
|
std::string tileFormat;
|
||||||
int tileAngle;
|
int tileAngle;
|
||||||
|
VipsForeignDzDepth tileDepth;
|
||||||
|
|
||||||
PipelineBaton():
|
PipelineBaton():
|
||||||
input(nullptr),
|
input(nullptr),
|
||||||
@@ -187,8 +191,10 @@ struct PipelineBaton {
|
|||||||
jpegProgressive(false),
|
jpegProgressive(false),
|
||||||
jpegChromaSubsampling("4:2:0"),
|
jpegChromaSubsampling("4:2:0"),
|
||||||
jpegTrellisQuantisation(false),
|
jpegTrellisQuantisation(false),
|
||||||
|
jpegQuantisationTable(0),
|
||||||
jpegOvershootDeringing(false),
|
jpegOvershootDeringing(false),
|
||||||
jpegOptimiseScans(false),
|
jpegOptimiseScans(false),
|
||||||
|
jpegOptimiseCoding(true),
|
||||||
pngProgressive(false),
|
pngProgressive(false),
|
||||||
pngCompressionLevel(9),
|
pngCompressionLevel(9),
|
||||||
pngAdaptiveFiltering(false),
|
pngAdaptiveFiltering(false),
|
||||||
@@ -209,12 +215,14 @@ struct PipelineBaton {
|
|||||||
booleanOp(VIPS_OPERATION_BOOLEAN_LAST),
|
booleanOp(VIPS_OPERATION_BOOLEAN_LAST),
|
||||||
bandBoolOp(VIPS_OPERATION_BOOLEAN_LAST),
|
bandBoolOp(VIPS_OPERATION_BOOLEAN_LAST),
|
||||||
extractChannel(-1),
|
extractChannel(-1),
|
||||||
|
removeAlpha(false),
|
||||||
colourspace(VIPS_INTERPRETATION_LAST),
|
colourspace(VIPS_INTERPRETATION_LAST),
|
||||||
tileSize(256),
|
tileSize(256),
|
||||||
tileOverlap(0),
|
tileOverlap(0),
|
||||||
tileContainer(VIPS_FOREIGN_DZ_CONTAINER_FS),
|
tileContainer(VIPS_FOREIGN_DZ_CONTAINER_FS),
|
||||||
tileLayout(VIPS_FOREIGN_DZ_LAYOUT_DZ),
|
tileLayout(VIPS_FOREIGN_DZ_LAYOUT_DZ),
|
||||||
tileAngle(0){
|
tileAngle(0),
|
||||||
|
tileDepth(VIPS_FOREIGN_DZ_DEPTH_LAST){
|
||||||
background[0] = 0.0;
|
background[0] = 0.0;
|
||||||
background[1] = 0.0;
|
background[1] = 0.0;
|
||||||
background[2] = 0.0;
|
background[2] = 0.0;
|
||||||
|
|||||||
19
src/stats.cc
19
src/stats.cc
@@ -59,7 +59,6 @@ class StatsWorker : public Nan::AsyncWorker {
|
|||||||
using sharp::MaximumImageAlpha;
|
using sharp::MaximumImageAlpha;
|
||||||
|
|
||||||
vips::VImage image;
|
vips::VImage image;
|
||||||
vips::VImage stats;
|
|
||||||
sharp::ImageType imageType = sharp::ImageType::UNKNOWN;
|
sharp::ImageType imageType = sharp::ImageType::UNKNOWN;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -69,9 +68,8 @@ class StatsWorker : public Nan::AsyncWorker {
|
|||||||
}
|
}
|
||||||
if (imageType != sharp::ImageType::UNKNOWN) {
|
if (imageType != sharp::ImageType::UNKNOWN) {
|
||||||
try {
|
try {
|
||||||
stats = image.stats();
|
vips::VImage stats = image.stats();
|
||||||
int bands = image.bands();
|
int const bands = image.bands();
|
||||||
double const max = MaximumImageAlpha(image.interpretation());
|
|
||||||
for (int b = 1; b <= bands; b++) {
|
for (int b = 1; b <= bands; b++) {
|
||||||
ChannelStats cStats(static_cast<int>(stats.getpoint(STAT_MIN_INDEX, b).front()),
|
ChannelStats cStats(static_cast<int>(stats.getpoint(STAT_MIN_INDEX, b).front()),
|
||||||
static_cast<int>(stats.getpoint(STAT_MAX_INDEX, b).front()),
|
static_cast<int>(stats.getpoint(STAT_MAX_INDEX, b).front()),
|
||||||
@@ -83,11 +81,15 @@ class StatsWorker : public Nan::AsyncWorker {
|
|||||||
static_cast<int>(stats.getpoint(STAT_MAXY_INDEX, b).front()));
|
static_cast<int>(stats.getpoint(STAT_MAXY_INDEX, b).front()));
|
||||||
baton->channelStats.push_back(cStats);
|
baton->channelStats.push_back(cStats);
|
||||||
}
|
}
|
||||||
|
// Image is not opaque when alpha layer is present and contains a non-mamixa value
|
||||||
// alpha layer is there and the last band i.e. alpha has its max value greater than 0)
|
if (sharp::HasAlpha(image)) {
|
||||||
if (sharp::HasAlpha(image) && stats.getpoint(STAT_MIN_INDEX, bands).front() != max) {
|
double const minAlpha = static_cast<double>(stats.getpoint(STAT_MIN_INDEX, bands).front());
|
||||||
baton->isOpaque = false;
|
if (minAlpha != MaximumImageAlpha(image.interpretation())) {
|
||||||
|
baton->isOpaque = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Estimate entropy via histogram of greyscale value frequency
|
||||||
|
baton->entropy = std::abs(image.colourspace(VIPS_INTERPRETATION_B_W)[0].hist_find().hist_entropy());
|
||||||
} catch (vips::VError const &err) {
|
} catch (vips::VError const &err) {
|
||||||
(baton->err).append(err.what());
|
(baton->err).append(err.what());
|
||||||
}
|
}
|
||||||
@@ -130,6 +132,7 @@ class StatsWorker : public Nan::AsyncWorker {
|
|||||||
|
|
||||||
Set(info, New("channels").ToLocalChecked(), channels);
|
Set(info, New("channels").ToLocalChecked(), channels);
|
||||||
Set(info, New("isOpaque").ToLocalChecked(), New<v8::Boolean>(baton->isOpaque));
|
Set(info, New("isOpaque").ToLocalChecked(), New<v8::Boolean>(baton->isOpaque));
|
||||||
|
Set(info, New("entropy").ToLocalChecked(), New<v8::Number>(baton->entropy));
|
||||||
argv[1] = info;
|
argv[1] = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,12 +51,14 @@ struct StatsBaton {
|
|||||||
// Output
|
// Output
|
||||||
std::vector<ChannelStats> channelStats;
|
std::vector<ChannelStats> channelStats;
|
||||||
bool isOpaque;
|
bool isOpaque;
|
||||||
|
double entropy;
|
||||||
|
|
||||||
std::string err;
|
std::string err;
|
||||||
|
|
||||||
StatsBaton():
|
StatsBaton():
|
||||||
input(nullptr),
|
input(nullptr),
|
||||||
isOpaque(true)
|
isOpaque(true),
|
||||||
|
entropy(0.0)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
BIN
test/fixtures/expected/extract-alpha-16bit.jpg
vendored
Normal file
BIN
test/fixtures/expected/extract-alpha-16bit.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 685 B |
BIN
test/fixtures/expected/extract-lch.jpg
vendored
Normal file
BIN
test/fixtures/expected/extract-lch.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -81,35 +81,45 @@ describe('Alpha transparency', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Enlargement with non-nearest neighbor interpolation shouldn’t cause dark edges', function (done) {
|
it('Enlargement with non-nearest neighbor interpolation shouldn’t cause dark edges', function () {
|
||||||
const base = 'alpha-premultiply-enlargement-2048x1536-paper.png';
|
const base = 'alpha-premultiply-enlargement-2048x1536-paper.png';
|
||||||
const actual = fixtures.path('output.' + base);
|
const actual = fixtures.path('output.' + base);
|
||||||
const expected = fixtures.expected(base);
|
const expected = fixtures.expected(base);
|
||||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
return sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||||
.resize(2048, 1536)
|
.resize(2048, 1536)
|
||||||
.toFile(actual, function (err) {
|
.toFile(actual)
|
||||||
if (err) {
|
.then(function () {
|
||||||
done(err);
|
fixtures.assertMaxColourDistance(actual, expected, 102);
|
||||||
} else {
|
|
||||||
fixtures.assertMaxColourDistance(actual, expected, 102);
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Reduction with non-nearest neighbor interpolation shouldn’t cause dark edges', function (done) {
|
it('Reduction with non-nearest neighbor interpolation shouldn’t cause dark edges', function () {
|
||||||
const base = 'alpha-premultiply-reduction-1024x768-paper.png';
|
const base = 'alpha-premultiply-reduction-1024x768-paper.png';
|
||||||
const actual = fixtures.path('output.' + base);
|
const actual = fixtures.path('output.' + base);
|
||||||
const expected = fixtures.expected(base);
|
const expected = fixtures.expected(base);
|
||||||
sharp(fixtures.inputPngAlphaPremultiplicationLarge)
|
return sharp(fixtures.inputPngAlphaPremultiplicationLarge)
|
||||||
.resize(1024, 768)
|
.resize(1024, 768)
|
||||||
.toFile(actual, function (err) {
|
.toFile(actual)
|
||||||
if (err) {
|
.then(function () {
|
||||||
done(err);
|
fixtures.assertMaxColourDistance(actual, expected, 102);
|
||||||
} else {
|
|
||||||
fixtures.assertMaxColourDistance(actual, expected, 102);
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Removes alpha from fixtures with transparency, ignores those without', function () {
|
||||||
|
return Promise.all([
|
||||||
|
fixtures.inputPngWithTransparency,
|
||||||
|
fixtures.inputPngWithTransparency16bit,
|
||||||
|
fixtures.inputWebPWithTransparency,
|
||||||
|
fixtures.inputJpg,
|
||||||
|
fixtures.inputPng,
|
||||||
|
fixtures.inputWebP
|
||||||
|
].map(function (input) {
|
||||||
|
return sharp(input)
|
||||||
|
.removeAlpha()
|
||||||
|
.toBuffer({ resolveWithObject: true })
|
||||||
|
.then(function (result) {
|
||||||
|
assert.strictEqual(3, result.info.channels);
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -177,25 +177,6 @@ describe('Crop', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Clamp before crop when one post-resize dimension is below target', function () {
|
|
||||||
return sharp(fixtures.inputJpg)
|
|
||||||
.resize(1024, 1034)
|
|
||||||
.toBuffer()
|
|
||||||
.then(function (input) {
|
|
||||||
return sharp(input)
|
|
||||||
.rotate(270)
|
|
||||||
.resize(256)
|
|
||||||
.crop(sharp.strategy.entropy)
|
|
||||||
.toBuffer({ resolveWithObject: true })
|
|
||||||
.then(function (result) {
|
|
||||||
assert.strictEqual(256, result.info.width);
|
|
||||||
assert.strictEqual(253, result.info.height);
|
|
||||||
assert.strictEqual(0, result.info.cropOffsetLeft);
|
|
||||||
assert.strictEqual(0, result.info.cropOffsetTop);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Entropy-based strategy', function () {
|
describe('Entropy-based strategy', function () {
|
||||||
it('JPEG', function (done) {
|
it('JPEG', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
|
|||||||
@@ -54,6 +54,32 @@ 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('Alpha from 16-bit PNG', function (done) {
|
||||||
|
const output = fixtures.path('output.extract-alpha-16bit.jpg');
|
||||||
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
|
.extractChannel(3)
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
fixtures.assertMaxColourDistance(output, fixtures.expected('extract-alpha-16bit.jpg'));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Invalid channel number', function () {
|
it('Invalid channel number', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
|
|||||||
@@ -389,6 +389,16 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Invalid JPEG quantisation table', function () {
|
||||||
|
[-1, 88.2, 'test'].forEach(function (table) {
|
||||||
|
it(table.toString(), function () {
|
||||||
|
assert.throws(function () {
|
||||||
|
sharp().jpeg({ quantisationTable: table });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Progressive JPEG image', function (done) {
|
it('Progressive JPEG image', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
@@ -826,6 +836,67 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Optimise coding generates smaller output length', function (done) {
|
||||||
|
// First generate with optimize coding enabled (default)
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.jpeg()
|
||||||
|
.toBuffer(function (err, withOptimiseCoding, withInfo) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, withOptimiseCoding.length > 0);
|
||||||
|
assert.strictEqual(withOptimiseCoding.length, withInfo.size);
|
||||||
|
assert.strictEqual('jpeg', withInfo.format);
|
||||||
|
assert.strictEqual(320, withInfo.width);
|
||||||
|
assert.strictEqual(240, withInfo.height);
|
||||||
|
// Then generate with coding disabled
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.jpeg({ optimizeCoding: false })
|
||||||
|
.toBuffer(function (err, withoutOptimiseCoding, withoutInfo) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, withoutOptimiseCoding.length > 0);
|
||||||
|
assert.strictEqual(withoutOptimiseCoding.length, withoutInfo.size);
|
||||||
|
assert.strictEqual('jpeg', withoutInfo.format);
|
||||||
|
assert.strictEqual(320, withoutInfo.width);
|
||||||
|
assert.strictEqual(240, withoutInfo.height);
|
||||||
|
// Verify optimised image is of a smaller size
|
||||||
|
assert.strictEqual(true, withOptimiseCoding.length < withoutOptimiseCoding.length);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Specifying quantisation table provides different JPEG', function (done) {
|
||||||
|
// First generate with default quantisation table
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.jpeg({ optimiseCoding: false })
|
||||||
|
.toBuffer(function (err, withDefaultQuantisationTable, withInfo) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, withDefaultQuantisationTable.length > 0);
|
||||||
|
assert.strictEqual(withDefaultQuantisationTable.length, withInfo.size);
|
||||||
|
assert.strictEqual('jpeg', withInfo.format);
|
||||||
|
assert.strictEqual(320, withInfo.width);
|
||||||
|
assert.strictEqual(240, withInfo.height);
|
||||||
|
// Then generate with different quantisation table
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.jpeg({ optimiseCoding: false, quantisationTable: 3 })
|
||||||
|
.toBuffer(function (err, withQuantTable3, withoutInfo) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, withQuantTable3.length > 0);
|
||||||
|
assert.strictEqual(withQuantTable3.length, withoutInfo.size);
|
||||||
|
assert.strictEqual('jpeg', withoutInfo.format);
|
||||||
|
assert.strictEqual(320, withoutInfo.width);
|
||||||
|
assert.strictEqual(240, withoutInfo.height);
|
||||||
|
|
||||||
|
// Verify image is same (as mozjpeg may not be present) size or less
|
||||||
|
assert.strictEqual(true, withQuantTable3.length <= withDefaultQuantisationTable.length);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Convert SVG to PNG at default 72DPI', function (done) {
|
it('Convert SVG to PNG at default 72DPI', function (done) {
|
||||||
sharp(fixtures.inputSvg)
|
sharp(fixtures.inputSvg)
|
||||||
.resize(1024)
|
.resize(1024)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const fs = require('fs');
|
||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
const libvips = require('../../lib/libvips');
|
const libvips = require('../../lib/libvips');
|
||||||
|
|
||||||
@@ -66,5 +67,11 @@ describe('libvips binaries', function () {
|
|||||||
|
|
||||||
delete process.env.SHARP_IGNORE_GLOBAL_LIBVIPS;
|
delete process.env.SHARP_IGNORE_GLOBAL_LIBVIPS;
|
||||||
});
|
});
|
||||||
|
it('cachePath returns a valid path ending with _libvips', function () {
|
||||||
|
const cachePath = libvips.cachePath();
|
||||||
|
assert.strictEqual('string', typeof cachePath);
|
||||||
|
assert.strictEqual('_libvips', cachePath.substr(-8));
|
||||||
|
assert.strictEqual(true, fs.existsSync(cachePath));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ describe('Image Stats', function () {
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0]['min']);
|
assert.strictEqual(0, stats.channels[0]['min']);
|
||||||
@@ -82,6 +83,7 @@ describe('Image Stats', function () {
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 0.3409031108021736));
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0]['min']);
|
assert.strictEqual(0, stats.channels[0]['min']);
|
||||||
@@ -105,7 +107,9 @@ describe('Image Stats', function () {
|
|||||||
it('PNG with transparency', function (done) {
|
it('PNG with transparency', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency).stats(function (err, stats) {
|
sharp(fixtures.inputPngWithTransparency).stats(function (err, stats) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
assert.strictEqual(false, stats.isOpaque);
|
assert.strictEqual(false, stats.isOpaque);
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 0.06778064835816622));
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0]['min']);
|
assert.strictEqual(0, stats.channels[0]['min']);
|
||||||
@@ -180,6 +184,7 @@ describe('Image Stats', function () {
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
assert.strictEqual(false, stats.isOpaque);
|
assert.strictEqual(false, stats.isOpaque);
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 0));
|
||||||
|
|
||||||
// alpha channel
|
// alpha channel
|
||||||
assert.strictEqual(0, stats.channels[3]['min']);
|
assert.strictEqual(0, stats.channels[3]['min']);
|
||||||
@@ -204,7 +209,9 @@ describe('Image Stats', function () {
|
|||||||
it('Tiff', function (done) {
|
it('Tiff', function (done) {
|
||||||
sharp(fixtures.inputTiff).stats(function (err, stats) {
|
sharp(fixtures.inputTiff).stats(function (err, stats) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 0.3851250782608986));
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0]['min']);
|
assert.strictEqual(0, stats.channels[0]['min']);
|
||||||
@@ -231,6 +238,7 @@ describe('Image Stats', function () {
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.51758075132966));
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0]['min']);
|
assert.strictEqual(0, stats.channels[0]['min']);
|
||||||
@@ -289,6 +297,7 @@ describe('Image Stats', function () {
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 6.087309412541799));
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(35, stats.channels[0]['min']);
|
assert.strictEqual(35, stats.channels[0]['min']);
|
||||||
@@ -345,7 +354,9 @@ describe('Image Stats', function () {
|
|||||||
it('Grayscale GIF with alpha', function (done) {
|
it('Grayscale GIF with alpha', function (done) {
|
||||||
sharp(fixtures.inputGifGreyPlusAlpha).stats(function (err, stats) {
|
sharp(fixtures.inputGifGreyPlusAlpha).stats(function (err, stats) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
assert.strictEqual(false, stats.isOpaque);
|
assert.strictEqual(false, stats.isOpaque);
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 1));
|
||||||
|
|
||||||
// gray channel
|
// gray channel
|
||||||
assert.strictEqual(0, stats.channels[0]['min']);
|
assert.strictEqual(0, stats.channels[0]['min']);
|
||||||
@@ -387,7 +398,9 @@ describe('Image Stats', function () {
|
|||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const pipeline = sharp().stats(function (err, stats) {
|
const pipeline = sharp().stats(function (err, stats) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0]['min']);
|
assert.strictEqual(0, stats.channels[0]['min']);
|
||||||
@@ -449,6 +462,7 @@ describe('Image Stats', function () {
|
|||||||
|
|
||||||
return pipeline.stats().then(function (stats) {
|
return pipeline.stats().then(function (stats) {
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0]['min']);
|
assert.strictEqual(0, stats.channels[0]['min']);
|
||||||
@@ -505,6 +519,7 @@ describe('Image Stats', function () {
|
|||||||
it('File in, Promise out', function () {
|
it('File in, Promise out', function () {
|
||||||
return sharp(fixtures.inputJpg).stats().then(function (stats) {
|
return sharp(fixtures.inputJpg).stats().then(function (stats) {
|
||||||
assert.strictEqual(true, stats.isOpaque);
|
assert.strictEqual(true, stats.isOpaque);
|
||||||
|
assert.strictEqual(true, isInAcceptableRange(stats.entropy, 7.319914765248541));
|
||||||
|
|
||||||
// red channel
|
// red channel
|
||||||
assert.strictEqual(0, stats.channels[0]['min']);
|
assert.strictEqual(0, stats.channels[0]['min']);
|
||||||
|
|||||||
@@ -46,6 +46,51 @@ const assertDeepZoomTiles = function (directory, expectedSize, expectedLevels, d
|
|||||||
}, done);
|
}, done);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const assertZoomifyTiles = function (directory, expectedTileSize, expectedLevels, done) {
|
||||||
|
fs.stat(path.join(directory, 'ImageProperties.xml'), function (err, stat) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.ok(stat.isFile());
|
||||||
|
assert.ok(stat.size > 0);
|
||||||
|
|
||||||
|
let maxTileLevel = -1;
|
||||||
|
fs.readdirSync(path.join(directory, 'TileGroup0')).forEach(function (tile) {
|
||||||
|
// Verify tile file name
|
||||||
|
assert.ok(/^[0-9]+-[0-9]+-[0-9]+\.jpg$/.test(tile));
|
||||||
|
let level = parseInt(tile.split('-')[0]);
|
||||||
|
maxTileLevel = Math.max(maxTileLevel, level);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(maxTileLevel + 1, expectedLevels); // add one to account for zero level tile
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const assertGoogleTiles = function (directory, expectedTileSize, expectedLevels, done) {
|
||||||
|
const levels = fs.readdirSync(directory);
|
||||||
|
assert.strictEqual(expectedLevels, levels.length - 1); // subtract one to account for default blank tile
|
||||||
|
|
||||||
|
fs.stat(path.join(directory, 'blank.png'), function (err, stat) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.ok(stat.isFile());
|
||||||
|
assert.ok(stat.size > 0);
|
||||||
|
|
||||||
|
// Basic check to confirm lowest and highest level tiles exist
|
||||||
|
fs.stat(path.join(directory, '0', '0', '0.jpg'), function (err, stat) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, stat.isFile());
|
||||||
|
assert.strictEqual(true, stat.size > 0);
|
||||||
|
|
||||||
|
fs.stat(path.join(directory, (expectedLevels - 1).toString(), '0', '0.jpg'), function (err, stat) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, stat.isFile());
|
||||||
|
assert.strictEqual(true, stat.size > 0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
describe('Tile', function () {
|
describe('Tile', function () {
|
||||||
it('Valid size values pass', function () {
|
it('Valid size values pass', function () {
|
||||||
[1, 8192].forEach(function (size) {
|
[1, 8192].forEach(function (size) {
|
||||||
@@ -144,6 +189,26 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Valid depths pass', function () {
|
||||||
|
['onepixel', 'onetile', 'one'].forEach(function (depth) {
|
||||||
|
assert.doesNotThrow(function (depth) {
|
||||||
|
sharp().tile({
|
||||||
|
depth: depth
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Invalid depths fail', function () {
|
||||||
|
['depth', 1].forEach(function (depth) {
|
||||||
|
assert.throws(function () {
|
||||||
|
sharp().tile({
|
||||||
|
depth: depth
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Prevent larger overlap than default size', function () {
|
it('Prevent larger overlap than default size', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
sharp().tile({
|
sharp().tile({
|
||||||
@@ -251,6 +316,54 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Deep Zoom layout with depth of one', function (done) {
|
||||||
|
const directory = fixtures.path('output.512_depth_one.dzi_files');
|
||||||
|
rimraf(directory, function () {
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.tile({
|
||||||
|
size: 512,
|
||||||
|
depth: 'one'
|
||||||
|
})
|
||||||
|
.toFile(fixtures.path('output.512_depth_one.dzi'), function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
// Verify only one depth generated
|
||||||
|
assertDeepZoomTiles(directory, 512, 1, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Deep Zoom layout with depth of onepixel', function (done) {
|
||||||
|
const directory = fixtures.path('output.512_depth_onepixel.dzi_files');
|
||||||
|
rimraf(directory, function () {
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.tile({
|
||||||
|
size: 512,
|
||||||
|
depth: 'onepixel'
|
||||||
|
})
|
||||||
|
.toFile(fixtures.path('output.512_depth_onepixel.dzi'), function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
// Verify only one depth generated
|
||||||
|
assertDeepZoomTiles(directory, 512, 13, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Deep Zoom layout with depth of onetile', function (done) {
|
||||||
|
const directory = fixtures.path('output.256_depth_onetile.dzi_files');
|
||||||
|
rimraf(directory, function () {
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.tile({
|
||||||
|
size: 256,
|
||||||
|
depth: 'onetile'
|
||||||
|
})
|
||||||
|
.toFile(fixtures.path('output.256_depth_onetile.dzi'), function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
// Verify only one depth generated
|
||||||
|
assertDeepZoomTiles(directory, 256, 5, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Zoomify layout', function (done) {
|
it('Zoomify layout', function (done) {
|
||||||
const directory = fixtures.path('output.zoomify.dzi');
|
const directory = fixtures.path('output.zoomify.dzi');
|
||||||
rimraf(directory, function () {
|
rimraf(directory, function () {
|
||||||
@@ -275,6 +388,69 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Zoomify layout with depth one', function (done) {
|
||||||
|
const directory = fixtures.path('output.zoomify.depth_one.dzi');
|
||||||
|
rimraf(directory, function () {
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.tile({
|
||||||
|
size: 256,
|
||||||
|
layout: 'zoomify',
|
||||||
|
depth: 'one'
|
||||||
|
})
|
||||||
|
.toFile(directory, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('dz', info.format);
|
||||||
|
assert.strictEqual(2725, info.width);
|
||||||
|
assert.strictEqual(2225, info.height);
|
||||||
|
assert.strictEqual(3, info.channels);
|
||||||
|
assert.strictEqual('number', typeof info.size);
|
||||||
|
assertZoomifyTiles(directory, 256, 1, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Zoomify layout with depth onetile', function (done) {
|
||||||
|
const directory = fixtures.path('output.zoomify.depth_onetile.dzi');
|
||||||
|
rimraf(directory, function () {
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.tile({
|
||||||
|
size: 256,
|
||||||
|
layout: 'zoomify',
|
||||||
|
depth: 'onetile'
|
||||||
|
})
|
||||||
|
.toFile(directory, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('dz', info.format);
|
||||||
|
assert.strictEqual(2725, info.width);
|
||||||
|
assert.strictEqual(2225, info.height);
|
||||||
|
assert.strictEqual(3, info.channels);
|
||||||
|
assert.strictEqual('number', typeof info.size);
|
||||||
|
assertZoomifyTiles(directory, 256, 5, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Zoomify layout with depth onepixel', function (done) {
|
||||||
|
const directory = fixtures.path('output.zoomify.depth_onepixel.dzi');
|
||||||
|
rimraf(directory, function () {
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.tile({
|
||||||
|
size: 256,
|
||||||
|
layout: 'zoomify',
|
||||||
|
depth: 'onepixel'
|
||||||
|
})
|
||||||
|
.toFile(directory, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('dz', info.format);
|
||||||
|
assert.strictEqual(2725, info.width);
|
||||||
|
assert.strictEqual(2225, info.height);
|
||||||
|
assert.strictEqual(3, info.channels);
|
||||||
|
assert.strictEqual('number', typeof info.size);
|
||||||
|
assertZoomifyTiles(directory, 256, 13, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Google layout', function (done) {
|
it('Google layout', function (done) {
|
||||||
const directory = fixtures.path('output.google.dzi');
|
const directory = fixtures.path('output.google.dzi');
|
||||||
rimraf(directory, function () {
|
rimraf(directory, function () {
|
||||||
@@ -410,6 +586,72 @@ describe('Tile', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Google layout with depth one', function (done) {
|
||||||
|
const directory = fixtures.path('output.google_depth_one.dzi');
|
||||||
|
rimraf(directory, function () {
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.tile({
|
||||||
|
layout: 'google',
|
||||||
|
depth: 'one',
|
||||||
|
size: 256
|
||||||
|
})
|
||||||
|
.toFile(directory, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('dz', info.format);
|
||||||
|
assert.strictEqual(2725, info.width);
|
||||||
|
assert.strictEqual(2225, info.height);
|
||||||
|
assert.strictEqual(3, info.channels);
|
||||||
|
assert.strictEqual('number', typeof info.size);
|
||||||
|
|
||||||
|
assertGoogleTiles(directory, 256, 1, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Google layout with depth onepixel', function (done) {
|
||||||
|
const directory = fixtures.path('output.google_depth_onepixel.dzi');
|
||||||
|
rimraf(directory, function () {
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.tile({
|
||||||
|
layout: 'google',
|
||||||
|
depth: 'onepixel',
|
||||||
|
size: 256
|
||||||
|
})
|
||||||
|
.toFile(directory, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('dz', info.format);
|
||||||
|
assert.strictEqual(2725, info.width);
|
||||||
|
assert.strictEqual(2225, info.height);
|
||||||
|
assert.strictEqual(3, info.channels);
|
||||||
|
assert.strictEqual('number', typeof info.size);
|
||||||
|
|
||||||
|
assertGoogleTiles(directory, 256, 13, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Google layout with depth onetile', function (done) {
|
||||||
|
const directory = fixtures.path('output.google_depth_onetile.dzi');
|
||||||
|
rimraf(directory, function () {
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.tile({
|
||||||
|
layout: 'google',
|
||||||
|
depth: 'onetile',
|
||||||
|
size: 256
|
||||||
|
})
|
||||||
|
.toFile(directory, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual('dz', info.format);
|
||||||
|
assert.strictEqual(2725, info.width);
|
||||||
|
assert.strictEqual(2225, info.height);
|
||||||
|
assert.strictEqual(3, info.channels);
|
||||||
|
assert.strictEqual('number', typeof info.size);
|
||||||
|
|
||||||
|
assertGoogleTiles(directory, 256, 5, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Write to ZIP container using file extension', function (done) {
|
it('Write to ZIP container using file extension', function (done) {
|
||||||
const container = fixtures.path('output.dz.container.zip');
|
const container = fixtures.path('output.dz.container.zip');
|
||||||
const extractTo = fixtures.path('output.dz.container');
|
const extractTo = fixtures.path('output.dz.container');
|
||||||
|
|||||||
Reference in New Issue
Block a user