sharp 0.25.1 → 0.26.0

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/lib/output.js CHANGED
@@ -11,7 +11,8 @@ const formats = new Map([
11
11
  ['png', 'png'],
12
12
  ['raw', 'raw'],
13
13
  ['tiff', 'tiff'],
14
- ['webp', 'webp']
14
+ ['webp', 'webp'],
15
+ ['gif', 'gif']
15
16
  ]);
16
17
 
17
18
  /**
@@ -36,7 +37,7 @@ const formats = new Map([
36
37
  * .then(info => { ... })
37
38
  * .catch(err => { ... });
38
39
  *
39
- * @param {String} fileOut - the path to write the image data to.
40
+ * @param {string} fileOut - the path to write the image data to.
40
41
  * @param {Function} [callback] - called on completion with two arguments `(err, info)`.
41
42
  * `info` contains the output image `format`, `size` (bytes), `width`, `height`,
42
43
  * `channels` and `premultiplied` (indicating if premultiplication was used).
@@ -103,7 +104,7 @@ function toFile (fileOut, callback) {
103
104
  * .catch(err => { ... });
104
105
  *
105
106
  * @param {Object} [options]
106
- * @param {Boolean} [options.resolveWithObject] Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
107
+ * @param {boolean} [options.resolveWithObject] Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
107
108
  * @param {Function} [callback]
108
109
  * @returns {Promise<Buffer>} - when no callback is provided
109
110
  */
@@ -118,8 +119,11 @@ function toBuffer (options, callback) {
118
119
 
119
120
  /**
120
121
  * 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
- * This will also convert to and add a web-friendly sRGB ICC profile.
122
+ * This will also convert to and add a web-friendly sRGB ICC profile unless a custom
123
+ * output profile is provided.
124
+ *
125
+ * The default behaviour, when `withMetadata` is not used, is to convert to the device-independent
126
+ * sRGB colour space and strip all metadata, including the removal of any ICC profile.
123
127
  *
124
128
  * @example
125
129
  * sharp('input.jpg')
@@ -128,7 +132,8 @@ function toBuffer (options, callback) {
128
132
  * .then(info => { ... });
129
133
  *
130
134
  * @param {Object} [options]
131
- * @param {Number} [options.orientation] value between 1 and 8, used to update the EXIF `Orientation` tag.
135
+ * @param {number} [options.orientation] value between 1 and 8, used to update the EXIF `Orientation` tag.
136
+ * @param {string} [options.icc] filesystem path to output ICC profile, defaults to sRGB.
132
137
  * @returns {Sharp}
133
138
  * @throws {Error} Invalid parameters
134
139
  */
@@ -142,6 +147,13 @@ function withMetadata (options) {
142
147
  throw is.invalidParameterError('orientation', 'integer between 1 and 8', options.orientation);
143
148
  }
144
149
  }
150
+ if (is.defined(options.icc)) {
151
+ if (is.string(options.icc)) {
152
+ this.options.withMetadataIcc = options.icc;
153
+ } else {
154
+ throw is.invalidParameterError('icc', 'string filesystem path to ICC profile', options.icc);
155
+ }
156
+ }
145
157
  }
146
158
  return this;
147
159
  }
