sharp 0.33.5 → 0.35.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/README.md +12 -18
- package/dist/channel.cjs +177 -0
- package/{lib/channel.js → dist/channel.mjs} +11 -8
- package/dist/colour.cjs +195 -0
- package/{lib/colour.js → dist/colour.mjs} +38 -23
- package/dist/composite.cjs +213 -0
- package/{lib/composite.js → dist/composite.mjs} +14 -11
- package/{lib/constructor.js → dist/constructor.cjs} +102 -43
- package/dist/constructor.mjs +511 -0
- package/dist/index.cjs +25 -0
- package/dist/index.mjs +25 -0
- package/dist/input.cjs +814 -0
- package/{lib/input.js → dist/input.mjs} +224 -68
- package/{lib/is.js → dist/is.cjs} +19 -45
- package/dist/is.mjs +143 -0
- package/{lib/libvips.js → dist/libvips.cjs} +52 -43
- package/dist/libvips.mjs +212 -0
- package/dist/operation.cjs +987 -0
- package/{lib/operation.js → dist/operation.mjs} +108 -79
- package/{lib/output.js → dist/output.cjs} +243 -36
- package/dist/output.mjs +1794 -0
- package/dist/resize.cjs +613 -0
- package/{lib/resize.js → dist/resize.mjs} +38 -12
- package/dist/sharp.cjs +164 -0
- package/dist/sharp.mjs +164 -0
- package/{lib/utility.js → dist/utility.cjs} +23 -24
- package/dist/utility.mjs +295 -0
- package/install/build.js +38 -0
- package/lib/index.d.ts +347 -125
- package/package.json +75 -84
- package/src/binding.gyp +49 -26
- package/src/common.cc +203 -111
- package/src/common.h +68 -40
- package/src/metadata.cc +106 -22
- package/src/metadata.h +15 -5
- package/src/operations.cc +62 -21
- package/src/operations.h +15 -3
- package/src/pipeline.cc +374 -183
- package/src/pipeline.h +34 -7
- package/src/sharp.cc +11 -8
- package/src/stats.cc +16 -13
- package/src/stats.h +6 -3
- package/src/utilities.cc +32 -12
- package/src/utilities.h +5 -2
- package/install/check.js +0 -41
- package/lib/index.js +0 -16
- package/lib/sharp.js +0 -114
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/*!
|
|
2
|
+
Copyright 2013 Lovell Fuller and others.
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
6
|
const path = require('node:path');
|
|
7
|
-
const is = require('./is');
|
|
8
|
-
const sharp = require('./sharp');
|
|
7
|
+
const is = require('./is.cjs');
|
|
8
|
+
const sharp = require('./sharp.cjs');
|
|
9
9
|
|
|
10
10
|
const formats = new Map([
|
|
11
11
|
['heic', 'heif'],
|
|
@@ -43,7 +43,7 @@ const bitdepthFromColourCount = (colours) => 1 << 31 - Math.clz32(Math.ceil(Math
|
|
|
43
43
|
* Note that raw pixel data is only supported for buffer output.
|
|
44
44
|
*
|
|
45
45
|
* By default all metadata will be removed, which includes EXIF-based orientation.
|
|
46
|
-
* See {@link #withmetadata
|
|
46
|
+
* See {@link #withmetadata withMetadata} for control over this.
|
|
47
47
|
*
|
|
48
48
|
* The caller is responsible for ensuring directory structures and permissions exist.
|
|
49
49
|
*
|
|
@@ -76,7 +76,7 @@ function toFile (fileOut, callback) {
|
|
|
76
76
|
err = new Error('Missing output file path');
|
|
77
77
|
} else if (is.string(this.options.input.file) && path.resolve(this.options.input.file) === path.resolve(fileOut)) {
|
|
78
78
|
err = new Error('Cannot use same file for input and output');
|
|
79
|
-
} else if (jp2Regex.test(path.extname(fileOut)) && !this.constructor.format.
|
|
79
|
+
} else if (jp2Regex.test(path.extname(fileOut)) && !this.constructor.format.jp2.output.file) {
|
|
80
80
|
err = errJp2Save();
|
|
81
81
|
}
|
|
82
82
|
if (err) {
|
|
@@ -97,12 +97,12 @@ function toFile (fileOut, callback) {
|
|
|
97
97
|
* Write output to a Buffer.
|
|
98
98
|
* JPEG, PNG, WebP, AVIF, TIFF, GIF and raw pixel data output are supported.
|
|
99
99
|
*
|
|
100
|
-
* Use {@link #toformat
|
|
100
|
+
* Use {@link #toformat toFormat} or one of the format-specific functions such as {@link #jpeg jpeg}, {@link #png png} etc. to set the output format.
|
|
101
101
|
*
|
|
102
102
|
* If no explicit format is set, the output format will match the input image, except SVG input which becomes PNG output.
|
|
103
103
|
*
|
|
104
104
|
* By default all metadata will be removed, which includes EXIF-based orientation.
|
|
105
|
-
* See {@link #withmetadata
|
|
105
|
+
* See {@link #withmetadata withMetadata} for control over this.
|
|
106
106
|
*
|
|
107
107
|
* `callback`, if present, gets three arguments `(err, data, info)` where:
|
|
108
108
|
* - `err` is an error, if any.
|
|
@@ -164,6 +164,64 @@ function toBuffer (options, callback) {
|
|
|
164
164
|
return this._pipeline(is.fn(options) ? options : callback, stack);
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Write output to a `Uint8Array` backed by a transferable `ArrayBuffer`.
|
|
169
|
+
* JPEG, PNG, WebP, AVIF, TIFF, GIF and raw pixel data output are supported.
|
|
170
|
+
*
|
|
171
|
+
* Use {@link #toformat toFormat} or one of the format-specific functions such as {@link #jpeg jpeg}, {@link #png png} etc. to set the output format.
|
|
172
|
+
*
|
|
173
|
+
* If no explicit format is set, the output format will match the input image, except SVG input which becomes PNG output.
|
|
174
|
+
*
|
|
175
|
+
* By default all metadata will be removed, which includes EXIF-based orientation.
|
|
176
|
+
* See {@link #keepexif keepExif} and similar methods for control over this.
|
|
177
|
+
*
|
|
178
|
+
* Resolves with an `Object` containing:
|
|
179
|
+
* - `data` is the output image as a `Uint8Array` backed by a transferable `ArrayBuffer`.
|
|
180
|
+
* - `info` contains properties relating to the output image such as `width` and `height`.
|
|
181
|
+
*
|
|
182
|
+
* @since v0.35.0
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* const { data, info } = await sharp(input).toUint8Array();
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* const { data } = await sharp(input)
|
|
189
|
+
* .avif()
|
|
190
|
+
* .toUint8Array();
|
|
191
|
+
* const base64String = data.toBase64();
|
|
192
|
+
*
|
|
193
|
+
* @returns {Promise<{ data: Uint8Array, info: Object }>}
|
|
194
|
+
*/
|
|
195
|
+
function toUint8Array () {
|
|
196
|
+
this.options.resolveWithObject = true;
|
|
197
|
+
this.options.typedArrayOut = true;
|
|
198
|
+
const stack = Error();
|
|
199
|
+
return this._pipeline(null, stack);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Set output density (DPI) in EXIF metadata.
|
|
204
|
+
*
|
|
205
|
+
* @since 0.35.0
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* const data = await sharp(input)
|
|
209
|
+
* .withDensity(96)
|
|
210
|
+
* .toBuffer();
|
|
211
|
+
*
|
|
212
|
+
* @param {number} density Number of pixels per inch (DPI).
|
|
213
|
+
* @returns {Sharp}
|
|
214
|
+
* @throws {Error} Invalid parameters
|
|
215
|
+
*/
|
|
216
|
+
function withDensity (density) {
|
|
217
|
+
if (is.number(density) && density > 0) {
|
|
218
|
+
this.options.withMetadataDensity = density;
|
|
219
|
+
} else {
|
|
220
|
+
throw is.invalidParameterError('density', 'positive number', density);
|
|
221
|
+
}
|
|
222
|
+
return this.keepExif();
|
|
223
|
+
}
|
|
224
|
+
|
|
167
225
|
/**
|
|
168
226
|
* Keep all EXIF metadata from the input image in the output image.
|
|
169
227
|
*
|
|
@@ -256,7 +314,7 @@ function withExifMerge (exif) {
|
|
|
256
314
|
/**
|
|
257
315
|
* Keep ICC profile from the input image in the output image.
|
|
258
316
|
*
|
|
259
|
-
*
|
|
317
|
+
* When input and output colour spaces differ, use with {@link /api-colour/#tocolourspace toColourspace} and optionally {@link /api-colour/#pipelinecolourspace pipelineColourspace}.
|
|
260
318
|
*
|
|
261
319
|
* @since 0.33.0
|
|
262
320
|
*
|
|
@@ -265,6 +323,13 @@ function withExifMerge (exif) {
|
|
|
265
323
|
* .keepIccProfile()
|
|
266
324
|
* .toBuffer();
|
|
267
325
|
*
|
|
326
|
+
* @example
|
|
327
|
+
* const cmykOutputWithIccProfile = await sharp(cmykInputWithIccProfile)
|
|
328
|
+
* .pipelineColourspace('cmyk')
|
|
329
|
+
* .toColourspace('cmyk')
|
|
330
|
+
* .keepIccProfile()
|
|
331
|
+
* .toBuffer();
|
|
332
|
+
*
|
|
268
333
|
* @returns {Sharp}
|
|
269
334
|
*/
|
|
270
335
|
function keepIccProfile () {
|
|
@@ -312,6 +377,113 @@ function withIccProfile (icc, options) {
|
|
|
312
377
|
return this;
|
|
313
378
|
}
|
|
314
379
|
|
|
380
|
+
/**
|
|
381
|
+
* If the input contains gain map metadata, attempt to process the image and gain map separately,
|
|
382
|
+
* recombining them into a single output image.
|
|
383
|
+
*
|
|
384
|
+
* This approach is faster and should produce better results than {@link #withgainmap withGainMap},
|
|
385
|
+
* however not all operations are supported.
|
|
386
|
+
*
|
|
387
|
+
* Only JPEG input and output are supported.
|
|
388
|
+
* JPEG output options other than `quality` are ignored.
|
|
389
|
+
*
|
|
390
|
+
* This feature is experimental and the API may change.
|
|
391
|
+
*
|
|
392
|
+
* @since 0.35.0
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* const outputWithResizedGainMap = await sharp(inputWithGainMap)
|
|
396
|
+
* .keepGainMap()
|
|
397
|
+
* .resize({ width: 64 })
|
|
398
|
+
* .toBuffer();
|
|
399
|
+
*
|
|
400
|
+
* @returns {Sharp}
|
|
401
|
+
*/
|
|
402
|
+
function keepGainMap() {
|
|
403
|
+
this.options.keepGainMap = true;
|
|
404
|
+
this.options.withGainMap = false;
|
|
405
|
+
this.options.keepMetadata |= 0b100000;
|
|
406
|
+
return this;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* If the input contains gain map metadata, use it to convert the main image to HDR (High Dynamic Range) before further processing.
|
|
411
|
+
* The input gain map is discarded.
|
|
412
|
+
*
|
|
413
|
+
* If the output is JPEG, generate and attach a new ISO 21496-1 gain map.
|
|
414
|
+
* JPEG output options other than `quality` are ignored.
|
|
415
|
+
*
|
|
416
|
+
* This feature is experimental and the API may change.
|
|
417
|
+
*
|
|
418
|
+
* @since 0.35.0
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* const outputWithRegeneratedGainMap = await sharp(inputWithGainMap)
|
|
422
|
+
* .withGainMap()
|
|
423
|
+
* .toBuffer();
|
|
424
|
+
*
|
|
425
|
+
* @returns {Sharp}
|
|
426
|
+
*/
|
|
427
|
+
function withGainMap() {
|
|
428
|
+
this.options.withGainMap = true;
|
|
429
|
+
this.options.keepGainMap = false;
|
|
430
|
+
this.options.colourspace = 'scrgb';
|
|
431
|
+
return this;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Keep XMP metadata from the input image in the output image.
|
|
436
|
+
*
|
|
437
|
+
* @since 0.34.3
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
* const outputWithXmp = await sharp(inputWithXmp)
|
|
441
|
+
* .keepXmp()
|
|
442
|
+
* .toBuffer();
|
|
443
|
+
*
|
|
444
|
+
* @returns {Sharp}
|
|
445
|
+
*/
|
|
446
|
+
function keepXmp () {
|
|
447
|
+
this.options.keepMetadata |= 0b00010;
|
|
448
|
+
return this;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Set XMP metadata in the output image.
|
|
453
|
+
*
|
|
454
|
+
* Supported by PNG, JPEG, WebP, and TIFF output.
|
|
455
|
+
*
|
|
456
|
+
* @since 0.34.3
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* const xmpString = `
|
|
460
|
+
* <?xml version="1.0"?>
|
|
461
|
+
* <x:xmpmeta xmlns:x="adobe:ns:meta/">
|
|
462
|
+
* <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
|
463
|
+
* <rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
|
464
|
+
* <dc:creator><rdf:Seq><rdf:li>John Doe</rdf:li></rdf:Seq></dc:creator>
|
|
465
|
+
* </rdf:Description>
|
|
466
|
+
* </rdf:RDF>
|
|
467
|
+
* </x:xmpmeta>`;
|
|
468
|
+
*
|
|
469
|
+
* const data = await sharp(input)
|
|
470
|
+
* .withXmp(xmpString)
|
|
471
|
+
* .toBuffer();
|
|
472
|
+
*
|
|
473
|
+
* @param {string} xmp String containing XMP metadata to be embedded in the output image.
|
|
474
|
+
* @returns {Sharp}
|
|
475
|
+
* @throws {Error} Invalid parameters
|
|
476
|
+
*/
|
|
477
|
+
function withXmp (xmp) {
|
|
478
|
+
if (is.string(xmp) && xmp.length > 0) {
|
|
479
|
+
this.options.withXmp = xmp;
|
|
480
|
+
this.options.keepMetadata |= 0b00010;
|
|
481
|
+
} else {
|
|
482
|
+
throw is.invalidParameterError('xmp', 'non-empty string', xmp);
|
|
483
|
+
}
|
|
484
|
+
return this;
|
|
485
|
+
}
|
|
486
|
+
|
|
315
487
|
/**
|
|
316
488
|
* Keep all metadata (EXIF, ICC, XMP, IPTC) from the input image in the output image.
|
|
317
489
|
*
|
|
@@ -328,7 +500,7 @@ function withIccProfile (icc, options) {
|
|
|
328
500
|
* @returns {Sharp}
|
|
329
501
|
*/
|
|
330
502
|
function keepMetadata () {
|
|
331
|
-
this.options.keepMetadata
|
|
503
|
+
this.options.keepMetadata |= 0b11111;
|
|
332
504
|
return this;
|
|
333
505
|
}
|
|
334
506
|
|
|
@@ -512,7 +684,7 @@ function jpeg (options) {
|
|
|
512
684
|
* Set `palette` to `true` for slower, indexed PNG output.
|
|
513
685
|
*
|
|
514
686
|
* For 16 bits per pixel output, convert to `rgb16` via
|
|
515
|
-
* {@link /api-colour
|
|
687
|
+
* {@link /api-colour/#tocolourspace toColourspace}.
|
|
516
688
|
*
|
|
517
689
|
* @example
|
|
518
690
|
* // Convert any input to full colour PNG output
|
|
@@ -623,12 +795,14 @@ function png (options) {
|
|
|
623
795
|
* @param {boolean} [options.lossless=false] - use lossless compression mode
|
|
624
796
|
* @param {boolean} [options.nearLossless=false] - use near_lossless compression mode
|
|
625
797
|
* @param {boolean} [options.smartSubsample=false] - use high quality chroma subsampling
|
|
798
|
+
* @param {boolean} [options.smartDeblock=false] - auto-adjust the deblocking filter, can improve low contrast edges (slow)
|
|
626
799
|
* @param {string} [options.preset='default'] - named preset for preprocessing/filtering, one of: default, photo, picture, drawing, icon, text
|
|
627
800
|
* @param {number} [options.effort=4] - CPU effort, between 0 (fastest) and 6 (slowest)
|
|
628
801
|
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
|
|
629
802
|
* @param {number|number[]} [options.delay] - delay(s) between animation frames (in milliseconds)
|
|
630
803
|
* @param {boolean} [options.minSize=false] - prevent use of animation key frames to minimise file size (slow)
|
|
631
804
|
* @param {boolean} [options.mixed=false] - allow mixture of lossy and lossless animation frames (slow)
|
|
805
|
+
* @param {boolean} [options.exact=false] - preserve the colour data in transparent pixels
|
|
632
806
|
* @param {boolean} [options.force=true] - force WebP output, otherwise attempt to use input format
|
|
633
807
|
* @returns {Sharp}
|
|
634
808
|
* @throws {Error} Invalid options
|
|
@@ -658,6 +832,9 @@ function webp (options) {
|
|
|
658
832
|
if (is.defined(options.smartSubsample)) {
|
|
659
833
|
this._setBooleanOption('webpSmartSubsample', options.smartSubsample);
|
|
660
834
|
}
|
|
835
|
+
if (is.defined(options.smartDeblock)) {
|
|
836
|
+
this._setBooleanOption('webpSmartDeblock', options.smartDeblock);
|
|
837
|
+
}
|
|
661
838
|
if (is.defined(options.preset)) {
|
|
662
839
|
if (is.string(options.preset) && is.inArray(options.preset, ['default', 'photo', 'picture', 'drawing', 'icon', 'text'])) {
|
|
663
840
|
this.options.webpPreset = options.preset;
|
|
@@ -678,6 +855,9 @@ function webp (options) {
|
|
|
678
855
|
if (is.defined(options.mixed)) {
|
|
679
856
|
this._setBooleanOption('webpMixed', options.mixed);
|
|
680
857
|
}
|
|
858
|
+
if (is.defined(options.exact)) {
|
|
859
|
+
this._setBooleanOption('webpExact', options.exact);
|
|
860
|
+
}
|
|
681
861
|
}
|
|
682
862
|
trySetAnimationOptions(options, this.options);
|
|
683
863
|
return this._updateFormatOut('webp', options);
|
|
@@ -725,6 +905,7 @@ function webp (options) {
|
|
|
725
905
|
* @param {number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, between 0 (least) and 1 (most)
|
|
726
906
|
* @param {number} [options.interFrameMaxError=0] - maximum inter-frame error for transparency, between 0 (lossless) and 32
|
|
727
907
|
* @param {number} [options.interPaletteMaxError=3] - maximum inter-palette error for palette reuse, between 0 and 256
|
|
908
|
+
* @param {boolean} [options.keepDuplicateFrames=false] - keep duplicate frames in the output instead of combining them
|
|
728
909
|
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
|
|
729
910
|
* @param {number|number[]} [options.delay] - delay(s) between animation frames (in milliseconds)
|
|
730
911
|
* @param {boolean} [options.force=true] - force GIF output, otherwise attempt to use input format
|
|
@@ -775,18 +956,24 @@ function gif (options) {
|
|
|
775
956
|
throw is.invalidParameterError('interPaletteMaxError', 'number between 0.0 and 256.0', options.interPaletteMaxError);
|
|
776
957
|
}
|
|
777
958
|
}
|
|
959
|
+
if (is.defined(options.keepDuplicateFrames)) {
|
|
960
|
+
if (is.bool(options.keepDuplicateFrames)) {
|
|
961
|
+
this._setBooleanOption('gifKeepDuplicateFrames', options.keepDuplicateFrames);
|
|
962
|
+
} else {
|
|
963
|
+
throw is.invalidParameterError('keepDuplicateFrames', 'boolean', options.keepDuplicateFrames);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
778
966
|
}
|
|
779
967
|
trySetAnimationOptions(options, this.options);
|
|
780
968
|
return this._updateFormatOut('gif', options);
|
|
781
969
|
}
|
|
782
970
|
|
|
783
|
-
/* istanbul ignore next */
|
|
784
971
|
/**
|
|
785
972
|
* Use these JP2 options for output image.
|
|
786
973
|
*
|
|
787
974
|
* Requires libvips compiled with support for OpenJPEG.
|
|
788
975
|
* The prebuilt binaries do not include this - see
|
|
789
|
-
* {@link
|
|
976
|
+
* {@link /install#custom-libvips installing a custom libvips}.
|
|
790
977
|
*
|
|
791
978
|
* @example
|
|
792
979
|
* // Convert any input to lossless JP2 output
|
|
@@ -815,7 +1002,8 @@ function gif (options) {
|
|
|
815
1002
|
* @throws {Error} Invalid options
|
|
816
1003
|
*/
|
|
817
1004
|
function jp2 (options) {
|
|
818
|
-
|
|
1005
|
+
/* node:coverage ignore next 41 */
|
|
1006
|
+
if (!this.constructor.format.jp2.output.buffer) {
|
|
819
1007
|
throw errJp2Save();
|
|
820
1008
|
}
|
|
821
1009
|
if (is.object(options)) {
|
|
@@ -894,7 +1082,7 @@ function trySetAnimationOptions (source, target) {
|
|
|
894
1082
|
/**
|
|
895
1083
|
* Use these TIFF options for output image.
|
|
896
1084
|
*
|
|
897
|
-
* The `density` can be set in pixels/inch via {@link #withmetadata
|
|
1085
|
+
* The `density` can be set in pixels/inch via {@link #withmetadata withMetadata}
|
|
898
1086
|
* instead of providing `xres` and `yres` in pixels/mm.
|
|
899
1087
|
*
|
|
900
1088
|
* @example
|
|
@@ -911,6 +1099,7 @@ function trySetAnimationOptions (source, target) {
|
|
|
911
1099
|
* @param {number} [options.quality=80] - quality, integer 1-100
|
|
912
1100
|
* @param {boolean} [options.force=true] - force TIFF output, otherwise attempt to use input format
|
|
913
1101
|
* @param {string} [options.compression='jpeg'] - compression options: none, jpeg, deflate, packbits, ccittfax4, lzw, webp, zstd, jp2k
|
|
1102
|
+
* @param {boolean} [options.bigtiff=false] - use BigTIFF variant (has no effect when compression is none)
|
|
914
1103
|
* @param {string} [options.predictor='horizontal'] - compression predictor options: none, horizontal, float
|
|
915
1104
|
* @param {boolean} [options.pyramid=false] - write an image pyramid
|
|
916
1105
|
* @param {boolean} [options.tile=false] - write a tiled tiff
|
|
@@ -919,7 +1108,7 @@ function trySetAnimationOptions (source, target) {
|
|
|
919
1108
|
* @param {number} [options.xres=1.0] - horizontal resolution in pixels/mm
|
|
920
1109
|
* @param {number} [options.yres=1.0] - vertical resolution in pixels/mm
|
|
921
1110
|
* @param {string} [options.resolutionUnit='inch'] - resolution unit options: inch, cm
|
|
922
|
-
* @param {number} [options.bitdepth=
|
|
1111
|
+
* @param {number} [options.bitdepth=0] - reduce bitdepth to 1, 2 or 4 bit
|
|
923
1112
|
* @param {boolean} [options.miniswhite=false] - write 1-bit images as miniswhite
|
|
924
1113
|
* @returns {Sharp}
|
|
925
1114
|
* @throws {Error} Invalid options
|
|
@@ -934,10 +1123,10 @@ function tiff (options) {
|
|
|
934
1123
|
}
|
|
935
1124
|
}
|
|
936
1125
|
if (is.defined(options.bitdepth)) {
|
|
937
|
-
if (is.integer(options.bitdepth) && is.inArray(options.bitdepth, [1, 2, 4
|
|
1126
|
+
if (is.integer(options.bitdepth) && is.inArray(options.bitdepth, [1, 2, 4])) {
|
|
938
1127
|
this.options.tiffBitdepth = options.bitdepth;
|
|
939
1128
|
} else {
|
|
940
|
-
throw is.invalidParameterError('bitdepth', '1, 2
|
|
1129
|
+
throw is.invalidParameterError('bitdepth', '1, 2 or 4', options.bitdepth);
|
|
941
1130
|
}
|
|
942
1131
|
}
|
|
943
1132
|
// tiling
|
|
@@ -989,6 +1178,10 @@ function tiff (options) {
|
|
|
989
1178
|
throw is.invalidParameterError('compression', 'one of: none, jpeg, deflate, packbits, ccittfax4, lzw, webp, zstd, jp2k', options.compression);
|
|
990
1179
|
}
|
|
991
1180
|
}
|
|
1181
|
+
// bigtiff
|
|
1182
|
+
if (is.defined(options.bigtiff)) {
|
|
1183
|
+
this._setBooleanOption('tiffBigtiff', options.bigtiff);
|
|
1184
|
+
}
|
|
992
1185
|
// predictor
|
|
993
1186
|
if (is.defined(options.predictor)) {
|
|
994
1187
|
if (is.string(options.predictor) && is.inArray(options.predictor, ['none', 'horizontal', 'float'])) {
|
|
@@ -1013,7 +1206,8 @@ function tiff (options) {
|
|
|
1013
1206
|
* Use these AVIF options for output image.
|
|
1014
1207
|
*
|
|
1015
1208
|
* AVIF image sequences are not supported.
|
|
1016
|
-
*
|
|
1209
|
+
*
|
|
1210
|
+
* When using Windows ARM64, this feature requires a CPU with ARM64v8.4 or later.
|
|
1017
1211
|
*
|
|
1018
1212
|
* @example
|
|
1019
1213
|
* const data = await sharp(input)
|
|
@@ -1033,6 +1227,7 @@ function tiff (options) {
|
|
|
1033
1227
|
* @param {number} [options.effort=4] - CPU effort, between 0 (fastest) and 9 (slowest)
|
|
1034
1228
|
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
|
|
1035
1229
|
* @param {number} [options.bitdepth=8] - set bitdepth to 8, 10 or 12 bit
|
|
1230
|
+
* @param {string} [options.tune='auto'] - tune output for a quality metric, one of 'auto' (default), 'iq', 'psnr' or 'ssim'
|
|
1036
1231
|
* @returns {Sharp}
|
|
1037
1232
|
* @throws {Error} Invalid options
|
|
1038
1233
|
*/
|
|
@@ -1060,6 +1255,7 @@ function avif (options) {
|
|
|
1060
1255
|
* @param {number} [options.effort=4] - CPU effort, between 0 (fastest) and 9 (slowest)
|
|
1061
1256
|
* @param {string} [options.chromaSubsampling='4:4:4'] - set to '4:2:0' to use chroma subsampling
|
|
1062
1257
|
* @param {number} [options.bitdepth=8] - set bitdepth to 8, 10 or 12 bit
|
|
1258
|
+
* @param {string} [options.tune='auto'] - tune output for a quality metric, one of 'auto' (default), 'iq', 'psnr' or 'ssim'
|
|
1063
1259
|
* @returns {Sharp}
|
|
1064
1260
|
* @throws {Error} Invalid options
|
|
1065
1261
|
*/
|
|
@@ -1100,14 +1296,22 @@ function heif (options) {
|
|
|
1100
1296
|
}
|
|
1101
1297
|
if (is.defined(options.bitdepth)) {
|
|
1102
1298
|
if (is.integer(options.bitdepth) && is.inArray(options.bitdepth, [8, 10, 12])) {
|
|
1103
|
-
if (options.bitdepth !== 8 && this.constructor.versions.heif) {
|
|
1104
|
-
throw is.invalidParameterError('bitdepth when using prebuilt binaries', 8, options.bitdepth);
|
|
1105
|
-
}
|
|
1106
1299
|
this.options.heifBitdepth = options.bitdepth;
|
|
1107
1300
|
} else {
|
|
1108
1301
|
throw is.invalidParameterError('bitdepth', '8, 10 or 12', options.bitdepth);
|
|
1109
1302
|
}
|
|
1110
1303
|
}
|
|
1304
|
+
if (is.defined(options.tune)) {
|
|
1305
|
+
if (is.string(options.tune) && is.inArray(options.tune, ['auto', 'iq', 'psnr', 'ssim'])) {
|
|
1306
|
+
if (this.options.heifLossless && options.tune === 'iq') {
|
|
1307
|
+
this.options.heifTune = 'ssim';
|
|
1308
|
+
} else {
|
|
1309
|
+
this.options.heifTune = options.tune;
|
|
1310
|
+
}
|
|
1311
|
+
} else {
|
|
1312
|
+
throw is.invalidParameterError('tune', 'one of: auto, iq, psnr, ssim', options.tune);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1111
1315
|
} else {
|
|
1112
1316
|
throw is.invalidParameterError('options', 'Object', options);
|
|
1113
1317
|
}
|
|
@@ -1121,9 +1325,7 @@ function heif (options) {
|
|
|
1121
1325
|
*
|
|
1122
1326
|
* Requires libvips compiled with support for libjxl.
|
|
1123
1327
|
* The prebuilt binaries do not include this - see
|
|
1124
|
-
* {@link
|
|
1125
|
-
*
|
|
1126
|
-
* Image metadata (EXIF, XMP) is unsupported.
|
|
1328
|
+
* {@link /install/#custom-libvips installing a custom libvips}.
|
|
1127
1329
|
*
|
|
1128
1330
|
* @since 0.31.3
|
|
1129
1331
|
*
|
|
@@ -1132,7 +1334,9 @@ function heif (options) {
|
|
|
1132
1334
|
* @param {number} [options.quality] - calculate `distance` based on JPEG-like quality, between 1 and 100, overrides distance if specified
|
|
1133
1335
|
* @param {number} [options.decodingTier=0] - target decode speed tier, between 0 (highest quality) and 4 (lowest quality)
|
|
1134
1336
|
* @param {boolean} [options.lossless=false] - use lossless compression
|
|
1135
|
-
* @param {number} [options.effort=7] - CPU effort, between
|
|
1337
|
+
* @param {number} [options.effort=7] - CPU effort, between 1 (fastest) and 9 (slowest)
|
|
1338
|
+
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
|
|
1339
|
+
* @param {number|number[]} [options.delay] - delay(s) between animation frames (in milliseconds)
|
|
1136
1340
|
* @returns {Sharp}
|
|
1137
1341
|
* @throws {Error} Invalid options
|
|
1138
1342
|
*/
|
|
@@ -1169,13 +1373,14 @@ function jxl (options) {
|
|
|
1169
1373
|
}
|
|
1170
1374
|
}
|
|
1171
1375
|
if (is.defined(options.effort)) {
|
|
1172
|
-
if (is.integer(options.effort) && is.inRange(options.effort,
|
|
1376
|
+
if (is.integer(options.effort) && is.inRange(options.effort, 1, 9)) {
|
|
1173
1377
|
this.options.jxlEffort = options.effort;
|
|
1174
1378
|
} else {
|
|
1175
|
-
throw is.invalidParameterError('effort', 'integer between
|
|
1379
|
+
throw is.invalidParameterError('effort', 'integer between 1 and 9', options.effort);
|
|
1176
1380
|
}
|
|
1177
1381
|
}
|
|
1178
1382
|
}
|
|
1383
|
+
trySetAnimationOptions(options, this.options);
|
|
1179
1384
|
return this._updateFormatOut('jxl', options);
|
|
1180
1385
|
}
|
|
1181
1386
|
|
|
@@ -1227,10 +1432,6 @@ function raw (options) {
|
|
|
1227
1432
|
*
|
|
1228
1433
|
* The container will be set to `zip` when the output is a Buffer or Stream, otherwise it will default to `fs`.
|
|
1229
1434
|
*
|
|
1230
|
-
* Requires libvips compiled with support for libgsf.
|
|
1231
|
-
* The prebuilt binaries do not include this - see
|
|
1232
|
-
* {@link https://sharp.pixelplumbing.com/install#custom-libvips installing a custom libvips}.
|
|
1233
|
-
*
|
|
1234
1435
|
* @example
|
|
1235
1436
|
* sharp('input.tiff')
|
|
1236
1437
|
* .png()
|
|
@@ -1437,7 +1638,6 @@ function _setBooleanOption (key, val) {
|
|
|
1437
1638
|
* @private
|
|
1438
1639
|
*/
|
|
1439
1640
|
function _read () {
|
|
1440
|
-
/* istanbul ignore else */
|
|
1441
1641
|
if (!this.options.streamOut) {
|
|
1442
1642
|
this.options.streamOut = true;
|
|
1443
1643
|
const stack = Error();
|
|
@@ -1551,18 +1751,25 @@ function _pipeline (callback, stack) {
|
|
|
1551
1751
|
|
|
1552
1752
|
/**
|
|
1553
1753
|
* Decorate the Sharp prototype with output-related functions.
|
|
1754
|
+
* @module Sharp
|
|
1554
1755
|
* @private
|
|
1555
1756
|
*/
|
|
1556
|
-
module.exports =
|
|
1757
|
+
module.exports = (Sharp) => {
|
|
1557
1758
|
Object.assign(Sharp.prototype, {
|
|
1558
1759
|
// Public
|
|
1559
1760
|
toFile,
|
|
1560
1761
|
toBuffer,
|
|
1762
|
+
toUint8Array,
|
|
1763
|
+
withDensity,
|
|
1561
1764
|
keepExif,
|
|
1562
1765
|
withExif,
|
|
1563
1766
|
withExifMerge,
|
|
1564
1767
|
keepIccProfile,
|
|
1565
1768
|
withIccProfile,
|
|
1769
|
+
keepGainMap,
|
|
1770
|
+
withGainMap,
|
|
1771
|
+
keepXmp,
|
|
1772
|
+
withXmp,
|
|
1566
1773
|
keepMetadata,
|
|
1567
1774
|
withMetadata,
|
|
1568
1775
|
toFormat,
|