sharp 0.20.8 → 0.21.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -11
- package/binding.gyp +16 -1
- package/docs/api-channel.md +16 -0
- package/docs/api-colour.md +1 -19
- package/docs/api-composite.md +2 -3
- package/docs/api-constructor.md +2 -3
- package/docs/api-input.md +7 -2
- package/docs/api-operation.md +73 -115
- package/docs/api-output.md +9 -0
- package/docs/api-resize.md +160 -108
- package/docs/api-utility.md +4 -7
- package/docs/changelog.md +102 -0
- package/docs/image/sharp-logo.svg +5 -0
- package/docs/index.md +12 -6
- package/docs/install.md +41 -42
- package/docs/performance.md +14 -21
- package/install/libvips.js +28 -24
- package/lib/channel.js +20 -4
- package/lib/colour.js +35 -18
- package/lib/composite.js +2 -3
- package/lib/constructor.js +27 -42
- package/lib/input.js +9 -6
- package/lib/libvips.js +7 -1
- package/lib/operation.js +81 -123
- package/lib/output.js +128 -60
- package/lib/platform.js +4 -1
- package/lib/resize.js +310 -107
- package/lib/utility.js +5 -8
- package/package.json +30 -21
- package/src/common.cc +59 -14
- package/src/common.h +15 -12
- package/src/libvips/cplusplus/VImage.cpp +95 -95
- package/src/libvips/cplusplus/vips-operators.cpp +268 -185
- package/src/metadata.cc +34 -1
- package/src/metadata.h +10 -1
- package/src/operations.cc +47 -49
- package/src/operations.h +13 -2
- package/src/pipeline.cc +101 -95
- package/src/pipeline.h +40 -14
- package/src/sharp.cc +1 -1
- package/src/stats.cc +1 -1
- package/src/stats.h +1 -1
- package/src/utilities.cc +2 -2
- package/src/utilities.h +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# sharp
|
|
2
2
|
|
|
3
|
+
<img src="docs/image/sharp-logo.svg" width="160" height="160" alt="sharp logo" align="right">
|
|
4
|
+
|
|
3
5
|
```sh
|
|
4
6
|
npm install sharp
|
|
5
7
|
```
|
|
@@ -21,8 +23,8 @@ Lanczos resampling ensures quality is not sacrificed for speed.
|
|
|
21
23
|
As well as image resizing, operations such as
|
|
22
24
|
rotation, extraction, compositing and gamma correction are available.
|
|
23
25
|
|
|
24
|
-
Most modern 64-bit OS X, Windows and Linux
|
|
25
|
-
Node versions
|
|
26
|
+
Most modern 64-bit OS X, Windows and Linux systems running
|
|
27
|
+
Node versions 6, 8, 10 and 11
|
|
26
28
|
do not require any additional install or runtime dependencies.
|
|
27
29
|
|
|
28
30
|
## Examples
|
|
@@ -63,29 +65,29 @@ readableStream
|
|
|
63
65
|
.pipe(writableStream);
|
|
64
66
|
```
|
|
65
67
|
|
|
66
|
-
[](https://coveralls.io/r/lovell/sharp?branch=master)
|
|
67
69
|
|
|
68
70
|
### Documentation
|
|
69
71
|
|
|
70
|
-
Visit [sharp.pixelplumbing.com](
|
|
71
|
-
[installation instructions](
|
|
72
|
-
[API documentation](
|
|
73
|
-
[benchmark tests](
|
|
74
|
-
[changelog](
|
|
72
|
+
Visit [sharp.pixelplumbing.com](https://sharp.pixelplumbing.com/) for complete
|
|
73
|
+
[installation instructions](https://sharp.pixelplumbing.com/page/install),
|
|
74
|
+
[API documentation](https://sharp.pixelplumbing.com/page/api),
|
|
75
|
+
[benchmark tests](https://sharp.pixelplumbing.com/page/performance) and
|
|
76
|
+
[changelog](https://sharp.pixelplumbing.com/page/changelog).
|
|
75
77
|
|
|
76
78
|
### Contributing
|
|
77
79
|
|
|
78
80
|
A [guide for contributors](https://github.com/lovell/sharp/blob/master/CONTRIBUTING.md)
|
|
79
81
|
covers reporting bugs, requesting features and submitting code changes.
|
|
80
82
|
|
|
81
|
-
###
|
|
83
|
+
### Licensing
|
|
82
84
|
|
|
83
|
-
Copyright 2013, 2014, 2015, 2016, 2017, 2018 Lovell Fuller and contributors.
|
|
85
|
+
Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 Lovell Fuller and contributors.
|
|
84
86
|
|
|
85
87
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
86
88
|
you may not use this file except in compliance with the License.
|
|
87
89
|
You may obtain a copy of the License at
|
|
88
|
-
[
|
|
90
|
+
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
|
89
91
|
|
|
90
92
|
Unless required by applicable law or agreed to in writing, software
|
|
91
93
|
distributed under the License is distributed on an "AS IS" BASIS,
|
package/binding.gyp
CHANGED
|
@@ -128,9 +128,11 @@
|
|
|
128
128
|
'../vendor/lib/libcairo.so',
|
|
129
129
|
'../vendor/lib/libcroco-0.6.so',
|
|
130
130
|
'../vendor/lib/libexif.so',
|
|
131
|
+
'../vendor/lib/libexpat.so',
|
|
131
132
|
'../vendor/lib/libffi.so',
|
|
132
133
|
'../vendor/lib/libfontconfig.so',
|
|
133
134
|
'../vendor/lib/libfreetype.so',
|
|
135
|
+
'../vendor/lib/libfribidi.so',
|
|
134
136
|
'../vendor/lib/libgdk_pixbuf-2.0.so',
|
|
135
137
|
'../vendor/lib/libgif.so',
|
|
136
138
|
'../vendor/lib/libgio-2.0.so',
|
|
@@ -138,6 +140,7 @@
|
|
|
138
140
|
'../vendor/lib/libgsf-1.so',
|
|
139
141
|
'../vendor/lib/libgthread-2.0.so',
|
|
140
142
|
'../vendor/lib/libharfbuzz.so',
|
|
143
|
+
'../vendor/lib/libharfbuzz-subset.so.0',
|
|
141
144
|
'../vendor/lib/libjpeg.so',
|
|
142
145
|
'../vendor/lib/liblcms2.so',
|
|
143
146
|
'../vendor/lib/liborc-0.4.so',
|
|
@@ -149,6 +152,8 @@
|
|
|
149
152
|
'../vendor/lib/librsvg-2.so',
|
|
150
153
|
'../vendor/lib/libtiff.so',
|
|
151
154
|
'../vendor/lib/libwebp.so',
|
|
155
|
+
'../vendor/lib/libwebpdemux.so',
|
|
156
|
+
'../vendor/lib/libwebpmux.so',
|
|
152
157
|
'../vendor/lib/libxml2.so',
|
|
153
158
|
'../vendor/lib/libz.so',
|
|
154
159
|
# Ensure runtime linking is relative to sharp.node
|
|
@@ -178,13 +183,23 @@
|
|
|
178
183
|
},
|
|
179
184
|
'configurations': {
|
|
180
185
|
'Release': {
|
|
186
|
+
'cflags_cc': [
|
|
187
|
+
'-Wno-cast-function-type',
|
|
188
|
+
'-Wno-deprecated-declarations'
|
|
189
|
+
],
|
|
190
|
+
'xcode_settings': {
|
|
191
|
+
'OTHER_CPLUSPLUSFLAGS': [
|
|
192
|
+
'-Wno-deprecated-declarations'
|
|
193
|
+
]
|
|
194
|
+
},
|
|
181
195
|
'msvs_settings': {
|
|
182
196
|
'VCCLCompilerTool': {
|
|
183
197
|
'ExceptionHandling': 1
|
|
184
198
|
}
|
|
185
199
|
},
|
|
186
200
|
'msvs_disabled_warnings': [
|
|
187
|
-
4275
|
|
201
|
+
4275,
|
|
202
|
+
4996
|
|
188
203
|
]
|
|
189
204
|
}
|
|
190
205
|
},
|
package/docs/api-channel.md
CHANGED
|
@@ -16,6 +16,22 @@ sharp('rgba.png')
|
|
|
16
16
|
|
|
17
17
|
Returns **Sharp**
|
|
18
18
|
|
|
19
|
+
## ensureAlpha
|
|
20
|
+
|
|
21
|
+
Ensure alpha channel, if missing. The added alpha channel will be fully opaque. This is a no-op if the image already has an alpha channel.
|
|
22
|
+
|
|
23
|
+
### Examples
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
sharp('rgb.jpg')
|
|
27
|
+
.ensureAlpha()
|
|
28
|
+
.toFile('rgba.png', function(err, info) {
|
|
29
|
+
// rgba.png is a 4 channel image with a fully opaque alpha channel
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Returns **Sharp**
|
|
34
|
+
|
|
19
35
|
## extractChannel
|
|
20
36
|
|
|
21
37
|
Extract a single channel from a multi-channel image.
|
package/docs/api-colour.md
CHANGED
|
@@ -1,23 +1,5 @@
|
|
|
1
1
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
2
2
|
|
|
3
|
-
## background
|
|
4
|
-
|
|
5
|
-
Set the background for the `embed`, `flatten` and `extend` operations.
|
|
6
|
-
The default background is `{r: 0, g: 0, b: 0, alpha: 1}`, black without transparency.
|
|
7
|
-
|
|
8
|
-
Delegates to the _color_ module, which can throw an Error
|
|
9
|
-
but is liberal in what it accepts, clipping values to sensible min/max.
|
|
10
|
-
The alpha value is a float between `0` (transparent) and `1` (opaque).
|
|
11
|
-
|
|
12
|
-
### Parameters
|
|
13
|
-
|
|
14
|
-
- `rgba` **([String][1] \| [Object][2])** parsed by the [color][3] module to extract values for red, green, blue and alpha.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- Throws **[Error][4]** Invalid parameter
|
|
18
|
-
|
|
19
|
-
Returns **Sharp**
|
|
20
|
-
|
|
21
3
|
## tint
|
|
22
4
|
|
|
23
5
|
Tint the image using the provided chroma while preserving the image luminance.
|
|
@@ -94,4 +76,4 @@ Returns **Sharp**
|
|
|
94
76
|
|
|
95
77
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
96
78
|
|
|
97
|
-
[6]: https://github.com/
|
|
79
|
+
[6]: https://github.com/libvips/libvips/blob/master/libvips/iofuncs/enumtypes.c#L568
|
package/docs/api-composite.md
CHANGED
|
@@ -11,7 +11,7 @@ If the overlay image contains an alpha channel then composition with premultipli
|
|
|
11
11
|
|
|
12
12
|
### Parameters
|
|
13
13
|
|
|
14
|
-
- `overlay` **([Buffer][1] \| [String][2])
|
|
14
|
+
- `overlay` **([Buffer][1] \| [String][2])?** Buffer containing image data or String containing the path to an image file.
|
|
15
15
|
- `options` **[Object][3]?**
|
|
16
16
|
- `options.gravity` **[String][2]** gravity at which to place the overlay. (optional, default `'centre'`)
|
|
17
17
|
- `options.top` **[Number][4]?** the pixel offset from the top edge.
|
|
@@ -35,8 +35,7 @@ If the overlay image contains an alpha channel then composition with premultipli
|
|
|
35
35
|
sharp('input.png')
|
|
36
36
|
.rotate(180)
|
|
37
37
|
.resize(300)
|
|
38
|
-
.flatten()
|
|
39
|
-
.background('#ff6600')
|
|
38
|
+
.flatten( { background: '#ff6600' } )
|
|
40
39
|
.overlayWith('overlay.png', { gravity: sharp.gravity.southeast } )
|
|
41
40
|
.sharpen()
|
|
42
41
|
.withMetadata()
|
package/docs/api-constructor.md
CHANGED
|
@@ -9,9 +9,8 @@
|
|
|
9
9
|
a String containing the path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
|
|
10
10
|
JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
|
11
11
|
- `options` **[Object][3]?** if present, is an Object with optional attributes.
|
|
12
|
-
- `options.failOnError` **[Boolean][4]** by default
|
|
13
|
-
to decode images, even if the data is corrupt or invalid.
|
|
14
|
-
if you'd rather halt processing and raise an error when loading invalid images. (optional, default `false`)
|
|
12
|
+
- `options.failOnError` **[Boolean][4]** by default halt processing and raise an error when loading invalid images.
|
|
13
|
+
Set this flag to `false` if you'd rather apply a "best effort" to decode images, even if the data is corrupt or invalid. (optional, default `true`)
|
|
15
14
|
- `options.density` **[Number][5]** number representing the DPI for vector images. (optional, default `72`)
|
|
16
15
|
- `options.page` **[Number][5]** page number to extract for multi-page input (GIF, TIFF) (optional, default `0`)
|
|
17
16
|
- `options.raw` **[Object][3]?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
package/docs/api-input.md
CHANGED
|
@@ -25,12 +25,17 @@ Fast access to (uncached) image metadata without decoding any compressed image d
|
|
|
25
25
|
A Promises/A+ promise is returned when `callback` is not provided.
|
|
26
26
|
|
|
27
27
|
- `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
|
|
28
|
+
- `size`: Total size of image in bytes, for Stream and Buffer input only
|
|
28
29
|
- `width`: Number of pixels wide (EXIF orientation is not taken into consideration)
|
|
29
30
|
- `height`: Number of pixels high (EXIF orientation is not taken into consideration)
|
|
30
31
|
- `space`: Name of colour space interpretation e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][1]
|
|
31
32
|
- `channels`: Number of bands e.g. `3` for sRGB, `4` for CMYK
|
|
32
33
|
- `depth`: Name of pixel depth format e.g. `uchar`, `char`, `ushort`, `float` [...][2]
|
|
33
34
|
- `density`: Number of pixels per inch (DPI), if present
|
|
35
|
+
- `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
|
36
|
+
- `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
|
37
|
+
- `pages`: Number of pages this TIFF, GIF or PDF image contains.
|
|
38
|
+
- `pageHeight`: Number of pixels high each page in this PDF image will be.
|
|
34
39
|
- `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
|
35
40
|
- `hasAlpha`: Boolean indicating the presence of an alpha transparency channel
|
|
36
41
|
- `orientation`: Number value of the EXIF Orientation header, if present
|
|
@@ -126,9 +131,9 @@ The default behaviour _before_ function call is `false`, meaning the libvips acc
|
|
|
126
131
|
|
|
127
132
|
Returns **Sharp**
|
|
128
133
|
|
|
129
|
-
[1]: https://github.com/
|
|
134
|
+
[1]: https://github.com/libvips/libvips/blob/master/libvips/iofuncs/enumtypes.c#L636
|
|
130
135
|
|
|
131
|
-
[2]: https://github.com/
|
|
136
|
+
[2]: https://github.com/libvips/libvips/blob/master/libvips/iofuncs/enumtypes.c#L672
|
|
132
137
|
|
|
133
138
|
[3]: https://www.npmjs.com/package/icc
|
|
134
139
|
|
package/docs/api-operation.md
CHANGED
|
@@ -5,9 +5,12 @@
|
|
|
5
5
|
Rotate the output image by either an explicit angle
|
|
6
6
|
or auto-orient based on the EXIF `Orientation` tag.
|
|
7
7
|
|
|
8
|
-
If an angle is provided, it is converted to a valid
|
|
8
|
+
If an angle is provided, it is converted to a valid positive degree rotation.
|
|
9
9
|
For example, `-450` will produce a 270deg rotation.
|
|
10
10
|
|
|
11
|
+
When rotating by an angle other than a multiple of 90,
|
|
12
|
+
the background colour can be provided with the `background` option.
|
|
13
|
+
|
|
11
14
|
If no angle is provided, it is determined from the EXIF data.
|
|
12
15
|
Mirroring is supported and may infer the use of a flip operation.
|
|
13
16
|
|
|
@@ -18,7 +21,9 @@ for example `rotate(x).extract(y)` will produce a different result to `extract(y
|
|
|
18
21
|
|
|
19
22
|
### Parameters
|
|
20
23
|
|
|
21
|
-
- `angle` **[Number][1]** angle of rotation
|
|
24
|
+
- `angle` **[Number][1]** angle of rotation. (optional, default `auto`)
|
|
25
|
+
- `options` **[Object][2]?** if present, is an Object with optional attributes.
|
|
26
|
+
- `options.background` **([String][3] \| [Object][2])** parsed by the [color][4] module to extract values for red, green, blue and alpha. (optional, default `"#000000"`)
|
|
22
27
|
|
|
23
28
|
### Examples
|
|
24
29
|
|
|
@@ -34,47 +39,7 @@ const pipeline = sharp()
|
|
|
34
39
|
readableStream.pipe(pipeline);
|
|
35
40
|
```
|
|
36
41
|
|
|
37
|
-
- Throws **[Error][
|
|
38
|
-
|
|
39
|
-
Returns **Sharp**
|
|
40
|
-
|
|
41
|
-
## extract
|
|
42
|
-
|
|
43
|
-
Extract a region of the image.
|
|
44
|
-
|
|
45
|
-
- Use `extract` before `resize` for pre-resize extraction.
|
|
46
|
-
- Use `extract` after `resize` for post-resize extraction.
|
|
47
|
-
- Use `extract` before and after for both.
|
|
48
|
-
|
|
49
|
-
### Parameters
|
|
50
|
-
|
|
51
|
-
- `options` **[Object][3]**
|
|
52
|
-
- `options.left` **[Number][1]** zero-indexed offset from left edge
|
|
53
|
-
- `options.top` **[Number][1]** zero-indexed offset from top edge
|
|
54
|
-
- `options.width` **[Number][1]** dimension of extracted image
|
|
55
|
-
- `options.height` **[Number][1]** dimension of extracted image
|
|
56
|
-
|
|
57
|
-
### Examples
|
|
58
|
-
|
|
59
|
-
```javascript
|
|
60
|
-
sharp(input)
|
|
61
|
-
.extract({ left: left, top: top, width: width, height: height })
|
|
62
|
-
.toFile(output, function(err) {
|
|
63
|
-
// Extract a region of the input image, saving in the same format.
|
|
64
|
-
});
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
```javascript
|
|
68
|
-
sharp(input)
|
|
69
|
-
.extract({ left: leftOffsetPre, top: topOffsetPre, width: widthPre, height: heightPre })
|
|
70
|
-
.resize(width, height)
|
|
71
|
-
.extract({ left: leftOffsetPost, top: topOffsetPost, width: widthPost, height: heightPost })
|
|
72
|
-
.toFile(output, function(err) {
|
|
73
|
-
// Extract a region, resize, then extract from the resized image
|
|
74
|
-
});
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
- Throws **[Error][2]** Invalid parameters
|
|
42
|
+
- Throws **[Error][5]** Invalid parameters
|
|
78
43
|
|
|
79
44
|
Returns **Sharp**
|
|
80
45
|
|
|
@@ -85,7 +50,7 @@ The use of `flip` implies the removal of the EXIF `Orientation` tag, if any.
|
|
|
85
50
|
|
|
86
51
|
### Parameters
|
|
87
52
|
|
|
88
|
-
- `flip` **[Boolean][
|
|
53
|
+
- `flip` **[Boolean][6]** (optional, default `true`)
|
|
89
54
|
|
|
90
55
|
Returns **Sharp**
|
|
91
56
|
|
|
@@ -96,7 +61,7 @@ The use of `flop` implies the removal of the EXIF `Orientation` tag, if any.
|
|
|
96
61
|
|
|
97
62
|
### Parameters
|
|
98
63
|
|
|
99
|
-
- `flop` **[Boolean][
|
|
64
|
+
- `flop` **[Boolean][6]** (optional, default `true`)
|
|
100
65
|
|
|
101
66
|
Returns **Sharp**
|
|
102
67
|
|
|
@@ -114,7 +79,7 @@ Separate control over the level of sharpening in "flat" and "jagged" areas is av
|
|
|
114
79
|
- `jagged` **[Number][1]** the level of sharpening to apply to "jagged" areas. (optional, default `2.0`)
|
|
115
80
|
|
|
116
81
|
|
|
117
|
-
- Throws **[Error][
|
|
82
|
+
- Throws **[Error][5]** Invalid parameters
|
|
118
83
|
|
|
119
84
|
Returns **Sharp**
|
|
120
85
|
|
|
@@ -128,7 +93,7 @@ When used without parameters the default window is 3x3.
|
|
|
128
93
|
- `size` **[Number][1]** square mask size: size x size (optional, default `3`)
|
|
129
94
|
|
|
130
95
|
|
|
131
|
-
- Throws **[Error][
|
|
96
|
+
- Throws **[Error][5]** Invalid parameters
|
|
132
97
|
|
|
133
98
|
Returns **Sharp**
|
|
134
99
|
|
|
@@ -143,59 +108,18 @@ When a `sigma` is provided, performs a slower, more accurate Gaussian blur.
|
|
|
143
108
|
- `sigma` **[Number][1]?** a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
|
144
109
|
|
|
145
110
|
|
|
146
|
-
- Throws **[Error][
|
|
147
|
-
|
|
148
|
-
Returns **Sharp**
|
|
149
|
-
|
|
150
|
-
## extend
|
|
151
|
-
|
|
152
|
-
Extends/pads the edges of the image with the colour provided to the `background` method.
|
|
153
|
-
This operation will always occur after resizing and extraction, if any.
|
|
154
|
-
|
|
155
|
-
### Parameters
|
|
156
|
-
|
|
157
|
-
- `extend` **([Number][1] \| [Object][3])** single pixel count to add to all edges or an Object with per-edge counts
|
|
158
|
-
- `extend.top` **[Number][1]?**
|
|
159
|
-
- `extend.left` **[Number][1]?**
|
|
160
|
-
- `extend.bottom` **[Number][1]?**
|
|
161
|
-
- `extend.right` **[Number][1]?**
|
|
162
|
-
|
|
163
|
-
### Examples
|
|
164
|
-
|
|
165
|
-
```javascript
|
|
166
|
-
// Resize to 140 pixels wide, then add 10 transparent pixels
|
|
167
|
-
// to the top, left and right edges and 20 to the bottom edge
|
|
168
|
-
sharp(input)
|
|
169
|
-
.resize(140)
|
|
170
|
-
.background({r: 0, g: 0, b: 0, alpha: 0})
|
|
171
|
-
.extend({top: 10, bottom: 20, left: 10, right: 10})
|
|
172
|
-
...
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
- Throws **[Error][2]** Invalid parameters
|
|
111
|
+
- Throws **[Error][5]** Invalid parameters
|
|
176
112
|
|
|
177
113
|
Returns **Sharp**
|
|
178
114
|
|
|
179
115
|
## flatten
|
|
180
116
|
|
|
181
|
-
Merge alpha transparency channel, if any, with
|
|
182
|
-
|
|
183
|
-
### Parameters
|
|
184
|
-
|
|
185
|
-
- `flatten` **[Boolean][4]** (optional, default `true`)
|
|
186
|
-
|
|
187
|
-
Returns **Sharp**
|
|
188
|
-
|
|
189
|
-
## trim
|
|
190
|
-
|
|
191
|
-
Trim "boring" pixels from all edges that contain values within a percentage similarity of the top-left pixel.
|
|
117
|
+
Merge alpha transparency channel, if any, with a background.
|
|
192
118
|
|
|
193
119
|
### Parameters
|
|
194
120
|
|
|
195
|
-
- `
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
- Throws **[Error][2]** Invalid parameters
|
|
121
|
+
- `options` **[Object][2]?**
|
|
122
|
+
- `options.background` **([String][3] \| [Object][2])** background colour, parsed by the [color][4] module, defaults to black. (optional, default `{r:0,g:0,b:0}`)
|
|
199
123
|
|
|
200
124
|
Returns **Sharp**
|
|
201
125
|
|
|
@@ -207,12 +131,15 @@ This can improve the perceived brightness of a resized image in non-linear colou
|
|
|
207
131
|
JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation
|
|
208
132
|
when applying a gamma correction.
|
|
209
133
|
|
|
134
|
+
Supply a second argument to use a different output gamma value, otherwise the first value is used in both cases.
|
|
135
|
+
|
|
210
136
|
### Parameters
|
|
211
137
|
|
|
212
138
|
- `gamma` **[Number][1]** value between 1.0 and 3.0. (optional, default `2.2`)
|
|
139
|
+
- `gammaOut` **[Number][1]?** value between 1.0 and 3.0. (optional, defaults to same as `gamma`)
|
|
213
140
|
|
|
214
141
|
|
|
215
|
-
- Throws **[Error][
|
|
142
|
+
- Throws **[Error][5]** Invalid parameters
|
|
216
143
|
|
|
217
144
|
Returns **Sharp**
|
|
218
145
|
|
|
@@ -222,7 +149,7 @@ Produce the "negative" of the image.
|
|
|
222
149
|
|
|
223
150
|
### Parameters
|
|
224
151
|
|
|
225
|
-
- `negate` **[Boolean][
|
|
152
|
+
- `negate` **[Boolean][6]** (optional, default `true`)
|
|
226
153
|
|
|
227
154
|
Returns **Sharp**
|
|
228
155
|
|
|
@@ -232,7 +159,7 @@ Enhance output image contrast by stretching its luminance to cover the full dyna
|
|
|
232
159
|
|
|
233
160
|
### Parameters
|
|
234
161
|
|
|
235
|
-
- `normalise` **[Boolean][
|
|
162
|
+
- `normalise` **[Boolean][6]** (optional, default `true`)
|
|
236
163
|
|
|
237
164
|
Returns **Sharp**
|
|
238
165
|
|
|
@@ -242,7 +169,7 @@ Alternative spelling of normalise.
|
|
|
242
169
|
|
|
243
170
|
### Parameters
|
|
244
171
|
|
|
245
|
-
- `normalize` **[Boolean][
|
|
172
|
+
- `normalize` **[Boolean][6]** (optional, default `true`)
|
|
246
173
|
|
|
247
174
|
Returns **Sharp**
|
|
248
175
|
|
|
@@ -252,10 +179,10 @@ Convolve the image with the specified kernel.
|
|
|
252
179
|
|
|
253
180
|
### Parameters
|
|
254
181
|
|
|
255
|
-
- `kernel` **[Object][
|
|
182
|
+
- `kernel` **[Object][2]**
|
|
256
183
|
- `kernel.width` **[Number][1]** width of the kernel in pixels.
|
|
257
184
|
- `kernel.height` **[Number][1]** width of the kernel in pixels.
|
|
258
|
-
- `kernel.kernel` **[Array][
|
|
185
|
+
- `kernel.kernel` **[Array][7]<[Number][1]>** Array of length `width*height` containing the kernel values.
|
|
259
186
|
- `kernel.scale` **[Number][1]** the scale of the kernel in pixels. (optional, default `sum`)
|
|
260
187
|
- `kernel.offset` **[Number][1]** the offset of the kernel in pixels. (optional, default `0`)
|
|
261
188
|
|
|
@@ -275,7 +202,7 @@ sharp(input)
|
|
|
275
202
|
});
|
|
276
203
|
```
|
|
277
204
|
|
|
278
|
-
- Throws **[Error][
|
|
205
|
+
- Throws **[Error][5]** Invalid parameters
|
|
279
206
|
|
|
280
207
|
Returns **Sharp**
|
|
281
208
|
|
|
@@ -286,12 +213,12 @@ Any pixel value greather than or equal to the threshold value will be set to 255
|
|
|
286
213
|
### Parameters
|
|
287
214
|
|
|
288
215
|
- `threshold` **[Number][1]** a value in the range 0-255 representing the level at which the threshold will be applied. (optional, default `128`)
|
|
289
|
-
- `options` **[Object][
|
|
290
|
-
- `options.greyscale` **[Boolean][
|
|
291
|
-
- `options.grayscale` **[Boolean][
|
|
216
|
+
- `options` **[Object][2]?**
|
|
217
|
+
- `options.greyscale` **[Boolean][6]** convert to single channel greyscale. (optional, default `true`)
|
|
218
|
+
- `options.grayscale` **[Boolean][6]** alternative spelling for greyscale. (optional, default `true`)
|
|
292
219
|
|
|
293
220
|
|
|
294
|
-
- Throws **[Error][
|
|
221
|
+
- Throws **[Error][5]** Invalid parameters
|
|
295
222
|
|
|
296
223
|
Returns **Sharp**
|
|
297
224
|
|
|
@@ -304,16 +231,16 @@ the selected bitwise boolean `operation` between the corresponding pixels of the
|
|
|
304
231
|
|
|
305
232
|
### Parameters
|
|
306
233
|
|
|
307
|
-
- `operand` **([Buffer][
|
|
308
|
-
- `operator` **[String][
|
|
309
|
-
- `options` **[Object][
|
|
310
|
-
- `options.raw` **[Object][
|
|
234
|
+
- `operand` **([Buffer][8] \| [String][3])** Buffer containing image data or String containing the path to an image file.
|
|
235
|
+
- `operator` **[String][3]** one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
|
236
|
+
- `options` **[Object][2]?**
|
|
237
|
+
- `options.raw` **[Object][2]?** describes operand when using raw pixel data.
|
|
311
238
|
- `options.raw.width` **[Number][1]?**
|
|
312
239
|
- `options.raw.height` **[Number][1]?**
|
|
313
240
|
- `options.raw.channels` **[Number][1]?**
|
|
314
241
|
|
|
315
242
|
|
|
316
|
-
- Throws **[Error][
|
|
243
|
+
- Throws **[Error][5]** Invalid parameters
|
|
317
244
|
|
|
318
245
|
Returns **Sharp**
|
|
319
246
|
|
|
@@ -327,20 +254,51 @@ Apply the linear formula a \* input + b to the image (levels adjustment)
|
|
|
327
254
|
- `b` **[Number][1]** offset (optional, default `0.0`)
|
|
328
255
|
|
|
329
256
|
|
|
330
|
-
- Throws **[Error][
|
|
257
|
+
- Throws **[Error][5]** Invalid parameters
|
|
258
|
+
|
|
259
|
+
Returns **Sharp**
|
|
260
|
+
|
|
261
|
+
## recomb
|
|
262
|
+
|
|
263
|
+
Recomb the image with the specified matrix.
|
|
264
|
+
|
|
265
|
+
### Parameters
|
|
266
|
+
|
|
267
|
+
- `inputMatrix`
|
|
268
|
+
- `3x3` **[Array][7]<[Array][7]<[Number][1]>>** Recombination matrix
|
|
269
|
+
|
|
270
|
+
### Examples
|
|
271
|
+
|
|
272
|
+
```javascript
|
|
273
|
+
sharp(input)
|
|
274
|
+
.recomb([
|
|
275
|
+
[0.3588, 0.7044, 0.1368],
|
|
276
|
+
[0.2990, 0.5870, 0.1140],
|
|
277
|
+
[0.2392, 0.4696, 0.0912],
|
|
278
|
+
])
|
|
279
|
+
.raw()
|
|
280
|
+
.toBuffer(function(err, data, info) {
|
|
281
|
+
// data contains the raw pixel data after applying the recomb
|
|
282
|
+
// With this example input, a sepia filter has been applied
|
|
283
|
+
});
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
- Throws **[Error][5]** Invalid parameters
|
|
331
287
|
|
|
332
288
|
Returns **Sharp**
|
|
333
289
|
|
|
334
290
|
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
335
291
|
|
|
336
|
-
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/
|
|
292
|
+
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
293
|
+
|
|
294
|
+
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
337
295
|
|
|
338
|
-
[
|
|
296
|
+
[4]: https://www.npmjs.org/package/color
|
|
339
297
|
|
|
340
|
-
[
|
|
298
|
+
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
341
299
|
|
|
342
|
-
[
|
|
300
|
+
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
343
301
|
|
|
344
|
-
[
|
|
302
|
+
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
345
303
|
|
|
346
|
-
[
|
|
304
|
+
[8]: https://nodejs.org/api/buffer.html
|
package/docs/api-output.md
CHANGED
|
@@ -154,6 +154,11 @@ Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
|
|
154
154
|
- `options.progressive` **[Boolean][6]** use progressive (interlace) scan (optional, default `false`)
|
|
155
155
|
- `options.compressionLevel` **[Number][8]** zlib compression level, 0-9 (optional, default `9`)
|
|
156
156
|
- `options.adaptiveFiltering` **[Boolean][6]** use adaptive row filtering (optional, default `false`)
|
|
157
|
+
- `options.palette` **[Boolean][6]** quantise to a palette-based image with alpha transparency support, requires libimagequant (optional, default `false`)
|
|
158
|
+
- `options.quality` **[Number][8]** use the lowest number of colours needed to achieve given quality, requires libimagequant (optional, default `100`)
|
|
159
|
+
- `options.colours` **[Number][8]** maximum number of palette entries, requires libimagequant (optional, default `256`)
|
|
160
|
+
- `options.colors` **[Number][8]** alternative spelling of `options.colours`, requires libimagequant (optional, default `256`)
|
|
161
|
+
- `options.dither` **[Number][8]** level of Floyd-Steinberg error diffusion, requires libimagequant (optional, default `1.0`)
|
|
157
162
|
- `options.force` **[Boolean][6]** force PNG output, otherwise attempt to use input format (optional, default `true`)
|
|
158
163
|
|
|
159
164
|
### Examples
|
|
@@ -206,6 +211,10 @@ Use these TIFF options for output image.
|
|
|
206
211
|
- `options.force` **[Boolean][6]** force TIFF output, otherwise attempt to use input format (optional, default `true`)
|
|
207
212
|
- `options.compression` **[Boolean][6]** compression options: lzw, deflate, jpeg, ccittfax4 (optional, default `'jpeg'`)
|
|
208
213
|
- `options.predictor` **[Boolean][6]** compression predictor options: none, horizontal, float (optional, default `'horizontal'`)
|
|
214
|
+
- `options.pyramid` **[Boolean][6]** write an image pyramid (optional, default `false`)
|
|
215
|
+
- `options.tile` **[Boolean][6]** write a tiled tiff (optional, default `false`)
|
|
216
|
+
- `options.tileWidth` **[Boolean][6]** horizontal tile size (optional, default `256`)
|
|
217
|
+
- `options.tileHeight` **[Boolean][6]** vertical tile size (optional, default `256`)
|
|
209
218
|
- `options.xres` **[Number][8]** horizontal resolution in pixels/mm (optional, default `1.0`)
|
|
210
219
|
- `options.yres` **[Number][8]** vertical resolution in pixels/mm (optional, default `1.0`)
|
|
211
220
|
- `options.squash` **[Boolean][6]** squash 8-bit images down to 1 bit (optional, default `false`)
|