@@ -155,7 +167,7 @@ function withMetadata (options) {
155
167
  * .toFormat('png')
156
168
  * .toBuffer();
157
169
  *
158
- * @param {(String|Object)} format - as a String or an Object with an 'id' attribute
170
+ * @param {(string|Object)} format - as a string or an Object with an 'id' attribute
159
171
  * @param {Object} options - output options
160
172
  * @returns {Sharp}
161
173
  * @throws {Error} unsupported format or options
@@ -171,6 +183,8 @@ function toFormat (format, options) {
171
183
  /**
172
184
  * Use these JPEG options for output image.
173
185
  *
186
+ * Some of these options require the use of a globally-installed libvips compiled with support for mozjpeg.
187
+ *
174
188
  * @example
175
189
  * // Convert any input to very high quality JPEG output
176
190
  * const data = await sharp(input)
@@ -181,18 +195,18 @@ function toFormat (format, options) {
181
195
  * .toBuffer();
182
196
  *
183
197
  * @param {Object} [options] - output options
184
- * @param {Number} [options.quality=80] - quality, integer 1-100
185
- * @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
186
- * @param {String} [options.chromaSubsampling='4:2:0'] - set to '4:4:4' to prevent chroma subsampling when quality <= 90
187
- * @param {Boolean} [options.trellisQuantisation=false] - apply trellis quantisation, requires libvips compiled with support for mozjpeg
188
- * @param {Boolean} [options.overshootDeringing=false] - apply overshoot deringing, requires libvips compiled with support for mozjpeg
189
- * @param {Boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive, requires libvips compiled with support for mozjpeg
190
- * @param {Boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans
191
- * @param {Boolean} [options.optimiseCoding=true] - optimise Huffman coding tables
192
- * @param {Boolean} [options.optimizeCoding=true] - alternative spelling of optimiseCoding
193
- * @param {Number} [options.quantisationTable=0] - quantization table to use, integer 0-8, requires libvips compiled with support for mozjpeg
194
- * @param {Number} [options.quantizationTable=0] - alternative spelling of quantisationTable
195
- * @param {Boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format
198
+ * @param {number} [options.quality=80] - quality, integer 1-100
199
+ * @param {boolean} [options.progressive=false] - use progressive (interlace) scan
200
+ * @param {string} [options.chromaSubsampling='4:2:0'] - set to '4:4:4' to prevent chroma subsampling otherwise defaults to '4:2:0' chroma subsampling
201
+ * @param {boolean} [options.optimiseCoding=true] - optimise Huffman coding tables
202
+ * @param {boolean} [options.optimizeCoding=true] - alternative spelling of optimiseCoding
203
+ * @param {boolean} [options.trellisQuantisation=false] - apply trellis quantisation, requires libvips compiled with support for mozjpeg
204
+ * @param {boolean} [options.overshootDeringing=false] - apply overshoot deringing, requires libvips compiled with support for mozjpeg
205
+ * @param {boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive, requires libvips compiled with support for mozjpeg
206
+ * @param {boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans, requires libvips compiled with support for mozjpeg
207
+ * @param {number} [options.quantisationTable=0] - quantization table to use, integer 0-8, requires libvips compiled with support for mozjpeg
208
+ * @param {number} [options.quantizationTable=0] - alternative spelling of quantisationTable, requires libvips compiled with support for mozjpeg
209
+ * @param {boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format
196
210
  * @returns {Sharp}
197
211
  * @throws {Error} Invalid options
198
212
  */
@@ -251,6 +265,8 @@ function jpeg (options) {
251
265
  * PNG output is always full colour at 8 or 16 bits per pixel.
252
266
  * Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
253
267
  *
268
+ * Some of these options require the use of a globally-installed libvips compiled with support for libimagequant (GPL).
269
+ *
254
270
  * @example
255
271
  * // Convert any input to PNG output
256
272
  * const data = await sharp(input)
@@ -258,15 +274,15 @@ function jpeg (options) {
258
274
  * .toBuffer();
259
275
  *
260
276
  * @param {Object} [options]
261
- * @param {Boolean} [options.progressive=false] - use progressive (interlace) scan
262
- * @param {Number} [options.compressionLevel=9] - zlib compression level, 0-9
263
- * @param {Boolean} [options.adaptiveFiltering=false] - use adaptive row filtering
264
- * @param {Boolean} [options.palette=false] - quantise to a palette-based image with alpha transparency support, requires libvips compiled with support for libimagequant
265
- * @param {Number} [options.quality=100] - use the lowest number of colours needed to achieve given quality, requires libvips compiled with support for libimagequant
266
- * @param {Number} [options.colours=256] - maximum number of palette entries, requires libvips compiled with support for libimagequant
267
- * @param {Number} [options.colors=256] - alternative spelling of `options.colours`, requires libvips compiled with support for libimagequant
268
- * @param {Number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, requires libvips compiled with support for libimagequant
269
- * @param {Boolean} [options.force=true] - force PNG output, otherwise attempt to use input format
277
+ * @param {boolean} [options.progressive=false] - use progressive (interlace) scan
278
+ * @param {number} [options.compressionLevel=9] - zlib compression level, 0-9
279
+ * @param {boolean} [options.adaptiveFiltering=false] - use adaptive row filtering
280
+ * @param {boolean} [options.palette=false] - quantise to a palette-based image with alpha transparency support, requires libvips compiled with support for libimagequant
281
+ * @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
282
+ * @param {number} [options.colours=256] - maximum number of palette entries, sets `palette` to `true`, requires libvips compiled with support for libimagequant
283
+ * @param {number} [options.colors=256] - alternative spelling of `options.colours`, sets `palette` to `true`, requires libvips compiled with support for libimagequant
284
+ * @param {number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, sets `palette` to `true`, requires libvips compiled with support for libimagequant
285
+ * @param {boolean} [options.force=true] - force PNG output, otherwise attempt to use input format
270
286
  * @returns {Sharp}
271
287
  * @throws {Error} Invalid options
272
288
  */
@@ -287,28 +303,30 @@ function png (options) {
287
303
  }
288
304
  if (is.defined(options.palette)) {
289
305
  this._setBooleanOption('pngPalette', options.palette);
290
- if (this.options.pngPalette) {
291
- if (is.defined(options.quality)) {
292
- if (is.integer(options.quality) && is.inRange(options.quality, 0, 100)) {
293
- this.options.pngQuality = options.quality;
294
- } else {
295
- throw is.invalidParameterError('quality', 'integer between 0 and 100', options.quality);
296
- }
306
+ } else if (is.defined(options.quality) || is.defined(options.colours || options.colors) || is.defined(options.dither)) {
307
+ this._setBooleanOption('pngPalette', true);
308
+ }
309
+ if (this.options.pngPalette) {
310
+ if (is.defined(options.quality)) {
311
+ if (is.integer(options.quality) && is.inRange(options.quality, 0, 100)) {
312
+ this.options.pngQuality = options.quality;
313
+ } else {
314
+ throw is.invalidParameterError('quality', 'integer between 0 and 100', options.quality);
297
315
  }
298
- const colours = options.colours || options.colors;
299
- if (is.defined(colours)) {
300
- if (is.integer(colours) && is.inRange(colours, 2, 256)) {
301
- this.options.pngColours = colours;
302
- } else {
303
- throw is.invalidParameterError('colours', 'integer between 2 and 256', colours);
304
- }
316
+ }
317
+ const colours = options.colours || options.colors;
318
+ if (is.defined(colours)) {
319
+ if (is.integer(colours) && is.inRange(colours, 2, 256)) {
320
+ this.options.pngColours = colours;
321
+ } else {
322
+ throw is.invalidParameterError('colours', 'integer between 2 and 256', colours);
305
323
  }
306
- if (is.defined(options.dither)) {
307
- if (is.number(options.dither) && is.inRange(options.dither, 0, 1)) {
308
- this.options.pngDither = options.dither;
309
- } else {
310
- throw is.invalidParameterError('dither', 'number between 0.0 and 1.0', options.dither);
311
- }
324
+ }
325
+ if (is.defined(options.dither)) {
326
+ if (is.number(options.dither) && is.inRange(options.dither, 0, 1)) {
327
+ this.options.pngDither = options.dither;
328
+ } else {
329
+ throw is.invalidParameterError('dither', 'number between 0.0 and 1.0', options.dither);
312
330
  }
313
331
  }
314
332
  }
@@ -326,13 +344,16 @@ function png (options) {
326
344
  * .toBuffer();
327
345
  *
328
346
  * @param {Object} [options] - output options
329
- * @param {Number} [options.quality=80] - quality, integer 1-100
330
- * @param {Number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100
331
- * @param {Boolean} [options.lossless=false] - use lossless compression mode
332
- * @param {Boolean} [options.nearLossless=false] - use near_lossless compression mode
333
- * @param {Boolean} [options.smartSubsample=false] - use high quality chroma subsampling
334
- * @param {Number} [options.reductionEffort=4] - level of CPU effort to reduce file size, integer 0-6
335
- * @param {Boolean} [options.force=true] - force WebP output, otherwise attempt to use input format
347
+ * @param {number} [options.quality=80] - quality, integer 1-100
348
+ * @param {number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100
349
+ * @param {boolean} [options.lossless=false] - use lossless compression mode
350
+ * @param {boolean} [options.nearLossless=false] - use near_lossless compression mode
351
+ * @param {boolean} [options.smartSubsample=false] - use high quality chroma subsampling
352
+ * @param {number} [options.reductionEffort=4] - level of CPU effort to reduce file size, integer 0-6
353
+ * @param {number} [options.pageHeight] - page height for animated output
354
+ * @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
355
+ * @param {number[]} [options.delay] - list of delays between animation frames (in milliseconds)
356
+ * @param {boolean} [options.force=true] - force WebP output, otherwise attempt to use input format
336
357
  * @returns {Sharp}
337
358
  * @throws {Error} Invalid options
338
359
  */
@@ -367,9 +388,73 @@ function webp (options) {
367
388
  throw is.invalidParameterError('reductionEffort', 'integer between 0 and 6', options.reductionEffort);
368
389
  }
369
390
  }
391
+
392
+ trySetAnimationOptions(options, this.options);
370
393
  return this._updateFormatOut('webp', options);
371
394
  }
372
395
 
396
+ /**
397
+ * Use these GIF options for output image.
398
+ *
399
+ * Requires libvips compiled with support for ImageMagick or GraphicsMagick.
400
+ * The prebuilt binaries do not include this - see
401
+ * {@link https://sharp.pixelplumbing.com/install#custom-libvips installing a custom libvips}.
402
+ *
403
+ * @param {Object} [options] - output options
404
+ * @param {number} [options.pageHeight] - page height for animated output
405
+ * @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
406
+ * @param {number[]} [options.delay] - list of delays between animation frames (in milliseconds)
407
+ * @param {boolean} [options.force=true] - force GIF output, otherwise attempt to use input format
408
+ * @returns {Sharp}
409
+ * @throws {Error} Invalid options
410
+ */
411
+ /* istanbul ignore next */
412
+ function gif (options) {
413
+ if (!this.constructor.format.magick.output.buffer) {
414
+ throw new Error('The gif operation requires libvips to have been installed with support for ImageMagick');
415
+ }
416
+ trySetAnimationOptions(options, this.options);
417
+ return this._updateFormatOut('gif', options);
418
+ }
419
+
420
+ /**
421
+ * Set animation options if available.
422
+ * @private
423
+ *
424
+ * @param {Object} [source] - output options
425
+ * @param {number} [source.pageHeight] - page height for animated output
426
+ * @param {number} [source.loop=0] - number of animation iterations, use 0 for infinite animation
427
+ * @param {number[]} [source.delay] - list of delays between animation frames (in milliseconds)
428
+ * @param {Object} [target] - target object for valid options
429
+ * @throws {Error} Invalid options
430
+ */
431
+ function trySetAnimationOptions (source, target) {
432
+ if (is.object(source) && is.defined(source.pageHeight)) {
433
+ if (is.integer(source.pageHeight) && source.pageHeight > 0) {
434
+ target.pageHeight = source.pageHeight;
435
+ } else {
436
+ throw is.invalidParameterError('pageHeight', 'integer larger than 0', source.pageHeight);
437
+ }
438
+ }
439
+ if (is.object(source) && is.defined(source.loop)) {
440
+ if (is.integer(source.loop) && is.inRange(source.loop, 0, 65535)) {
441
+ target.loop = source.loop;
442
+ } else {
443
+ throw is.invalidParameterError('loop', 'integer between 0 and 65535', source.loop);
444
+ }
445
+ }
446
+ if (is.object(source) && is.defined(source.delay)) {
447
+ if (
448
+ Array.isArray(source.delay) &&
449
+ source.delay.every(is.integer) &&
450
+ source.delay.every(v => is.inRange(v, 0, 65535))) {
451
+ target.delay = source.delay;
452
+ } else {
453
+ throw is.invalidParameterError('delay', 'array of integers between 0 and 65535', source.delay);
454
+ }
455
+ }
456
+ }
457
+
373
458
  /**
374
459
  * Use these TIFF options for output image.
375
460
  *
@@ -378,23 +463,23 @@ function webp (options) {
378
463
  * sharp('input.svg')
379
464
  * .tiff({
380
465
  * compression: 'lzw',
381
- * squash: true
466
+ * bitdepth: 1
382
467
  * })
383
468
  * .toFile('1-bpp-output.tiff')
384
469
  * .then(info => { ... });
385
470
  *
386
471
  * @param {Object} [options] - output options
387
- * @param {Number} [options.quality=80] - quality, integer 1-100
388
- * @param {Boolean} [options.force=true] - force TIFF output, otherwise attempt to use input format
389
- * @param {Boolean} [options.compression='jpeg'] - compression options: lzw, deflate, jpeg, ccittfax4
390
- * @param {Boolean} [options.predictor='horizontal'] - compression predictor options: none, horizontal, float
391
- * @param {Boolean} [options.pyramid=false] - write an image pyramid
392
- * @param {Boolean} [options.tile=false] - write a tiled tiff
393
- * @param {Boolean} [options.tileWidth=256] - horizontal tile size
394
- * @param {Boolean} [options.tileHeight=256] - vertical tile size
395
- * @param {Number} [options.xres=1.0] - horizontal resolution in pixels/mm
396
- * @param {Number} [options.yres=1.0] - vertical resolution in pixels/mm
397
- * @param {Boolean} [options.squash=false] - squash 8-bit images down to 1 bit
472
+ * @param {number} [options.quality=80] - quality, integer 1-100
473
+ * @param {boolean} [options.force=true] - force TIFF output, otherwise attempt to use input format
474
+ * @param {boolean} [options.compression='jpeg'] - compression options: lzw, deflate, jpeg, ccittfax4
475
+ * @param {boolean} [options.predictor='horizontal'] - compression predictor options: none, horizontal, float
476
+ * @param {boolean} [options.pyramid=false] - write an image pyramid
477
+ * @param {boolean} [options.tile=false] - write a tiled tiff
478
+ * @param {boolean} [options.tileWidth=256] - horizontal tile size
479
+ * @param {boolean} [options.tileHeight=256] - vertical tile size
480
+ * @param {number} [options.xres=1.0] - horizontal resolution in pixels/mm
481
+ * @param {number} [options.yres=1.0] - vertical resolution in pixels/mm
482
+ * @param {boolean} [options.bitdepth=8] - reduce bitdepth to 1, 2 or 4 bit
398
483
  * @returns {Sharp}
399
484
  * @throws {Error} Invalid options
400
485
  */
@@ -407,8 +492,12 @@ function tiff (options) {
407
492
  throw is.invalidParameterError('quality', 'integer between 1 and 100', options.quality);
408
493
  }
409
494
  }
410
- if (is.defined(options.squash)) {
411
- this._setBooleanOption('tiffSquash', options.squash);
495
+ if (is.defined(options.bitdepth)) {
496
+ if (is.integer(options.bitdepth) && is.inArray(options.bitdepth, [1, 2, 4, 8])) {
497
+ this.options.tiffBitdepth = options.bitdepth;
498
+ } else {
499
+ throw is.invalidParameterError('bitdepth', '1, 2, 4 or 8', options.bitdepth);
500
+ }
412
501
  }
413
502
  // tiling
414
503
  if (is.defined(options.tile)) {
@@ -480,9 +569,9 @@ function tiff (options) {
480
569
  * @since 0.23.0
481
570
  *
482
571
  * @param {Object} [options] - output options
483
- * @param {Number} [options.quality=80] - quality, integer 1-100
484
- * @param {Boolean} [options.compression='hevc'] - compression format: hevc, avc, jpeg, av1
485
- * @param {Boolean} [options.lossless=false] - use lossless compression
572
+ * @param {number} [options.quality=80] - quality, integer 1-100
573
+ * @param {boolean} [options.compression='hevc'] - compression format: hevc, avc, jpeg, av1
574
+ * @param {boolean} [options.lossless=false] - use lossless compression
486
575
  * @returns {Sharp}
487
576
  * @throws {Error} Invalid options
488
577
  */
@@ -532,7 +621,7 @@ function heif (options) {
532
621
  * const data = await sharp('input.png')
533
622
  * .ensureAlpha()
534
623
  * .extractChannel(3)
535
- * .colourspace('b-w')
624
+ * .toColourspace('b-w')
536
625
  * .raw()
537
626
  * .toBuffer();
538
627
  *
@@ -561,14 +650,14 @@ function raw () {
561
650
  * });
562
651
  *
563
652
  * @param {Object} [options]
564
- * @param {Number} [options.size=256] tile size in pixels, a value between 1 and 8192.
565
- * @param {Number} [options.overlap=0] tile overlap in pixels, a value between 0 and 8192.
566
- * @param {Number} [options.angle=0] tile angle of rotation, must be a multiple of 90.
567
- * @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.
568
- * @param {String} [options.depth] how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
569
- * @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
570
- * @param {String} [options.container='fs'] tile container, with value `fs` (filesystem) or `zip` (compressed file).
571
- * @param {String} [options.layout='dz'] filesystem layout, possible values are `dz`, `zoomify` or `google`.
653
+ * @param {number} [options.size=256] tile size in pixels, a value between 1 and 8192.
654
+ * @param {number} [options.overlap=0] tile overlap in pixels, a value between 0 and 8192.
655
+ * @param {number} [options.angle=0] tile angle of rotation, must be a multiple of 90.
656
+ * @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.
657
+ * @param {string} [options.depth] how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
658
+ * @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
659
+ * @param {string} [options.container='fs'] tile container, with value `fs` (filesystem) or `zip` (compressed file).
660
+ * @param {string} [options.layout='dz'] filesystem layout, possible values are `dz`, `iiif`, `zoomify` or `google`.
572
661
  * @returns {Sharp}
573
662
  * @throws {Error} Invalid parameters
574
663
  */
@@ -603,10 +692,10 @@ function tile (options) {
603
692
  }
604
693
  // Layout
605
694
  if (is.defined(options.layout)) {
606
- if (is.string(options.layout) && is.inArray(options.layout, ['dz', 'google', 'zoomify'])) {
695
+ if (is.string(options.layout) && is.inArray(options.layout, ['dz', 'google', 'iiif', 'zoomify'])) {
607
696
  this.options.tileLayout = options.layout;
608
697
  } else {
609
- throw is.invalidParameterError('layout', 'one of: dz, google, zoomify', options.layout);
698
+ throw is.invalidParameterError('layout', 'one of: dz, google, iiif, zoomify', options.layout);
610
699
  }
611
700
  }
612
701
  // Angle of rotation,
@@ -651,9 +740,9 @@ function tile (options) {
651
740
  * Update the output format unless options.force is false,
652
741
  * in which case revert to input format.
653
742
  * @private
654
- * @param {String} formatOut
743
+ * @param {string} formatOut
655
744
  * @param {Object} [options]
656
- * @param {Boolean} [options.force=true] - force output format, otherwise attempt to use input format
745
+ * @param {boolean} [options.force=true] - force output format, otherwise attempt to use input format
657
746
  * @returns {Sharp}
658
747
  */
659
748
  function _updateFormatOut (formatOut, options) {
@@ -664,10 +753,10 @@ function _updateFormatOut (formatOut, options) {
664
753
  }
665
754
 
666
755
  /**
667
- * Update a Boolean attribute of the this.options Object.
756
+ * Update a boolean attribute of the this.options Object.
668
757
  * @private
669
- * @param {String} key
670
- * @param {Boolean} val
758
+ * @param {string} key
759
+ * @param {boolean} val
671
760
  * @throws {Error} Invalid key
672
761
  */
673
762
  function _setBooleanOption (key, val) {
@@ -796,6 +885,7 @@ module.exports = function (Sharp) {
796
885
  webp,
797
886
  tiff,
798
887
  heif,
888
+ gif,
799
889
  raw,
800
890
  tile,
801
891
  // Private
package/lib/platform.js CHANGED
@@ -13,7 +13,8 @@ module.exports = function () {
13
13
  const platformId = [`${platform}${libc}`];
14
14
 
15
15
  if (arch === 'arm') {
16
- platformId.push(`armv${env.npm_config_arm_version || process.config.variables.arm_version || '6'}`);
16
+ const fallback = process.versions.electron ? '7' : '6';
17
+ platformId.push(`armv${env.npm_config_arm_version || process.config.variables.arm_version || fallback}`);
17
18
  } else if (arch === 'arm64') {
18
19
  platformId.push(`arm64v${env.npm_config_arm_version || '8'}`);
19
20
  } else {
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`: Crop to cover both provided dimensions (the default).
100
- * - `contain`: Embed within both provided dimensions.
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 {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.
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 {(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]
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 {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
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 {Number} [threshold=10] the allowed difference from the top-left pixel, a number greater than zero.
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
@@ -23,7 +23,7 @@ let versions = {
23
23
  vips: sharp.libvipsVersion()
24
24
  };
25
25
  try {
26
- versions = require('../vendor/versions.json');
26
+ versions = require(`../vendor/${versions.vips}/versions.json`);
27
27
  } catch (err) {}
28
28
 
29
29
  /**
@@ -39,10 +39,10 @@ try {
39
39
  * sharp.cache( { files: 0 } );
40
40
  * sharp.cache(false);
41
41
  *
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
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 {Number} [concurrency]
81
- * @returns {Number} concurrency
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 {Boolean} [simd=true]
128
- * @returns {Boolean}
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);