@revizly/sharp 0.35.0-revizly4 → 0.35.0-revizly41
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/{lib/channel.js → dist/channel.cjs} +1 -1
- package/dist/channel.mjs +177 -0
- package/{lib/colour.js → dist/colour.cjs} +11 -7
- package/dist/colour.mjs +199 -0
- package/{lib/composite.js → dist/composite.cjs} +2 -1
- package/dist/composite.mjs +213 -0
- package/{lib/constructor.js → dist/constructor.cjs} +42 -29
- package/dist/constructor.mjs +512 -0
- package/dist/index.cjs +25 -0
- package/dist/index.d.cts +2001 -0
- package/dist/index.d.mts +2048 -0
- package/dist/index.mjs +25 -0
- package/{lib/input.js → dist/input.cjs} +26 -21
- package/dist/input.mjs +814 -0
- package/{lib/is.js → dist/is.cjs} +1 -1
- package/dist/is.mjs +143 -0
- package/{lib/libvips.js → dist/libvips.cjs} +35 -30
- package/dist/libvips.mjs +212 -0
- package/{lib/operation.js → dist/operation.cjs} +33 -51
- package/dist/operation.mjs +998 -0
- package/{lib/output.js → dist/output.cjs} +161 -28
- package/dist/output.mjs +1799 -0
- package/{lib/resize.js → dist/resize.cjs} +46 -24
- package/dist/resize.mjs +617 -0
- package/dist/sharp.cjs +125 -0
- package/dist/sharp.mjs +125 -0
- package/{lib/utility.js → dist/utility.cjs} +18 -8
- package/dist/utility.mjs +301 -0
- package/install/build.js +3 -3
- package/lib/index.d.ts +105 -75
- package/package.json +46 -27
- package/src/binding.gyp +18 -13
- package/src/common.cc +70 -17
- package/src/common.h +22 -3
- package/src/metadata.cc +66 -8
- package/src/metadata.h +6 -1
- package/src/operations.cc +25 -8
- package/src/operations.h +1 -1
- package/src/pipeline.cc +206 -69
- package/src/pipeline.h +16 -1
- package/src/stats.cc +6 -6
- package/src/utilities.cc +7 -6
- package/install/check.js +0 -14
- package/lib/index.js +0 -16
- package/lib/sharp.js +0 -121
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const is = require('./is');
|
|
6
|
+
const is = require('./is.cjs');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Weighting to apply when using contain/cover fit.
|
|
@@ -386,48 +386,52 @@ function resize (widthOrOptions, height, options) {
|
|
|
386
386
|
* ...
|
|
387
387
|
*
|
|
388
388
|
* @param {(number|Object)} extend - single pixel count to add to all edges or an Object with per-edge counts
|
|
389
|
-
* @param {number} [extend.top=0]
|
|
390
|
-
* @param {number} [extend.left=0]
|
|
391
|
-
* @param {number} [extend.bottom=0]
|
|
392
|
-
* @param {number} [extend.right=0]
|
|
389
|
+
* @param {number} [extend.top=0] - number of pixels to add to the top edge, valid values are integers in the range 0-10000
|
|
390
|
+
* @param {number} [extend.left=0] - number of pixels to add to the left edge, valid values are integers in the range 0-10000
|
|
391
|
+
* @param {number} [extend.bottom=0] - number of pixels to add to the bottom edge, valid values are integers in the range 0-10000
|
|
392
|
+
* @param {number} [extend.right=0] - number of pixels to add to the right edge, valid values are integers in the range 0-10000
|
|
393
393
|
* @param {String} [extend.extendWith='background'] - populate new pixels using this method, one of: background, copy, repeat, mirror.
|
|
394
394
|
* @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.
|
|
395
395
|
* @returns {Sharp}
|
|
396
396
|
* @throws {Error} Invalid parameters
|
|
397
397
|
*/
|
|
398
398
|
function extend (extend) {
|
|
399
|
-
if (is.integer(extend)
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
399
|
+
if (is.integer(extend)) {
|
|
400
|
+
if (is.inRange(extend, 1, 10000)) {
|
|
401
|
+
this.options.extendTop = extend;
|
|
402
|
+
this.options.extendBottom = extend;
|
|
403
|
+
this.options.extendLeft = extend;
|
|
404
|
+
this.options.extendRight = extend;
|
|
405
|
+
} else {
|
|
406
|
+
throw is.invalidParameterError('extend', 'integer between 1 and 10000', extend);
|
|
407
|
+
}
|
|
404
408
|
} else if (is.object(extend)) {
|
|
405
409
|
if (is.defined(extend.top)) {
|
|
406
|
-
if (is.integer(extend.top) && extend.top
|
|
410
|
+
if (is.integer(extend.top) && is.inRange(extend.top, 0, 10000)) {
|
|
407
411
|
this.options.extendTop = extend.top;
|
|
408
412
|
} else {
|
|
409
|
-
throw is.invalidParameterError('top', '
|
|
413
|
+
throw is.invalidParameterError('top', 'integer between 0 and 10000', extend.top);
|
|
410
414
|
}
|
|
411
415
|
}
|
|
412
416
|
if (is.defined(extend.bottom)) {
|
|
413
|
-
if (is.integer(extend.bottom) && extend.bottom
|
|
417
|
+
if (is.integer(extend.bottom) && is.inRange(extend.bottom, 0, 10000)) {
|
|
414
418
|
this.options.extendBottom = extend.bottom;
|
|
415
419
|
} else {
|
|
416
|
-
throw is.invalidParameterError('bottom', '
|
|
420
|
+
throw is.invalidParameterError('bottom', 'integer between 0 and 10000', extend.bottom);
|
|
417
421
|
}
|
|
418
422
|
}
|
|
419
423
|
if (is.defined(extend.left)) {
|
|
420
|
-
if (is.integer(extend.left) && extend.left
|
|
424
|
+
if (is.integer(extend.left) && is.inRange(extend.left, 0, 10000)) {
|
|
421
425
|
this.options.extendLeft = extend.left;
|
|
422
426
|
} else {
|
|
423
|
-
throw is.invalidParameterError('left', '
|
|
427
|
+
throw is.invalidParameterError('left', 'integer between 0 and 10000', extend.left);
|
|
424
428
|
}
|
|
425
429
|
}
|
|
426
430
|
if (is.defined(extend.right)) {
|
|
427
|
-
if (is.integer(extend.right) && extend.right
|
|
431
|
+
if (is.integer(extend.right) && is.inRange(extend.right, 0, 10000)) {
|
|
428
432
|
this.options.extendRight = extend.right;
|
|
429
433
|
} else {
|
|
430
|
-
throw is.invalidParameterError('right', '
|
|
434
|
+
throw is.invalidParameterError('right', 'integer between 0 and 10000', extend.right);
|
|
431
435
|
}
|
|
432
436
|
}
|
|
433
437
|
this._setBackgroundColourOption('extendBackground', extend.background);
|
|
@@ -467,10 +471,10 @@ function extend (extend) {
|
|
|
467
471
|
* });
|
|
468
472
|
*
|
|
469
473
|
* @param {Object} options - describes the region to extract using integral pixel values
|
|
470
|
-
* @param {number} options.left - zero-indexed offset from left edge
|
|
471
|
-
* @param {number} options.top - zero-indexed offset from top edge
|
|
472
|
-
* @param {number} options.width - width of region to extract
|
|
473
|
-
* @param {number} options.height - height of region to extract
|
|
474
|
+
* @param {number} options.left - zero-indexed offset from left edge, an integer between 0 and 100000000
|
|
475
|
+
* @param {number} options.top - zero-indexed offset from top edge, an integer between 0 and 100000000
|
|
476
|
+
* @param {number} options.width - width of region to extract, an integer between 0 and 100000000
|
|
477
|
+
* @param {number} options.height - height of region to extract, an integer between 0 and 100000000
|
|
474
478
|
* @returns {Sharp}
|
|
475
479
|
* @throws {Error} Invalid parameters
|
|
476
480
|
*/
|
|
@@ -481,10 +485,10 @@ function extract (options) {
|
|
|
481
485
|
}
|
|
482
486
|
['left', 'top', 'width', 'height'].forEach(function (name) {
|
|
483
487
|
const value = options[name];
|
|
484
|
-
if (is.integer(value) && value
|
|
488
|
+
if (is.integer(value) && is.inRange(value, 0, 100000000)) {
|
|
485
489
|
this.options[name + (name === 'left' || name === 'top' ? 'Offset' : '') + suffix] = value;
|
|
486
490
|
} else {
|
|
487
|
-
throw is.invalidParameterError(name, 'integer', value);
|
|
491
|
+
throw is.invalidParameterError(name, 'integer between 0 and 100000000', value);
|
|
488
492
|
}
|
|
489
493
|
}, this);
|
|
490
494
|
// Ensure existing rotation occurs before pre-resize extraction
|
|
@@ -506,6 +510,8 @@ function extract (options) {
|
|
|
506
510
|
*
|
|
507
511
|
* If the result of this operation would trim an image to nothing then no change is made.
|
|
508
512
|
*
|
|
513
|
+
* Use the `lineArt` and `threshold` options for control over sensitivity.
|
|
514
|
+
*
|
|
509
515
|
* The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
|
510
516
|
*
|
|
511
517
|
* @example
|
|
@@ -540,10 +546,19 @@ function extract (options) {
|
|
|
540
546
|
* })
|
|
541
547
|
* .toBuffer();
|
|
542
548
|
*
|
|
549
|
+
* @example
|
|
550
|
+
* // Trim image leaving (up to) a 10 pixel margin around the trimmed content.
|
|
551
|
+
* const output = await sharp(input)
|
|
552
|
+
* .trim({
|
|
553
|
+
* margin: 10
|
|
554
|
+
* })
|
|
555
|
+
* .toBuffer();
|
|
556
|
+
*
|
|
543
557
|
* @param {Object} [options]
|
|
544
558
|
* @param {string|Object} [options.background='top-left pixel'] - Background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to that of the top-left pixel.
|
|
545
559
|
* @param {number} [options.threshold=10] - Allowed difference from the above colour, a positive number.
|
|
546
560
|
* @param {boolean} [options.lineArt=false] - Does the input more closely resemble line art (e.g. vector) rather than being photographic?
|
|
561
|
+
* @param {number} [options.margin=0] - Leave a margin around trimmed content, integral number of pixels between 0 and 10000000.
|
|
547
562
|
* @returns {Sharp}
|
|
548
563
|
* @throws {Error} Invalid parameters
|
|
549
564
|
*/
|
|
@@ -564,6 +579,13 @@ function trim (options) {
|
|
|
564
579
|
if (is.defined(options.lineArt)) {
|
|
565
580
|
this._setBooleanOption('trimLineArt', options.lineArt);
|
|
566
581
|
}
|
|
582
|
+
if (is.defined(options.margin)) {
|
|
583
|
+
if (is.integer(options.margin) && is.inRange(options.margin, 0, 10000000)) {
|
|
584
|
+
this.options.trimMargin = options.margin;
|
|
585
|
+
} else {
|
|
586
|
+
throw is.invalidParameterError('margin', 'integer between 0 and 10000000', options.margin);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
567
589
|
} else {
|
|
568
590
|
throw is.invalidParameterError('trim', 'object', options);
|
|
569
591
|
}
|