sharp 0.28.2 → 0.29.2
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 +2 -2
- package/binding.gyp +12 -9
- package/install/can-compile.js +11 -0
- package/install/dll-copy.js +6 -6
- package/install/libvips.js +4 -9
- package/lib/channel.js +13 -7
- package/lib/colour.js +42 -1
- package/lib/composite.js +2 -0
- package/lib/constructor.js +21 -31
- package/lib/input.js +45 -3
- package/lib/is.js +19 -5
- package/lib/libvips.js +4 -19
- package/lib/operation.js +74 -7
- package/lib/output.js +145 -16
- package/lib/sharp.js +31 -0
- package/lib/utility.js +3 -2
- package/package.json +19 -15
- package/src/common.cc +67 -11
- package/src/common.h +25 -5
- package/src/libvips/cplusplus/VConnection.cpp +0 -26
- package/src/libvips/cplusplus/VImage.cpp +54 -16
- package/src/libvips/cplusplus/VInterpolate.cpp +0 -13
- package/src/libvips/cplusplus/vips-operators.cpp +185 -1
- package/src/metadata.cc +14 -0
- package/src/metadata.h +1 -0
- package/src/operations.cc +36 -3
- package/src/operations.h +18 -2
- package/src/pipeline.cc +104 -34
- package/src/pipeline.h +29 -3
- package/src/utilities.cc +1 -1
package/lib/operation.js
CHANGED
|
@@ -270,9 +270,11 @@ function blur (sigma) {
|
|
|
270
270
|
/**
|
|
271
271
|
* Merge alpha transparency channel, if any, with a background, then remove the alpha channel.
|
|
272
272
|
*
|
|
273
|
+
* See also {@link /api-channel#removealpha|removeAlpha}.
|
|
274
|
+
*
|
|
273
275
|
* @example
|
|
274
276
|
* await sharp(rgbaInput)
|
|
275
|
-
* .flatten({background: '#F0A703' })
|
|
277
|
+
* .flatten({ background: '#F0A703' })
|
|
276
278
|
* .toBuffer();
|
|
277
279
|
*
|
|
278
280
|
* @param {Object} [options]
|
|
@@ -323,11 +325,19 @@ function gamma (gamma, gammaOut) {
|
|
|
323
325
|
|
|
324
326
|
/**
|
|
325
327
|
* Produce the "negative" of the image.
|
|
326
|
-
* @param {
|
|
328
|
+
* @param {Object} [options]
|
|
329
|
+
* @param {Boolean} [options.alpha=true] Whether or not to negate any alpha channel
|
|
327
330
|
* @returns {Sharp}
|
|
328
331
|
*/
|
|
329
|
-
function negate (
|
|
330
|
-
this.options.negate = is.bool(
|
|
332
|
+
function negate (options) {
|
|
333
|
+
this.options.negate = is.bool(options) ? options : true;
|
|
334
|
+
if (is.plainObject(options) && 'alpha' in options) {
|
|
335
|
+
if (!is.bool(options.alpha)) {
|
|
336
|
+
throw is.invalidParameterError('alpha', 'should be boolean value', options.alpha);
|
|
337
|
+
} else {
|
|
338
|
+
this.options.negateAlpha = options.alpha;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
331
341
|
return this;
|
|
332
342
|
}
|
|
333
343
|
|
|
@@ -350,6 +360,47 @@ function normalize (normalize) {
|
|
|
350
360
|
return this.normalise(normalize);
|
|
351
361
|
}
|
|
352
362
|
|
|
363
|
+
/**
|
|
364
|
+
* Perform contrast limiting adaptive histogram equalization
|
|
365
|
+
* {@link https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE|CLAHE}.
|
|
366
|
+
*
|
|
367
|
+
* This will, in general, enhance the clarity of the image by bringing out darker details.
|
|
368
|
+
*
|
|
369
|
+
* @since 0.28.3
|
|
370
|
+
*
|
|
371
|
+
* @param {Object} options
|
|
372
|
+
* @param {number} options.width - integer width of the region in pixels.
|
|
373
|
+
* @param {number} options.height - integer height of the region in pixels.
|
|
374
|
+
* @param {number} [options.maxSlope=3] - maximum value for the slope of the
|
|
375
|
+
* cumulative histogram. A value of 0 disables contrast limiting. Valid values
|
|
376
|
+
* are integers in the range 0-100 (inclusive)
|
|
377
|
+
* @returns {Sharp}
|
|
378
|
+
* @throws {Error} Invalid parameters
|
|
379
|
+
*/
|
|
380
|
+
function clahe (options) {
|
|
381
|
+
if (!is.plainObject(options)) {
|
|
382
|
+
throw is.invalidParameterError('options', 'plain object', options);
|
|
383
|
+
}
|
|
384
|
+
if (!('width' in options) || !is.integer(options.width) || options.width <= 0) {
|
|
385
|
+
throw is.invalidParameterError('width', 'integer above zero', options.width);
|
|
386
|
+
} else {
|
|
387
|
+
this.options.claheWidth = options.width;
|
|
388
|
+
}
|
|
389
|
+
if (!('height' in options) || !is.integer(options.height) || options.height <= 0) {
|
|
390
|
+
throw is.invalidParameterError('height', 'integer above zero', options.height);
|
|
391
|
+
} else {
|
|
392
|
+
this.options.claheHeight = options.height;
|
|
393
|
+
}
|
|
394
|
+
if (!is.defined(options.maxSlope)) {
|
|
395
|
+
this.options.claheMaxSlope = 3;
|
|
396
|
+
} else if (!is.integer(options.maxSlope) || options.maxSlope < 0 || options.maxSlope > 100) {
|
|
397
|
+
throw is.invalidParameterError('maxSlope', 'integer 0-100', options.maxSlope);
|
|
398
|
+
} else {
|
|
399
|
+
this.options.claheMaxSlope = options.maxSlope;
|
|
400
|
+
}
|
|
401
|
+
return this;
|
|
402
|
+
}
|
|
403
|
+
|
|
353
404
|
/**
|
|
354
405
|
* Convolve the image with the specified kernel.
|
|
355
406
|
*
|
|
@@ -368,7 +419,7 @@ function normalize (normalize) {
|
|
|
368
419
|
*
|
|
369
420
|
* @param {Object} kernel
|
|
370
421
|
* @param {number} kernel.width - width of the kernel in pixels.
|
|
371
|
-
* @param {number} kernel.height -
|
|
422
|
+
* @param {number} kernel.height - height of the kernel in pixels.
|
|
372
423
|
* @param {Array<number>} kernel.kernel - Array of length `width*height` containing the kernel values.
|
|
373
424
|
* @param {number} [kernel.scale=sum] - the scale of the kernel in pixels.
|
|
374
425
|
* @param {number} [kernel.offset=0] - the offset of the kernel in pixels.
|
|
@@ -519,14 +570,16 @@ function recomb (inputMatrix) {
|
|
|
519
570
|
}
|
|
520
571
|
|
|
521
572
|
/**
|
|
522
|
-
* Transforms the image using brightness, saturation
|
|
573
|
+
* Transforms the image using brightness, saturation, hue rotation, and lightness.
|
|
574
|
+
* Brightness and lightness both operate on luminance, with the difference being that
|
|
575
|
+
* brightness is multiplicative whereas lightness is additive.
|
|
523
576
|
*
|
|
524
577
|
* @since 0.22.1
|
|
525
578
|
*
|
|
526
579
|
* @example
|
|
527
580
|
* sharp(input)
|
|
528
581
|
* .modulate({
|
|
529
|
-
* brightness: 2 // increase
|
|
582
|
+
* brightness: 2 // increase brightness by a factor of 2
|
|
530
583
|
* });
|
|
531
584
|
*
|
|
532
585
|
* sharp(input)
|
|
@@ -534,6 +587,11 @@ function recomb (inputMatrix) {
|
|
|
534
587
|
* hue: 180 // hue-rotate by 180 degrees
|
|
535
588
|
* });
|
|
536
589
|
*
|
|
590
|
+
* sharp(input)
|
|
591
|
+
* .modulate({
|
|
592
|
+
* lightness: 50 // increase lightness by +50
|
|
593
|
+
* });
|
|
594
|
+
*
|
|
537
595
|
* // decreate brightness and saturation while also hue-rotating by 90 degrees
|
|
538
596
|
* sharp(input)
|
|
539
597
|
* .modulate({
|
|
@@ -546,6 +604,7 @@ function recomb (inputMatrix) {
|
|
|
546
604
|
* @param {number} [options.brightness] Brightness multiplier
|
|
547
605
|
* @param {number} [options.saturation] Saturation multiplier
|
|
548
606
|
* @param {number} [options.hue] Degrees for hue rotation
|
|
607
|
+
* @param {number} [options.lightness] Lightness addend
|
|
549
608
|
* @returns {Sharp}
|
|
550
609
|
*/
|
|
551
610
|
function modulate (options) {
|
|
@@ -573,6 +632,13 @@ function modulate (options) {
|
|
|
573
632
|
throw is.invalidParameterError('hue', 'number', options.hue);
|
|
574
633
|
}
|
|
575
634
|
}
|
|
635
|
+
if ('lightness' in options) {
|
|
636
|
+
if (is.number(options.lightness)) {
|
|
637
|
+
this.options.lightness = options.lightness;
|
|
638
|
+
} else {
|
|
639
|
+
throw is.invalidParameterError('lightness', 'number', options.lightness);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
576
642
|
return this;
|
|
577
643
|
}
|
|
578
644
|
|
|
@@ -594,6 +660,7 @@ module.exports = function (Sharp) {
|
|
|
594
660
|
negate,
|
|
595
661
|
normalise,
|
|
596
662
|
normalize,
|
|
663
|
+
clahe,
|
|
597
664
|
convolve,
|
|
598
665
|
threshold,
|
|
599
666
|
boolean,
|
package/lib/output.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const path = require('path');
|
|
3
4
|
const is = require('./is');
|
|
4
|
-
const sharp = require('
|
|
5
|
+
const sharp = require('./sharp');
|
|
5
6
|
|
|
6
7
|
const formats = new Map([
|
|
7
8
|
['heic', 'heif'],
|
|
@@ -12,11 +13,17 @@ const formats = new Map([
|
|
|
12
13
|
['png', 'png'],
|
|
13
14
|
['raw', 'raw'],
|
|
14
15
|
['tiff', 'tiff'],
|
|
16
|
+
['tif', 'tiff'],
|
|
15
17
|
['webp', 'webp'],
|
|
16
|
-
['gif', 'gif']
|
|
18
|
+
['gif', 'gif'],
|
|
19
|
+
['jp2', 'jp2'],
|
|
20
|
+
['jpx', 'jp2'],
|
|
21
|
+
['j2k', 'jp2'],
|
|
22
|
+
['j2c', 'jp2']
|
|
17
23
|
]);
|
|
18
24
|
|
|
19
25
|
const errMagickSave = new Error('GIF output requires libvips with support for ImageMagick');
|
|
26
|
+
const errJp2Save = new Error('JP2 output requires libvips with support for OpenJPEG');
|
|
20
27
|
|
|
21
28
|
/**
|
|
22
29
|
* Write output image data to a file.
|
|
@@ -28,6 +35,8 @@ const errMagickSave = new Error('GIF output requires libvips with support for Im
|
|
|
28
35
|
* By default all metadata will be removed, which includes EXIF-based orientation.
|
|
29
36
|
* See {@link withMetadata} for control over this.
|
|
30
37
|
*
|
|
38
|
+
* The caller is responsible for ensuring directory structures and permissions exist.
|
|
39
|
+
*
|
|
31
40
|
* A `Promise` is returned when `callback` is not provided.
|
|
32
41
|
*
|
|
33
42
|
* @example
|
|
@@ -52,7 +61,7 @@ function toFile (fileOut, callback) {
|
|
|
52
61
|
let err;
|
|
53
62
|
if (!is.string(fileOut)) {
|
|
54
63
|
err = new Error('Missing output file path');
|
|
55
|
-
} else if (this.options.input.file === fileOut) {
|
|
64
|
+
} else if (is.string(this.options.input.file) && path.resolve(this.options.input.file) === path.resolve(fileOut)) {
|
|
56
65
|
err = new Error('Cannot use same file for input and output');
|
|
57
66
|
} else if (this.options.formatOut === 'input' && fileOut.toLowerCase().endsWith('.gif') && !this.constructor.format.magick.output.file) {
|
|
58
67
|
err = errMagickSave;
|
|
@@ -403,7 +412,7 @@ function png (options) {
|
|
|
403
412
|
const colours = options.colours || options.colors;
|
|
404
413
|
if (is.defined(colours)) {
|
|
405
414
|
if (is.integer(colours) && is.inRange(colours, 2, 256)) {
|
|
406
|
-
this.options.
|
|
415
|
+
this.options.pngBitdepth = 1 << 31 - Math.clz32(Math.ceil(Math.log2(colours)));
|
|
407
416
|
} else {
|
|
408
417
|
throw is.invalidParameterError('colours', 'integer between 2 and 256', colours);
|
|
409
418
|
}
|
|
@@ -509,6 +518,84 @@ function gif (options) {
|
|
|
509
518
|
return this._updateFormatOut('gif', options);
|
|
510
519
|
}
|
|
511
520
|
|
|
521
|
+
/**
|
|
522
|
+
* Use these JP2 options for output image.
|
|
523
|
+
*
|
|
524
|
+
* Requires libvips compiled with support for OpenJPEG.
|
|
525
|
+
* The prebuilt binaries do not include this - see
|
|
526
|
+
* {@link https://sharp.pixelplumbing.com/install#custom-libvips installing a custom libvips}.
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* // Convert any input to lossless JP2 output
|
|
530
|
+
* const data = await sharp(input)
|
|
531
|
+
* .jp2({ lossless: true })
|
|
532
|
+
* .toBuffer();
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
* // Convert any input to very high quality JP2 output
|
|
536
|
+
* const data = await sharp(input)
|
|
537
|
+
* .jp2({
|
|
538
|
+
* quality: 100,
|
|
539
|
+
* chromaSubsampling: '4:4:4'
|
|
540
|
+
* })
|
|
541
|
+
* .toBuffer();
|
|
542
|
+
*
|
|
543
|
+
* @since 0.29.1
|
|
544
|
+
*
|
|
545
|
+
* @param {Object} [options] - output options
|
|
546
|
+
* @param {number} [options.quality=80] - quality, integer 1-100
|
|
547
|
+
* @param {boolean} [options.lossless=false] - use lossless compression mode
|
|
548
|
+
* @param {number} [options.tileWidth=512] - horizontal tile size
|
|
549
|
+
* @param {number} [options.tileHeight=512] - vertical tile size
|
|
550
|
+
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
|
|
551
|
+
* @returns {Sharp}
|
|
552
|
+
* @throws {Error} Invalid options
|
|
553
|
+
*/
|
|
554
|
+
/* istanbul ignore next */
|
|
555
|
+
function jp2 (options) {
|
|
556
|
+
if (!this.constructor.format.jp2k.output.buffer) {
|
|
557
|
+
throw errJp2Save;
|
|
558
|
+
}
|
|
559
|
+
if (is.object(options)) {
|
|
560
|
+
if (is.defined(options.quality)) {
|
|
561
|
+
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
|
562
|
+
this.options.jp2Quality = options.quality;
|
|
563
|
+
} else {
|
|
564
|
+
throw is.invalidParameterError('quality', 'integer between 1 and 100', options.quality);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
if (is.defined(options.lossless)) {
|
|
568
|
+
if (is.bool(options.lossless)) {
|
|
569
|
+
this.options.jp2Lossless = options.lossless;
|
|
570
|
+
} else {
|
|
571
|
+
throw is.invalidParameterError('lossless', 'boolean', options.lossless);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
if (is.defined(options.tileWidth)) {
|
|
575
|
+
if (is.integer(options.tileWidth) && is.inRange(options.tileWidth, 1, 32768)) {
|
|
576
|
+
this.options.jp2TileWidth = options.tileWidth;
|
|
577
|
+
} else {
|
|
578
|
+
throw is.invalidParameterError('tileWidth', 'integer between 1 and 32768', options.tileWidth);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
if (is.defined(options.tileHeight)) {
|
|
582
|
+
if (is.integer(options.tileHeight) && is.inRange(options.tileHeight, 1, 32768)) {
|
|
583
|
+
this.options.jp2TileHeight = options.tileHeight;
|
|
584
|
+
} else {
|
|
585
|
+
throw is.invalidParameterError('tileHeight', 'integer between 1 and 32768', options.tileHeight);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
if (is.defined(options.chromaSubsampling)) {
|
|
589
|
+
if (is.string(options.chromaSubsampling) && is.inArray(options.chromaSubsampling, ['4:2:0', '4:4:4'])) {
|
|
590
|
+
this.options.heifChromaSubsampling = options.chromaSubsampling;
|
|
591
|
+
} else {
|
|
592
|
+
throw is.invalidParameterError('chromaSubsampling', 'one of: 4:2:0, 4:4:4', options.chromaSubsampling);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
return this._updateFormatOut('jp2', options);
|
|
597
|
+
}
|
|
598
|
+
|
|
512
599
|
/**
|
|
513
600
|
* Set animation options if available.
|
|
514
601
|
* @private
|
|
@@ -654,13 +741,15 @@ function tiff (options) {
|
|
|
654
741
|
* Whilst it is possible to create AVIF images smaller than 16x16 pixels,
|
|
655
742
|
* most web browsers do not display these properly.
|
|
656
743
|
*
|
|
744
|
+
* AVIF image sequences are not supported.
|
|
745
|
+
*
|
|
657
746
|
* @since 0.27.0
|
|
658
747
|
*
|
|
659
748
|
* @param {Object} [options] - output options
|
|
660
749
|
* @param {number} [options.quality=50] - quality, integer 1-100
|
|
661
750
|
* @param {boolean} [options.lossless=false] - use lossless compression
|
|
662
|
-
* @param {number} [options.speed=5] - CPU effort vs file size, 0 (slowest/smallest) to
|
|
663
|
-
* @param {string} [options.chromaSubsampling='4:
|
|
751
|
+
* @param {number} [options.speed=5] - CPU effort vs file size, 0 (slowest/smallest) to 9 (fastest/largest)
|
|
752
|
+
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
|
|
664
753
|
* @returns {Sharp}
|
|
665
754
|
* @throws {Error} Invalid options
|
|
666
755
|
*/
|
|
@@ -680,8 +769,8 @@ function avif (options) {
|
|
|
680
769
|
* @param {number} [options.quality=50] - quality, integer 1-100
|
|
681
770
|
* @param {string} [options.compression='av1'] - compression format: av1, hevc
|
|
682
771
|
* @param {boolean} [options.lossless=false] - use lossless compression
|
|
683
|
-
* @param {number} [options.speed=5] - CPU effort vs file size, 0 (slowest/smallest) to
|
|
684
|
-
* @param {string} [options.chromaSubsampling='4:
|
|
772
|
+
* @param {number} [options.speed=5] - CPU effort vs file size, 0 (slowest/smallest) to 9 (fastest/largest)
|
|
773
|
+
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
|
|
685
774
|
* @returns {Sharp}
|
|
686
775
|
* @throws {Error} Invalid options
|
|
687
776
|
*/
|
|
@@ -709,10 +798,10 @@ function heif (options) {
|
|
|
709
798
|
}
|
|
710
799
|
}
|
|
711
800
|
if (is.defined(options.speed)) {
|
|
712
|
-
if (is.integer(options.speed) && is.inRange(options.speed, 0,
|
|
801
|
+
if (is.integer(options.speed) && is.inRange(options.speed, 0, 9)) {
|
|
713
802
|
this.options.heifSpeed = options.speed;
|
|
714
803
|
} else {
|
|
715
|
-
throw is.invalidParameterError('speed', 'integer between 0 and
|
|
804
|
+
throw is.invalidParameterError('speed', 'integer between 0 and 9', options.speed);
|
|
716
805
|
}
|
|
717
806
|
}
|
|
718
807
|
if (is.defined(options.chromaSubsampling)) {
|
|
@@ -727,28 +816,41 @@ function heif (options) {
|
|
|
727
816
|
}
|
|
728
817
|
|
|
729
818
|
/**
|
|
730
|
-
* Force output to be raw, uncompressed
|
|
819
|
+
* Force output to be raw, uncompressed pixel data.
|
|
731
820
|
* Pixel ordering is left-to-right, top-to-bottom, without padding.
|
|
732
821
|
* Channel ordering will be RGB or RGBA for non-greyscale colourspaces.
|
|
733
822
|
*
|
|
734
823
|
* @example
|
|
735
|
-
* // Extract raw RGB pixel data from JPEG input
|
|
824
|
+
* // Extract raw, unsigned 8-bit RGB pixel data from JPEG input
|
|
736
825
|
* const { data, info } = await sharp('input.jpg')
|
|
737
826
|
* .raw()
|
|
738
827
|
* .toBuffer({ resolveWithObject: true });
|
|
739
828
|
*
|
|
740
829
|
* @example
|
|
741
|
-
* // Extract alpha channel as raw pixel data from PNG input
|
|
830
|
+
* // Extract alpha channel as raw, unsigned 16-bit pixel data from PNG input
|
|
742
831
|
* const data = await sharp('input.png')
|
|
743
832
|
* .ensureAlpha()
|
|
744
833
|
* .extractChannel(3)
|
|
745
834
|
* .toColourspace('b-w')
|
|
746
|
-
* .raw()
|
|
835
|
+
* .raw({ depth: 'ushort' })
|
|
747
836
|
* .toBuffer();
|
|
748
837
|
*
|
|
749
|
-
* @
|
|
838
|
+
* @param {Object} [options] - output options
|
|
839
|
+
* @param {string} [options.depth='uchar'] - bit depth, one of: char, uchar (default), short, ushort, int, uint, float, complex, double, dpcomplex
|
|
840
|
+
* @throws {Error} Invalid options
|
|
750
841
|
*/
|
|
751
|
-
function raw () {
|
|
842
|
+
function raw (options) {
|
|
843
|
+
if (is.object(options)) {
|
|
844
|
+
if (is.defined(options.depth)) {
|
|
845
|
+
if (is.string(options.depth) && is.inArray(options.depth,
|
|
846
|
+
['char', 'uchar', 'short', 'ushort', 'int', 'uint', 'float', 'complex', 'double', 'dpcomplex']
|
|
847
|
+
)) {
|
|
848
|
+
this.options.rawDepth = options.depth;
|
|
849
|
+
} else {
|
|
850
|
+
throw is.invalidParameterError('depth', 'one of: char, uchar, short, ushort, int, uint, float, complex, double, dpcomplex', options.depth);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
752
854
|
return this._updateFormatOut('raw');
|
|
753
855
|
}
|
|
754
856
|
|
|
@@ -873,6 +975,31 @@ function tile (options) {
|
|
|
873
975
|
return this._updateFormatOut('dz');
|
|
874
976
|
}
|
|
875
977
|
|
|
978
|
+
/**
|
|
979
|
+
* Set a timeout for processing, in seconds.
|
|
980
|
+
* Use a value of zero to continue processing indefinitely, the default behaviour.
|
|
981
|
+
*
|
|
982
|
+
* The clock starts when libvips opens an input image for processing.
|
|
983
|
+
* Time spent waiting for a libuv thread to become available is not included.
|
|
984
|
+
*
|
|
985
|
+
* @since 0.29.2
|
|
986
|
+
*
|
|
987
|
+
* @param {Object} options
|
|
988
|
+
* @param {number} options.seconds - Number of seconds after which processing will be stopped
|
|
989
|
+
* @returns {Sharp}
|
|
990
|
+
*/
|
|
991
|
+
function timeout (options) {
|
|
992
|
+
if (!is.plainObject(options)) {
|
|
993
|
+
throw is.invalidParameterError('options', 'object', options);
|
|
994
|
+
}
|
|
995
|
+
if (is.integer(options.seconds) && is.inRange(options.seconds, 0, 3600)) {
|
|
996
|
+
this.options.timeoutSeconds = options.seconds;
|
|
997
|
+
} else {
|
|
998
|
+
throw is.invalidParameterError('seconds', 'integer between 0 and 3600', options.seconds);
|
|
999
|
+
}
|
|
1000
|
+
return this;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
876
1003
|
/**
|
|
877
1004
|
* Update the output format unless options.force is false,
|
|
878
1005
|
* in which case revert to input format.
|
|
@@ -1018,6 +1145,7 @@ module.exports = function (Sharp) {
|
|
|
1018
1145
|
withMetadata,
|
|
1019
1146
|
toFormat,
|
|
1020
1147
|
jpeg,
|
|
1148
|
+
jp2,
|
|
1021
1149
|
png,
|
|
1022
1150
|
webp,
|
|
1023
1151
|
tiff,
|
|
@@ -1026,6 +1154,7 @@ module.exports = function (Sharp) {
|
|
|
1026
1154
|
gif,
|
|
1027
1155
|
raw,
|
|
1028
1156
|
tile,
|
|
1157
|
+
timeout,
|
|
1029
1158
|
// Private
|
|
1030
1159
|
_updateFormatOut,
|
|
1031
1160
|
_setBooleanOption,
|
package/lib/sharp.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const platformAndArch = require('./platform')();
|
|
4
|
+
|
|
5
|
+
/* istanbul ignore next */
|
|
6
|
+
try {
|
|
7
|
+
module.exports = require(`../build/Release/sharp-${platformAndArch}.node`);
|
|
8
|
+
} catch (err) {
|
|
9
|
+
// Bail early if bindings aren't available
|
|
10
|
+
const help = ['', 'Something went wrong installing the "sharp" module', '', err.message, '', 'Possible solutions:'];
|
|
11
|
+
if (/dylib/.test(err.message) && /Incompatible library version/.test(err.message)) {
|
|
12
|
+
help.push('- Update Homebrew: "brew update && brew upgrade vips"');
|
|
13
|
+
} else {
|
|
14
|
+
help.push(
|
|
15
|
+
'- Install with the --verbose flag and look for errors: "npm install --ignore-scripts=false --verbose sharp"',
|
|
16
|
+
`- Install for the current runtime: "npm install --platform=${process.platform} --arch=${process.arch} sharp"`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
help.push(
|
|
20
|
+
'- Consult the installation documentation: https://sharp.pixelplumbing.com/install'
|
|
21
|
+
);
|
|
22
|
+
// Check loaded
|
|
23
|
+
if (process.platform === 'win32') {
|
|
24
|
+
const loadedModule = Object.keys(require.cache).find((i) => /[\\/]build[\\/]Release[\\/]sharp(.*)\.node$/.test(i));
|
|
25
|
+
if (loadedModule) {
|
|
26
|
+
const [, loadedPackage] = loadedModule.match(/node_modules[\\/]([^\\/]+)[\\/]/);
|
|
27
|
+
help.push(`- Ensure the version of sharp aligns with the ${loadedPackage} package: "npm ls sharp"`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
throw new Error(help.join('\n'));
|
|
31
|
+
}
|
package/lib/utility.js
CHANGED
|
@@ -4,7 +4,8 @@ const events = require('events');
|
|
|
4
4
|
const detectLibc = require('detect-libc');
|
|
5
5
|
|
|
6
6
|
const is = require('./is');
|
|
7
|
-
const
|
|
7
|
+
const platformAndArch = require('./platform')();
|
|
8
|
+
const sharp = require('./sharp');
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* An Object containing nested boolean values representing the available input and output formats/methods.
|
|
@@ -45,7 +46,7 @@ let versions = {
|
|
|
45
46
|
vips: sharp.libvipsVersion()
|
|
46
47
|
};
|
|
47
48
|
try {
|
|
48
|
-
versions = require(`../vendor/${versions.vips}/versions.json`);
|
|
49
|
+
versions = require(`../vendor/${versions.vips}/${platformAndArch}/versions.json`);
|
|
49
50
|
} catch (err) {}
|
|
50
51
|
|
|
51
52
|
/**
|
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, AVIF and TIFF images",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.29.2",
|
|
5
5
|
"author": "Lovell Fuller <npm@lovell.info>",
|
|
6
6
|
"homepage": "https://github.com/lovell/sharp",
|
|
7
7
|
"contributors": [
|
|
@@ -76,10 +76,13 @@
|
|
|
76
76
|
"Leon Radley <leon@radley.se>",
|
|
77
77
|
"alza54 <alza54@thiocod.in>",
|
|
78
78
|
"Jacob Smith <jacob@frende.me>",
|
|
79
|
-
"Michael Nutt <michael@nutt.im>"
|
|
79
|
+
"Michael Nutt <michael@nutt.im>",
|
|
80
|
+
"Brad Parham <baparham@gmail.com>",
|
|
81
|
+
"Taneli Vatanen <taneli.vatanen@gmail.com>",
|
|
82
|
+
"Joris Dugué <zaruike10@gmail.com>"
|
|
80
83
|
],
|
|
81
84
|
"scripts": {
|
|
82
|
-
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)",
|
|
85
|
+
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)",
|
|
83
86
|
"clean": "rm -rf node_modules/ build/ vendor/ .nyc_output/ coverage/ test/fixtures/output.*",
|
|
84
87
|
"test": "npm run test-lint && npm run test-unit && npm run test-licensing",
|
|
85
88
|
"test-lint": "semistandard && cpplint",
|
|
@@ -110,6 +113,7 @@
|
|
|
110
113
|
"tiff",
|
|
111
114
|
"gif",
|
|
112
115
|
"svg",
|
|
116
|
+
"jp2",
|
|
113
117
|
"dzi",
|
|
114
118
|
"image",
|
|
115
119
|
"resize",
|
|
@@ -120,45 +124,45 @@
|
|
|
120
124
|
"vips"
|
|
121
125
|
],
|
|
122
126
|
"dependencies": {
|
|
123
|
-
"color": "^
|
|
127
|
+
"color": "^4.0.1",
|
|
124
128
|
"detect-libc": "^1.0.3",
|
|
125
|
-
"node-addon-api": "^
|
|
126
|
-
"prebuild-install": "^6.1.
|
|
129
|
+
"node-addon-api": "^4.2.0",
|
|
130
|
+
"prebuild-install": "^6.1.4",
|
|
127
131
|
"semver": "^7.3.5",
|
|
128
132
|
"simple-get": "^3.1.0",
|
|
129
133
|
"tar-fs": "^2.1.1",
|
|
130
134
|
"tunnel-agent": "^0.6.0"
|
|
131
135
|
},
|
|
132
136
|
"devDependencies": {
|
|
133
|
-
"async": "^3.2.
|
|
137
|
+
"async": "^3.2.1",
|
|
134
138
|
"cc": "^3.0.1",
|
|
135
139
|
"decompress-zip": "^0.3.3",
|
|
136
140
|
"documentation": "^13.2.5",
|
|
137
141
|
"exif-reader": "^1.0.3",
|
|
138
142
|
"icc": "^2.0.0",
|
|
139
143
|
"license-checker": "^25.0.1",
|
|
140
|
-
"mocha": "^
|
|
141
|
-
"mock-fs": "^
|
|
144
|
+
"mocha": "^9.1.3",
|
|
145
|
+
"mock-fs": "^5.1.1",
|
|
142
146
|
"nyc": "^15.1.0",
|
|
143
|
-
"prebuild": "^
|
|
147
|
+
"prebuild": "^11.0.0",
|
|
144
148
|
"rimraf": "^3.0.2",
|
|
145
|
-
"semistandard": "^16.0.
|
|
149
|
+
"semistandard": "^16.0.1"
|
|
146
150
|
},
|
|
147
151
|
"license": "Apache-2.0",
|
|
148
152
|
"config": {
|
|
149
|
-
"libvips": "8.
|
|
153
|
+
"libvips": "8.11.3",
|
|
150
154
|
"runtime": "napi",
|
|
151
|
-
"target":
|
|
155
|
+
"target": 5
|
|
152
156
|
},
|
|
153
157
|
"engines": {
|
|
154
|
-
"node": ">=
|
|
158
|
+
"node": ">=12.13.0"
|
|
155
159
|
},
|
|
156
160
|
"funding": {
|
|
157
161
|
"url": "https://opencollective.com/libvips"
|
|
158
162
|
},
|
|
159
163
|
"binary": {
|
|
160
164
|
"napi_versions": [
|
|
161
|
-
|
|
165
|
+
5
|
|
162
166
|
]
|
|
163
167
|
},
|
|
164
168
|
"semistandard": {
|