sharp 0.25.0 → 0.25.4
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 +7 -6
- package/binding.gyp +33 -6
- package/install/dll-copy.js +2 -1
- package/install/libvips.js +2 -1
- package/lib/channel.js +7 -10
- package/lib/colour.js +5 -5
- package/lib/composite.js +2 -5
- package/lib/constructor.js +74 -17
- package/lib/input.js +30 -5
- package/lib/is.js +6 -6
- package/lib/libvips.js +1 -1
- package/lib/operation.js +27 -27
- package/lib/output.js +91 -83
- package/lib/resize.js +15 -15
- package/lib/utility.js +8 -8
- package/package.json +17 -15
- package/src/common.cc +16 -0
- package/src/common.h +2 -0
- package/src/metadata.cc +21 -0
- package/src/metadata.h +1 -0
- package/src/pipeline.cc +8 -5
- package/src/sharp.cc +7 -1
- package/src/stats.cc +12 -1
- package/src/stats.h +3 -1
package/lib/operation.js
CHANGED
|
@@ -32,9 +32,9 @@ const is = require('./is');
|
|
|
32
32
|
* });
|
|
33
33
|
* readableStream.pipe(pipeline);
|
|
34
34
|
*
|
|
35
|
-
* @param {
|
|
35
|
+
* @param {number} [angle=auto] angle of rotation.
|
|
36
36
|
* @param {Object} [options] - if present, is an Object with optional attributes.
|
|
37
|
-
* @param {
|
|
37
|
+
* @param {string|Object} [options.background="#000000"] parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
|
38
38
|
* @returns {Sharp}
|
|
39
39
|
* @throws {Error} Invalid parameters
|
|
40
40
|
*/
|
|
@@ -88,9 +88,9 @@ function flop (flop) {
|
|
|
88
88
|
* When a `sigma` is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.
|
|
89
89
|
* Separate control over the level of sharpening in "flat" and "jagged" areas is available.
|
|
90
90
|
*
|
|
91
|
-
* @param {
|
|
92
|
-
* @param {
|
|
93
|
-
* @param {
|
|
91
|
+
* @param {number} [sigma] - the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
|
92
|
+
* @param {number} [flat=1.0] - the level of sharpening to apply to "flat" areas.
|
|
93
|
+
* @param {number} [jagged=2.0] - the level of sharpening to apply to "jagged" areas.
|
|
94
94
|
* @returns {Sharp}
|
|
95
95
|
* @throws {Error} Invalid parameters
|
|
96
96
|
*/
|
|
@@ -129,7 +129,7 @@ function sharpen (sigma, flat, jagged) {
|
|
|
129
129
|
/**
|
|
130
130
|
* Apply median filter.
|
|
131
131
|
* When used without parameters the default window is 3x3.
|
|
132
|
-
* @param {
|
|
132
|
+
* @param {number} [size=3] square mask size: size x size
|
|
133
133
|
* @returns {Sharp}
|
|
134
134
|
* @throws {Error} Invalid parameters
|
|
135
135
|
*/
|
|
@@ -150,7 +150,7 @@ function median (size) {
|
|
|
150
150
|
* Blur the image.
|
|
151
151
|
* When used without parameters, performs a fast, mild blur of the output image.
|
|
152
152
|
* When a `sigma` is provided, performs a slower, more accurate Gaussian blur.
|
|
153
|
-
* @param {
|
|
153
|
+
* @param {number} [sigma] a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where `sigma = 1 + radius / 2`.
|
|
154
154
|
* @returns {Sharp}
|
|
155
155
|
* @throws {Error} Invalid parameters
|
|
156
156
|
*/
|
|
@@ -173,7 +173,7 @@ function blur (sigma) {
|
|
|
173
173
|
/**
|
|
174
174
|
* Merge alpha transparency channel, if any, with a background.
|
|
175
175
|
* @param {Object} [options]
|
|
176
|
-
* @param {
|
|
176
|
+
* @param {string|Object} [options.background={r: 0, g: 0, b: 0}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black.
|
|
177
177
|
* @returns {Sharp}
|
|
178
178
|
*/
|
|
179
179
|
function flatten (options) {
|
|
@@ -193,8 +193,8 @@ function flatten (options) {
|
|
|
193
193
|
*
|
|
194
194
|
* Supply a second argument to use a different output gamma value, otherwise the first value is used in both cases.
|
|
195
195
|
*
|
|
196
|
-
* @param {
|
|
197
|
-
* @param {
|
|
196
|
+
* @param {number} [gamma=2.2] value between 1.0 and 3.0.
|
|
197
|
+
* @param {number} [gammaOut] value between 1.0 and 3.0. (optional, defaults to same as `gamma`)
|
|
198
198
|
* @returns {Sharp}
|
|
199
199
|
* @throws {Error} Invalid parameters
|
|
200
200
|
*/
|
|
@@ -264,11 +264,11 @@ function normalize (normalize) {
|
|
|
264
264
|
* });
|
|
265
265
|
*
|
|
266
266
|
* @param {Object} kernel
|
|
267
|
-
* @param {
|
|
268
|
-
* @param {
|
|
269
|
-
* @param {Array<
|
|
270
|
-
* @param {
|
|
271
|
-
* @param {
|
|
267
|
+
* @param {number} kernel.width - width of the kernel in pixels.
|
|
268
|
+
* @param {number} kernel.height - width of the kernel in pixels.
|
|
269
|
+
* @param {Array<number>} kernel.kernel - Array of length `width*height` containing the kernel values.
|
|
270
|
+
* @param {number} [kernel.scale=sum] - the scale of the kernel in pixels.
|
|
271
|
+
* @param {number} [kernel.offset=0] - the offset of the kernel in pixels.
|
|
272
272
|
* @returns {Sharp}
|
|
273
273
|
* @throws {Error} Invalid parameters
|
|
274
274
|
*/
|
|
@@ -300,7 +300,7 @@ function convolve (kernel) {
|
|
|
300
300
|
|
|
301
301
|
/**
|
|
302
302
|
* Any pixel value greather than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
|
|
303
|
-
* @param {
|
|
303
|
+
* @param {number} [threshold=128] - a value in the range 0-255 representing the level at which the threshold will be applied.
|
|
304
304
|
* @param {Object} [options]
|
|
305
305
|
* @param {Boolean} [options.greyscale=true] - convert to single channel greyscale.
|
|
306
306
|
* @param {Boolean} [options.grayscale=true] - alternative spelling for greyscale.
|
|
@@ -331,13 +331,13 @@ function threshold (threshold, options) {
|
|
|
331
331
|
* This operation creates an output image where each pixel is the result of
|
|
332
332
|
* the selected bitwise boolean `operation` between the corresponding pixels of the input images.
|
|
333
333
|
*
|
|
334
|
-
* @param {Buffer|
|
|
335
|
-
* @param {
|
|
334
|
+
* @param {Buffer|string} operand - Buffer containing image data or string containing the path to an image file.
|
|
335
|
+
* @param {string} operator - one of `and`, `or` or `eor` to perform that bitwise operation, like the C logic operators `&`, `|` and `^` respectively.
|
|
336
336
|
* @param {Object} [options]
|
|
337
337
|
* @param {Object} [options.raw] - describes operand when using raw pixel data.
|
|
338
|
-
* @param {
|
|
339
|
-
* @param {
|
|
340
|
-
* @param {
|
|
338
|
+
* @param {number} [options.raw.width]
|
|
339
|
+
* @param {number} [options.raw.height]
|
|
340
|
+
* @param {number} [options.raw.channels]
|
|
341
341
|
* @returns {Sharp}
|
|
342
342
|
* @throws {Error} Invalid parameters
|
|
343
343
|
*/
|
|
@@ -353,8 +353,8 @@ function boolean (operand, operator, options) {
|
|
|
353
353
|
|
|
354
354
|
/**
|
|
355
355
|
* Apply the linear formula a * input + b to the image (levels adjustment)
|
|
356
|
-
* @param {
|
|
357
|
-
* @param {
|
|
356
|
+
* @param {number} [a=1.0] multiplier
|
|
357
|
+
* @param {number} [b=0.0] offset
|
|
358
358
|
* @returns {Sharp}
|
|
359
359
|
* @throws {Error} Invalid parameters
|
|
360
360
|
*/
|
|
@@ -394,7 +394,7 @@ function linear (a, b) {
|
|
|
394
394
|
* // With this example input, a sepia filter has been applied
|
|
395
395
|
* });
|
|
396
396
|
*
|
|
397
|
-
* @param {Array<Array<
|
|
397
|
+
* @param {Array<Array<number>>} inputMatrix - 3x3 Recombination matrix
|
|
398
398
|
* @returns {Sharp}
|
|
399
399
|
* @throws {Error} Invalid parameters
|
|
400
400
|
*/
|
|
@@ -440,9 +440,9 @@ function recomb (inputMatrix) {
|
|
|
440
440
|
* });
|
|
441
441
|
*
|
|
442
442
|
* @param {Object} [options]
|
|
443
|
-
* @param {
|
|
444
|
-
* @param {
|
|
445
|
-
* @param {
|
|
443
|
+
* @param {number} [options.brightness] Brightness multiplier
|
|
444
|
+
* @param {number} [options.saturation] Saturation multiplier
|
|
445
|
+
* @param {number} [options.hue] Degrees for hue rotation
|
|
446
446
|
* @returns {Sharp}
|
|
447
447
|
*/
|
|
448
448
|
function modulate (options) {
|
package/lib/output.js
CHANGED
|
@@ -36,7 +36,7 @@ const formats = new Map([
|
|
|
36
36
|
* .then(info => { ... })
|
|
37
37
|
* .catch(err => { ... });
|
|
38
38
|
*
|
|
39
|
-
* @param {
|
|
39
|
+
* @param {string} fileOut - the path to write the image data to.
|
|
40
40
|
* @param {Function} [callback] - called on completion with two arguments `(err, info)`.
|
|
41
41
|
* `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
|
42
42
|
* `channels` and `premultiplied` (indicating if premultiplication was used).
|
|
@@ -103,7 +103,7 @@ function toFile (fileOut, callback) {
|
|
|
103
103
|
* .catch(err => { ... });
|
|
104
104
|
*
|
|
105
105
|
* @param {Object} [options]
|
|
106
|
-
* @param {
|
|
106
|
+
* @param {boolean} [options.resolveWithObject] Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
|
107
107
|
* @param {Function} [callback]
|
|
108
108
|
* @returns {Promise<Buffer>} - when no callback is provided
|
|
109
109
|
*/
|
|
@@ -118,9 +118,11 @@ function toBuffer (options, callback) {
|
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
120
|
* Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
|
|
121
|
-
* The default behaviour, when `withMetadata` is not used, is to strip all metadata and convert to the device-independent sRGB colour space.
|
|
122
121
|
* This will also convert to and add a web-friendly sRGB ICC profile.
|
|
123
122
|
*
|
|
123
|
+
* The default behaviour, when `withMetadata` is not used, is to convert to the device-independent
|
|
124
|
+
* sRGB colour space and strip all metadata, including the removal of any ICC profile.
|
|
125
|
+
*
|
|
124
126
|
* @example
|
|
125
127
|
* sharp('input.jpg')
|
|
126
128
|
* .withMetadata()
|
|
@@ -128,7 +130,7 @@ function toBuffer (options, callback) {
|
|
|
128
130
|
* .then(info => { ... });
|
|
129
131
|
*
|
|
130
132
|
* @param {Object} [options]
|
|
131
|
-
* @param {
|
|
133
|
+
* @param {number} [options.orientation] value between 1 and 8, used to update the EXIF `Orientation` tag.
|
|
132
134
|
* @returns {Sharp}
|
|
133
135
|
* @throws {Error} Invalid parameters
|
|
134
136
|
*/
|
|
@@ -155,7 +157,7 @@ function withMetadata (options) {
|
|
|
155
157
|
* .toFormat('png')
|
|
156
158
|
* .toBuffer();
|
|
157
159
|
*
|
|
158
|
-
* @param {(
|
|
160
|
+
* @param {(string|Object)} format - as a string or an Object with an 'id' attribute
|
|
159
161
|
* @param {Object} options - output options
|
|
160
162
|
* @returns {Sharp}
|
|
161
163
|
* @throws {Error} unsupported format or options
|
|
@@ -171,6 +173,8 @@ function toFormat (format, options) {
|
|
|
171
173
|
/**
|
|
172
174
|
* Use these JPEG options for output image.
|
|
173
175
|
*
|
|
176
|
+
* Some of these options require the use of a globally-installed libvips compiled with support for mozjpeg.
|
|
177
|
+
*
|
|
174
178
|
* @example
|
|
175
179
|
* // Convert any input to very high quality JPEG output
|
|
176
180
|
* const data = await sharp(input)
|
|
@@ -181,18 +185,18 @@ function toFormat (format, options) {
|
|
|
181
185
|
* .toBuffer();
|
|
182
186
|
*
|
|
183
187
|
* @param {Object} [options] - output options
|
|
184
|
-
* @param {
|
|
185
|
-
* @param {
|
|
186
|
-
* @param {
|
|
187
|
-
* @param {
|
|
188
|
-
* @param {
|
|
189
|
-
* @param {
|
|
190
|
-
* @param {
|
|
191
|
-
* @param {
|
|
192
|
-
* @param {
|
|
193
|
-
* @param {
|
|
194
|
-
* @param {
|
|
195
|
-
* @param {
|
|
188
|
+
* @param {number} [options.quality=80] - quality, integer 1-100
|
|
189
|
+
* @param {boolean} [options.progressive=false] - use progressive (interlace) scan
|
|
190
|
+
* @param {string} [options.chromaSubsampling='4:2:0'] - for quality < 90, set to '4:4:4' to prevent chroma subsampling otherwise defaults to '4:2:0' (use chroma subsampling); for quality >= 90 chroma is never subsampled
|
|
191
|
+
* @param {boolean} [options.optimiseCoding=true] - optimise Huffman coding tables
|
|
192
|
+
* @param {boolean} [options.optimizeCoding=true] - alternative spelling of optimiseCoding
|
|
193
|
+
* @param {boolean} [options.trellisQuantisation=false] - apply trellis quantisation, requires libvips compiled with support for mozjpeg
|
|
194
|
+
* @param {boolean} [options.overshootDeringing=false] - apply overshoot deringing, requires libvips compiled with support for mozjpeg
|
|
195
|
+
* @param {boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive, requires libvips compiled with support for mozjpeg
|
|
196
|
+
* @param {boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans, requires libvips compiled with support for mozjpeg
|
|
197
|
+
* @param {number} [options.quantisationTable=0] - quantization table to use, integer 0-8, requires libvips compiled with support for mozjpeg
|
|
198
|
+
* @param {number} [options.quantizationTable=0] - alternative spelling of quantisationTable, requires libvips compiled with support for mozjpeg
|
|
199
|
+
* @param {boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format
|
|
196
200
|
* @returns {Sharp}
|
|
197
201
|
* @throws {Error} Invalid options
|
|
198
202
|
*/
|
|
@@ -251,6 +255,8 @@ function jpeg (options) {
|
|
|
251
255
|
* PNG output is always full colour at 8 or 16 bits per pixel.
|
|
252
256
|
* Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
|
|
253
257
|
*
|
|
258
|
+
* Some of these options require the use of a globally-installed libvips compiled with support for libimagequant (GPL).
|
|
259
|
+
*
|
|
254
260
|
* @example
|
|
255
261
|
* // Convert any input to PNG output
|
|
256
262
|
* const data = await sharp(input)
|
|
@@ -258,15 +264,15 @@ function jpeg (options) {
|
|
|
258
264
|
* .toBuffer();
|
|
259
265
|
*
|
|
260
266
|
* @param {Object} [options]
|
|
261
|
-
* @param {
|
|
262
|
-
* @param {
|
|
263
|
-
* @param {
|
|
264
|
-
* @param {
|
|
265
|
-
* @param {
|
|
266
|
-
* @param {
|
|
267
|
-
* @param {
|
|
268
|
-
* @param {
|
|
269
|
-
* @param {
|
|
267
|
+
* @param {boolean} [options.progressive=false] - use progressive (interlace) scan
|
|
268
|
+
* @param {number} [options.compressionLevel=9] - zlib compression level, 0-9
|
|
269
|
+
* @param {boolean} [options.adaptiveFiltering=false] - use adaptive row filtering
|
|
270
|
+
* @param {boolean} [options.palette=false] - quantise to a palette-based image with alpha transparency support, requires libvips compiled with support for libimagequant
|
|
271
|
+
* @param {number} [options.quality=100] - use the lowest number of colours needed to achieve given quality, sets `palette` to `true`, requires libvips compiled with support for libimagequant
|
|
272
|
+
* @param {number} [options.colours=256] - maximum number of palette entries, sets `palette` to `true`, requires libvips compiled with support for libimagequant
|
|
273
|
+
* @param {number} [options.colors=256] - alternative spelling of `options.colours`, sets `palette` to `true`, requires libvips compiled with support for libimagequant
|
|
274
|
+
* @param {number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, sets `palette` to `true`, requires libvips compiled with support for libimagequant
|
|
275
|
+
* @param {boolean} [options.force=true] - force PNG output, otherwise attempt to use input format
|
|
270
276
|
* @returns {Sharp}
|
|
271
277
|
* @throws {Error} Invalid options
|
|
272
278
|
*/
|
|
@@ -287,28 +293,30 @@ function png (options) {
|
|
|
287
293
|
}
|
|
288
294
|
if (is.defined(options.palette)) {
|
|
289
295
|
this._setBooleanOption('pngPalette', options.palette);
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
296
|
+
} else if (is.defined(options.quality) || is.defined(options.colours || options.colors) || is.defined(options.dither)) {
|
|
297
|
+
this._setBooleanOption('pngPalette', true);
|
|
298
|
+
}
|
|
299
|
+
if (this.options.pngPalette) {
|
|
300
|
+
if (is.defined(options.quality)) {
|
|
301
|
+
if (is.integer(options.quality) && is.inRange(options.quality, 0, 100)) {
|
|
302
|
+
this.options.pngQuality = options.quality;
|
|
303
|
+
} else {
|
|
304
|
+
throw is.invalidParameterError('quality', 'integer between 0 and 100', options.quality);
|
|
297
305
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
306
|
+
}
|
|
307
|
+
const colours = options.colours || options.colors;
|
|
308
|
+
if (is.defined(colours)) {
|
|
309
|
+
if (is.integer(colours) && is.inRange(colours, 2, 256)) {
|
|
310
|
+
this.options.pngColours = colours;
|
|
311
|
+
} else {
|
|
312
|
+
throw is.invalidParameterError('colours', 'integer between 2 and 256', colours);
|
|
305
313
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
314
|
+
}
|
|
315
|
+
if (is.defined(options.dither)) {
|
|
316
|
+
if (is.number(options.dither) && is.inRange(options.dither, 0, 1)) {
|
|
317
|
+
this.options.pngDither = options.dither;
|
|
318
|
+
} else {
|
|
319
|
+
throw is.invalidParameterError('dither', 'number between 0.0 and 1.0', options.dither);
|
|
312
320
|
}
|
|
313
321
|
}
|
|
314
322
|
}
|
|
@@ -326,13 +334,13 @@ function png (options) {
|
|
|
326
334
|
* .toBuffer();
|
|
327
335
|
*
|
|
328
336
|
* @param {Object} [options] - output options
|
|
329
|
-
* @param {
|
|
330
|
-
* @param {
|
|
331
|
-
* @param {
|
|
332
|
-
* @param {
|
|
333
|
-
* @param {
|
|
334
|
-
* @param {
|
|
335
|
-
* @param {
|
|
337
|
+
* @param {number} [options.quality=80] - quality, integer 1-100
|
|
338
|
+
* @param {number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100
|
|
339
|
+
* @param {boolean} [options.lossless=false] - use lossless compression mode
|
|
340
|
+
* @param {boolean} [options.nearLossless=false] - use near_lossless compression mode
|
|
341
|
+
* @param {boolean} [options.smartSubsample=false] - use high quality chroma subsampling
|
|
342
|
+
* @param {number} [options.reductionEffort=4] - level of CPU effort to reduce file size, integer 0-6
|
|
343
|
+
* @param {boolean} [options.force=true] - force WebP output, otherwise attempt to use input format
|
|
336
344
|
* @returns {Sharp}
|
|
337
345
|
* @throws {Error} Invalid options
|
|
338
346
|
*/
|
|
@@ -384,17 +392,17 @@ function webp (options) {
|
|
|
384
392
|
* .then(info => { ... });
|
|
385
393
|
*
|
|
386
394
|
* @param {Object} [options] - output options
|
|
387
|
-
* @param {
|
|
388
|
-
* @param {
|
|
389
|
-
* @param {
|
|
390
|
-
* @param {
|
|
391
|
-
* @param {
|
|
392
|
-
* @param {
|
|
393
|
-
* @param {
|
|
394
|
-
* @param {
|
|
395
|
-
* @param {
|
|
396
|
-
* @param {
|
|
397
|
-
* @param {
|
|
395
|
+
* @param {number} [options.quality=80] - quality, integer 1-100
|
|
396
|
+
* @param {boolean} [options.force=true] - force TIFF output, otherwise attempt to use input format
|
|
397
|
+
* @param {boolean} [options.compression='jpeg'] - compression options: lzw, deflate, jpeg, ccittfax4
|
|
398
|
+
* @param {boolean} [options.predictor='horizontal'] - compression predictor options: none, horizontal, float
|
|
399
|
+
* @param {boolean} [options.pyramid=false] - write an image pyramid
|
|
400
|
+
* @param {boolean} [options.tile=false] - write a tiled tiff
|
|
401
|
+
* @param {boolean} [options.tileWidth=256] - horizontal tile size
|
|
402
|
+
* @param {boolean} [options.tileHeight=256] - vertical tile size
|
|
403
|
+
* @param {number} [options.xres=1.0] - horizontal resolution in pixels/mm
|
|
404
|
+
* @param {number} [options.yres=1.0] - vertical resolution in pixels/mm
|
|
405
|
+
* @param {boolean} [options.squash=false] - squash 8-bit images down to 1 bit
|
|
398
406
|
* @returns {Sharp}
|
|
399
407
|
* @throws {Error} Invalid options
|
|
400
408
|
*/
|
|
@@ -480,9 +488,9 @@ function tiff (options) {
|
|
|
480
488
|
* @since 0.23.0
|
|
481
489
|
*
|
|
482
490
|
* @param {Object} [options] - output options
|
|
483
|
-
* @param {
|
|
484
|
-
* @param {
|
|
485
|
-
* @param {
|
|
491
|
+
* @param {number} [options.quality=80] - quality, integer 1-100
|
|
492
|
+
* @param {boolean} [options.compression='hevc'] - compression format: hevc, avc, jpeg, av1
|
|
493
|
+
* @param {boolean} [options.lossless=false] - use lossless compression
|
|
486
494
|
* @returns {Sharp}
|
|
487
495
|
* @throws {Error} Invalid options
|
|
488
496
|
*/
|
|
@@ -532,7 +540,7 @@ function heif (options) {
|
|
|
532
540
|
* const data = await sharp('input.png')
|
|
533
541
|
* .ensureAlpha()
|
|
534
542
|
* .extractChannel(3)
|
|
535
|
-
* .
|
|
543
|
+
* .toColourspace('b-w')
|
|
536
544
|
* .raw()
|
|
537
545
|
* .toBuffer();
|
|
538
546
|
*
|
|
@@ -561,14 +569,14 @@ function raw () {
|
|
|
561
569
|
* });
|
|
562
570
|
*
|
|
563
571
|
* @param {Object} [options]
|
|
564
|
-
* @param {
|
|
565
|
-
* @param {
|
|
566
|
-
* @param {
|
|
567
|
-
* @param {
|
|
568
|
-
* @param {
|
|
569
|
-
* @param {
|
|
570
|
-
* @param {
|
|
571
|
-
* @param {
|
|
572
|
+
* @param {number} [options.size=256] tile size in pixels, a value between 1 and 8192.
|
|
573
|
+
* @param {number} [options.overlap=0] tile overlap in pixels, a value between 0 and 8192.
|
|
574
|
+
* @param {number} [options.angle=0] tile angle of rotation, must be a multiple of 90.
|
|
575
|
+
* @param {string|Object} [options.background={r: 255, g: 255, b: 255, alpha: 1}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to white without transparency.
|
|
576
|
+
* @param {string} [options.depth] how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
|
577
|
+
* @param {number} [options.skipBlanks=-1] threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images
|
|
578
|
+
* @param {string} [options.container='fs'] tile container, with value `fs` (filesystem) or `zip` (compressed file).
|
|
579
|
+
* @param {string} [options.layout='dz'] filesystem layout, possible values are `dz`, `iiif`, `zoomify` or `google`.
|
|
572
580
|
* @returns {Sharp}
|
|
573
581
|
* @throws {Error} Invalid parameters
|
|
574
582
|
*/
|
|
@@ -603,10 +611,10 @@ function tile (options) {
|
|
|
603
611
|
}
|
|
604
612
|
// Layout
|
|
605
613
|
if (is.defined(options.layout)) {
|
|
606
|
-
if (is.string(options.layout) && is.inArray(options.layout, ['dz', 'google', 'zoomify'])) {
|
|
614
|
+
if (is.string(options.layout) && is.inArray(options.layout, ['dz', 'google', 'iiif', 'zoomify'])) {
|
|
607
615
|
this.options.tileLayout = options.layout;
|
|
608
616
|
} else {
|
|
609
|
-
throw is.invalidParameterError('layout', 'one of: dz, google, zoomify', options.layout);
|
|
617
|
+
throw is.invalidParameterError('layout', 'one of: dz, google, iiif, zoomify', options.layout);
|
|
610
618
|
}
|
|
611
619
|
}
|
|
612
620
|
// Angle of rotation,
|
|
@@ -651,9 +659,9 @@ function tile (options) {
|
|
|
651
659
|
* Update the output format unless options.force is false,
|
|
652
660
|
* in which case revert to input format.
|
|
653
661
|
* @private
|
|
654
|
-
* @param {
|
|
662
|
+
* @param {string} formatOut
|
|
655
663
|
* @param {Object} [options]
|
|
656
|
-
* @param {
|
|
664
|
+
* @param {boolean} [options.force=true] - force output format, otherwise attempt to use input format
|
|
657
665
|
* @returns {Sharp}
|
|
658
666
|
*/
|
|
659
667
|
function _updateFormatOut (formatOut, options) {
|
|
@@ -664,10 +672,10 @@ function _updateFormatOut (formatOut, options) {
|
|
|
664
672
|
}
|
|
665
673
|
|
|
666
674
|
/**
|
|
667
|
-
* Update a
|
|
675
|
+
* Update a boolean attribute of the this.options Object.
|
|
668
676
|
* @private
|
|
669
|
-
* @param {
|
|
670
|
-
* @param {
|
|
677
|
+
* @param {string} key
|
|
678
|
+
* @param {boolean} val
|
|
671
679
|
* @throws {Error} Invalid key
|
|
672
680
|
*/
|
|
673
681
|
function _setBooleanOption (key, val) {
|
package/lib/resize.js
CHANGED
|
@@ -96,8 +96,8 @@ function isRotationExpected (options) {
|
|
|
96
96
|
* Resize image to `width`, `height` or `width x height`.
|
|
97
97
|
*
|
|
98
98
|
* When both a `width` and `height` are provided, the possible methods by which the image should **fit** these are:
|
|
99
|
-
* - `cover`:
|
|
100
|
-
* - `contain`:
|
|
99
|
+
* - `cover`: (default) Preserving aspect ratio, ensure the image covers both provided dimensions by cropping/clipping to fit.
|
|
100
|
+
* - `contain`: Preserving aspect ratio, contain within both provided dimensions using "letterboxing" where necessary.
|
|
101
101
|
* - `fill`: Ignore the aspect ratio of the input and stretch to both provided dimensions.
|
|
102
102
|
* - `inside`: Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to both those specified.
|
|
103
103
|
* - `outside`: Preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to both those specified.
|
|
@@ -190,8 +190,8 @@ function isRotationExpected (options) {
|
|
|
190
190
|
* .toBuffer()
|
|
191
191
|
* );
|
|
192
192
|
*
|
|
193
|
-
* @param {
|
|
194
|
-
* @param {
|
|
193
|
+
* @param {number} [width] - pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.
|
|
194
|
+
* @param {number} [height] - pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
|
|
195
195
|
* @param {Object} [options]
|
|
196
196
|
* @param {String} [options.width] - alternative means of specifying `width`. If both are present this take priority.
|
|
197
197
|
* @param {String} [options.height] - alternative means of specifying `height`. If both are present this take priority.
|
|
@@ -302,11 +302,11 @@ function resize (width, height, options) {
|
|
|
302
302
|
* })
|
|
303
303
|
* ...
|
|
304
304
|
*
|
|
305
|
-
* @param {(
|
|
306
|
-
* @param {
|
|
307
|
-
* @param {
|
|
308
|
-
* @param {
|
|
309
|
-
* @param {
|
|
305
|
+
* @param {(number|Object)} extend - single pixel count to add to all edges or an Object with per-edge counts
|
|
306
|
+
* @param {number} [extend.top]
|
|
307
|
+
* @param {number} [extend.left]
|
|
308
|
+
* @param {number} [extend.bottom]
|
|
309
|
+
* @param {number} [extend.right]
|
|
310
310
|
* @param {String|Object} [extend.background={r: 0, g: 0, b: 0, alpha: 1}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency.
|
|
311
311
|
* @returns {Sharp}
|
|
312
312
|
* @throws {Error} Invalid parameters
|
|
@@ -336,7 +336,7 @@ function extend (extend) {
|
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
/**
|
|
339
|
-
* Extract a region of the image.
|
|
339
|
+
* Extract/crop a region of the image.
|
|
340
340
|
*
|
|
341
341
|
* - Use `extract` before `resize` for pre-resize extraction.
|
|
342
342
|
* - Use `extract` after `resize` for post-resize extraction.
|
|
@@ -358,10 +358,10 @@ function extend (extend) {
|
|
|
358
358
|
* });
|
|
359
359
|
*
|
|
360
360
|
* @param {Object} options - describes the region to extract using integral pixel values
|
|
361
|
-
* @param {
|
|
362
|
-
* @param {
|
|
363
|
-
* @param {
|
|
364
|
-
* @param {
|
|
361
|
+
* @param {number} options.left - zero-indexed offset from left edge
|
|
362
|
+
* @param {number} options.top - zero-indexed offset from top edge
|
|
363
|
+
* @param {number} options.width - width of region to extract
|
|
364
|
+
* @param {number} options.height - height of region to extract
|
|
365
365
|
* @returns {Sharp}
|
|
366
366
|
* @throws {Error} Invalid parameters
|
|
367
367
|
*/
|
|
@@ -388,7 +388,7 @@ function extract (options) {
|
|
|
388
388
|
*
|
|
389
389
|
* The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
|
390
390
|
*
|
|
391
|
-
* @param {
|
|
391
|
+
* @param {number} [threshold=10] the allowed difference from the top-left pixel, a number greater than zero.
|
|
392
392
|
* @returns {Sharp}
|
|
393
393
|
* @throws {Error} Invalid parameters
|
|
394
394
|
*/
|
package/lib/utility.js
CHANGED
|
@@ -39,10 +39,10 @@ try {
|
|
|
39
39
|
* sharp.cache( { files: 0 } );
|
|
40
40
|
* sharp.cache(false);
|
|
41
41
|
*
|
|
42
|
-
* @param {Object|
|
|
43
|
-
* @param {
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {
|
|
42
|
+
* @param {Object|boolean} [options=true] - Object with the following attributes, or boolean where true uses default cache settings and false removes all caching
|
|
43
|
+
* @param {number} [options.memory=50] - is the maximum memory in MB to use for this cache
|
|
44
|
+
* @param {number} [options.files=20] - is the maximum number of files to hold open
|
|
45
|
+
* @param {number} [options.items=100] - is the maximum number of operations to cache
|
|
46
46
|
* @returns {Object}
|
|
47
47
|
*/
|
|
48
48
|
function cache (options) {
|
|
@@ -77,8 +77,8 @@ cache(true);
|
|
|
77
77
|
* sharp.concurrency(2); // 2
|
|
78
78
|
* sharp.concurrency(0); // 4
|
|
79
79
|
*
|
|
80
|
-
* @param {
|
|
81
|
-
* @returns {
|
|
80
|
+
* @param {number} [concurrency]
|
|
81
|
+
* @returns {number} concurrency
|
|
82
82
|
*/
|
|
83
83
|
function concurrency (concurrency) {
|
|
84
84
|
return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
|
|
@@ -124,8 +124,8 @@ function counters () {
|
|
|
124
124
|
* const simd = sharp.simd(false);
|
|
125
125
|
* // prevent libvips from using liborc at runtime
|
|
126
126
|
*
|
|
127
|
-
* @param {
|
|
128
|
-
* @returns {
|
|
127
|
+
* @param {boolean} [simd=true]
|
|
128
|
+
* @returns {boolean}
|
|
129
129
|
*/
|
|
130
130
|
function simd (simd) {
|
|
131
131
|
return sharp.simd(is.bool(simd) ? simd : null);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sharp",
|
|
3
3
|
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP and TIFF images",
|
|
4
|
-
"version": "0.25.
|
|
4
|
+
"version": "0.25.4",
|
|
5
5
|
"author": "Lovell Fuller <npm@lovell.info>",
|
|
6
6
|
"homepage": "https://github.com/lovell/sharp",
|
|
7
7
|
"contributors": [
|
|
@@ -65,17 +65,19 @@
|
|
|
65
65
|
"Andargor <andargor@yahoo.com>",
|
|
66
66
|
"Paul Neave <paul.neave@gmail.com>",
|
|
67
67
|
"Brendan Kennedy <brenwken@gmail.com>",
|
|
68
|
-
"Brychan Bennett-Odlum <git@brychan.io>"
|
|
68
|
+
"Brychan Bennett-Odlum <git@brychan.io>",
|
|
69
|
+
"Edward Silverton <e.silverton@gmail.com>",
|
|
70
|
+
"Roman Malieiev <aromaleev@gmail.com>"
|
|
69
71
|
],
|
|
70
72
|
"scripts": {
|
|
71
|
-
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)",
|
|
73
|
+
"install": "(node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)",
|
|
72
74
|
"clean": "rm -rf node_modules/ build/ vendor/ .nyc_output/ coverage/ test/fixtures/output.*",
|
|
73
75
|
"test": "semistandard && cpplint && npm run test-unit && npm run test-licensing && prebuild-ci",
|
|
74
76
|
"test-unit": "nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
|
|
75
77
|
"test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;MIT\"",
|
|
76
78
|
"test-coverage": "./test/coverage/report.sh",
|
|
77
79
|
"test-leak": "./test/leak/leak.sh",
|
|
78
|
-
"docs-build": "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",
|
|
80
|
+
"docs-build": "documentation lint lib && 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 && node docs/search-index/build",
|
|
79
81
|
"docs-serve": "cd docs && npx serve",
|
|
80
82
|
"docs-publish": "cd docs && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
|
|
81
83
|
},
|
|
@@ -109,25 +111,25 @@
|
|
|
109
111
|
"dependencies": {
|
|
110
112
|
"color": "^3.1.2",
|
|
111
113
|
"detect-libc": "^1.0.3",
|
|
112
|
-
"node-addon-api": "^
|
|
114
|
+
"node-addon-api": "^3.0.0",
|
|
113
115
|
"npmlog": "^4.1.2",
|
|
114
|
-
"prebuild-install": "^5.3.
|
|
115
|
-
"semver": "^7.
|
|
116
|
-
"simple-get": "^
|
|
117
|
-
"tar": "^6.0.
|
|
116
|
+
"prebuild-install": "^5.3.4",
|
|
117
|
+
"semver": "^7.3.2",
|
|
118
|
+
"simple-get": "^4.0.0",
|
|
119
|
+
"tar": "^6.0.2",
|
|
118
120
|
"tunnel-agent": "^0.6.0"
|
|
119
121
|
},
|
|
120
122
|
"devDependencies": {
|
|
121
123
|
"async": "^3.2.0",
|
|
122
124
|
"cc": "^2.0.1",
|
|
123
125
|
"decompress-zip": "^0.3.2",
|
|
124
|
-
"documentation": "^
|
|
126
|
+
"documentation": "^13.0.1",
|
|
125
127
|
"exif-reader": "^1.0.3",
|
|
126
128
|
"icc": "^1.0.0",
|
|
127
129
|
"license-checker": "^25.0.1",
|
|
128
|
-
"mocha": "^
|
|
129
|
-
"mock-fs": "^4.
|
|
130
|
-
"nyc": "^15.
|
|
130
|
+
"mocha": "^8.0.1",
|
|
131
|
+
"mock-fs": "^4.12.0",
|
|
132
|
+
"nyc": "^15.1.0",
|
|
131
133
|
"prebuild": "^10.0.0",
|
|
132
134
|
"prebuild-ci": "^3.1.0",
|
|
133
135
|
"rimraf": "^3.0.2",
|
|
@@ -138,14 +140,14 @@
|
|
|
138
140
|
"libvips": "8.9.1"
|
|
139
141
|
},
|
|
140
142
|
"engines": {
|
|
141
|
-
"node": ">=10
|
|
143
|
+
"node": ">=10"
|
|
142
144
|
},
|
|
143
145
|
"funding": {
|
|
144
146
|
"url": "https://opencollective.com/libvips"
|
|
145
147
|
},
|
|
146
148
|
"binary": {
|
|
147
149
|
"napi_versions": [
|
|
148
|
-
|
|
150
|
+
3
|
|
149
151
|
]
|
|
150
152
|
},
|
|
151
153
|
"semistandard": {
|