sharp 0.35.2-rc.2 → 0.35.3-rc.1

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/dist/colour.cjs CHANGED
@@ -146,12 +146,16 @@ function _getBackgroundColourOption (value) {
146
146
  (is.string(value) && value.length >= 3 && value.length <= 200)
147
147
  ) {
148
148
  const colour = color(value);
149
- return [
150
- colour.red(),
151
- colour.green(),
152
- colour.blue(),
153
- Math.round(colour.alpha() * 255)
154
- ];
149
+ const red = colour.red();
150
+ const green = colour.green();
151
+ const blue = colour.blue();
152
+ const alpha = Math.round(colour.alpha() * 255);
153
+ for (const [channel, component] of [['red', red], ['green', green], ['blue', blue], ['alpha', alpha]]) {
154
+ if (!is.number(component)) {
155
+ throw is.invalidParameterError(`background.${channel}`, 'number', component);
156
+ }
157
+ }
158
+ return [red, green, blue, alpha];
155
159
  } else {
156
160
  throw is.invalidParameterError('background', 'object or string', value);
157
161
  }
package/dist/colour.mjs CHANGED
@@ -146,12 +146,16 @@ function _getBackgroundColourOption (value) {
146
146
  (is.string(value) && value.length >= 3 && value.length <= 200)
147
147
  ) {
148
148
  const colour = color(value);
149
- return [
150
- colour.red(),
151
- colour.green(),
152
- colour.blue(),
153
- Math.round(colour.alpha() * 255)
154
- ];
149
+ const red = colour.red();
150
+ const green = colour.green();
151
+ const blue = colour.blue();
152
+ const alpha = Math.round(colour.alpha() * 255);
153
+ for (const [channel, component] of [['red', red], ['green', green], ['blue', blue], ['alpha', alpha]]) {
154
+ if (!is.number(component)) {
155
+ throw is.invalidParameterError(`background.${channel}`, 'number', component);
156
+ }
157
+ }
158
+ return [red, green, blue, alpha];
155
159
  } else {
156
160
  throw is.invalidParameterError('background', 'object or string', value);
157
161
  }
package/dist/index.d.cts CHANGED
@@ -1508,11 +1508,11 @@ declare namespace sharp {
1508
1508
  tile?: boolean | undefined;
1509
1509
  /** Horizontal tile size (optional, default 256) */
1510
1510
  tileWidth?: number | undefined;
1511
- /** Vertical tile size (optional, default 256) */
1511
+ /** Vertical tile size, valid values are integers in the range 1-32768 (optional, default 256) */
1512
1512
  tileHeight?: number | undefined;
1513
- /** Horizontal resolution in pixels/mm (optional, default 1.0) */
1513
+ /** Horizontal resolution in pixels/mm, valid values are numbers in the range 0.001-1000000 (optional, default 1.0) */
1514
1514
  xres?: number | undefined;
1515
- /** Vertical resolution in pixels/mm (optional, default 1.0) */
1515
+ /** Vertical resolution in pixels/mm, valid values are numbers in the range 0.001-1000000 (optional, default 1.0) */
1516
1516
  yres?: number | undefined;
1517
1517
  /** Reduce bitdepth to 1, 2 or 4 bit (optional) */
1518
1518
  bitdepth?: 1 | 2 | 4 | undefined;
@@ -1598,13 +1598,13 @@ declare namespace sharp {
1598
1598
  }
1599
1599
 
1600
1600
  interface Region {
1601
- /** zero-indexed offset from left edge */
1601
+ /** zero-indexed offset from left edge, an integer between 0 and 100000000 */
1602
1602
  left: number;
1603
- /** zero-indexed offset from top edge */
1603
+ /** zero-indexed offset from top edge, an integer between 0 and 100000000 */
1604
1604
  top: number;
1605
- /** dimension of extracted image */
1605
+ /** dimension of extracted image, an integer between 0 and 100000000 */
1606
1606
  width: number;
1607
- /** dimension of extracted image */
1607
+ /** dimension of extracted image, an integer between 0 and 100000000 */
1608
1608
  height: number;
1609
1609
  }
1610
1610
 
@@ -1620,13 +1620,13 @@ declare namespace sharp {
1620
1620
  type ExtendWith = 'background' | 'copy' | 'repeat' | 'mirror';
1621
1621
 
1622
1622
  interface ExtendOptions {
1623
- /** single pixel count to top edge (optional, default 0) */
1623
+ /** single pixel count to top edge, valid values are integers in the range 0-10000 (optional, default 0) */
1624
1624
  top?: number | undefined;
1625
- /** single pixel count to left edge (optional, default 0) */
1625
+ /** single pixel count to left edge, valid values are integers in the range 0-10000 (optional, default 0) */
1626
1626
  left?: number | undefined;
1627
- /** single pixel count to bottom edge (optional, default 0) */
1627
+ /** single pixel count to bottom edge, valid values are integers in the range 0-10000 (optional, default 0) */
1628
1628
  bottom?: number | undefined;
1629
- /** single pixel count to right edge (optional, default 0) */
1629
+ /** single pixel count to right edge, valid values are integers in the range 0-10000 (optional, default 0) */
1630
1630
  right?: number | undefined;
1631
1631
  /** background colour, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
1632
1632
  background?: ColorLike | undefined;
@@ -1641,7 +1641,7 @@ declare namespace sharp {
1641
1641
  threshold?: number | undefined;
1642
1642
  /** Does the input more closely resemble line art (e.g. vector) rather than being photographic? (optional, default false) */
1643
1643
  lineArt?: boolean | undefined;
1644
- /** Leave a margin around trimmed content, value is in pixels. (optional, default 0) */
1644
+ /** Leave a margin around trimmed content, integral number of pixels between 0 and 10000000. (optional, default 0) */
1645
1645
  margin?: number | undefined;
1646
1646
  }
1647
1647
 
@@ -1669,11 +1669,11 @@ declare namespace sharp {
1669
1669
  }
1670
1670
 
1671
1671
  interface ClaheOptions {
1672
- /** width of the region */
1672
+ /** width of the region. Valid values are integers in the range 1-65536. */
1673
1673
  width: number;
1674
- /** height of the region */
1674
+ /** height of the region. Valid values are integers in the range 1-65536. */
1675
1675
  height: number;
1676
- /** max slope of the cumulative contrast. A value of 0 disables contrast limiting. Valid values are integers in the range 0-100 (inclusive) (optional, default 3) */
1676
+ /** max slope of the cumulative contrast. A value of 0 disables contrast limiting. Valid values are integers in the range 0-100. (optional, default 3) */
1677
1677
  maxSlope?: number | undefined;
1678
1678
  }
1679
1679
 
@@ -1783,6 +1783,8 @@ declare namespace sharp {
1783
1783
  channels: Channels;
1784
1784
  /** indicating if premultiplication was used */
1785
1785
  premultiplied: boolean;
1786
+ /** Indicates if the output image has an alpha channel */
1787
+ hasAlpha: boolean;
1786
1788
  /** Only defined when using a crop strategy */
1787
1789
  cropOffsetLeft?: number | undefined;
1788
1790
  /** Only defined when using a crop strategy */
package/dist/index.d.mts CHANGED
@@ -1502,11 +1502,11 @@ export interface TiffOptions extends OutputOptions {
1502
1502
  tile?: boolean | undefined;
1503
1503
  /** Horizontal tile size (optional, default 256) */
1504
1504
  tileWidth?: number | undefined;
1505
- /** Vertical tile size (optional, default 256) */
1505
+ /** Vertical tile size, valid values are integers in the range 1-32768 (optional, default 256) */
1506
1506
  tileHeight?: number | undefined;
1507
- /** Horizontal resolution in pixels/mm (optional, default 1.0) */
1507
+ /** Horizontal resolution in pixels/mm, valid values are numbers in the range 0.001-1000000 (optional, default 1.0) */
1508
1508
  xres?: number | undefined;
1509
- /** Vertical resolution in pixels/mm (optional, default 1.0) */
1509
+ /** Vertical resolution in pixels/mm, valid values are numbers in the range 0.001-1000000 (optional, default 1.0) */
1510
1510
  yres?: number | undefined;
1511
1511
  /** Reduce bitdepth to 1, 2 or 4 bit (optional) */
1512
1512
  bitdepth?: 1 | 2 | 4 | undefined;
@@ -1592,13 +1592,13 @@ export interface ResizeOptions {
1592
1592
  }
1593
1593
 
1594
1594
  export interface Region {
1595
- /** zero-indexed offset from left edge */
1595
+ /** zero-indexed offset from left edge, an integer between 0 and 100000000 */
1596
1596
  left: number;
1597
- /** zero-indexed offset from top edge */
1597
+ /** zero-indexed offset from top edge, an integer between 0 and 100000000 */
1598
1598
  top: number;
1599
- /** dimension of extracted image */
1599
+ /** dimension of extracted image, an integer between 0 and 100000000 */
1600
1600
  width: number;
1601
- /** dimension of extracted image */
1601
+ /** dimension of extracted image, an integer between 0 and 100000000 */
1602
1602
  height: number;
1603
1603
  }
1604
1604
 
@@ -1614,13 +1614,13 @@ export interface Noise {
1614
1614
  export type ExtendWith = 'background' | 'copy' | 'repeat' | 'mirror';
1615
1615
 
1616
1616
  export interface ExtendOptions {
1617
- /** single pixel count to top edge (optional, default 0) */
1617
+ /** single pixel count to top edge, valid values are integers in the range 0-10000 (optional, default 0) */
1618
1618
  top?: number | undefined;
1619
- /** single pixel count to left edge (optional, default 0) */
1619
+ /** single pixel count to left edge, valid values are integers in the range 0-10000 (optional, default 0) */
1620
1620
  left?: number | undefined;
1621
- /** single pixel count to bottom edge (optional, default 0) */
1621
+ /** single pixel count to bottom edge, valid values are integers in the range 0-10000 (optional, default 0) */
1622
1622
  bottom?: number | undefined;
1623
- /** single pixel count to right edge (optional, default 0) */
1623
+ /** single pixel count to right edge, valid values are integers in the range 0-10000 (optional, default 0) */
1624
1624
  right?: number | undefined;
1625
1625
  /** background colour, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
1626
1626
  background?: ColorLike | undefined;
@@ -1635,7 +1635,7 @@ export interface TrimOptions {
1635
1635
  threshold?: number | undefined;
1636
1636
  /** Does the input more closely resemble line art (e.g. vector) rather than being photographic? (optional, default false) */
1637
1637
  lineArt?: boolean | undefined;
1638
- /** Leave a margin around trimmed content, value is in pixels. (optional, default 0) */
1638
+ /** Leave a margin around trimmed content, integral number of pixels between 0 and 10000000. (optional, default 0) */
1639
1639
  margin?: number | undefined;
1640
1640
  }
1641
1641
 
@@ -1663,11 +1663,11 @@ export interface Kernel {
1663
1663
  }
1664
1664
 
1665
1665
  export interface ClaheOptions {
1666
- /** width of the region */
1666
+ /** width of the region. Valid values are integers in the range 1-65536. */
1667
1667
  width: number;
1668
- /** height of the region */
1668
+ /** height of the region. Valid values are integers in the range 1-65536. */
1669
1669
  height: number;
1670
- /** max slope of the cumulative contrast. A value of 0 disables contrast limiting. Valid values are integers in the range 0-100 (inclusive) (optional, default 3) */
1670
+ /** max slope of the cumulative contrast. A value of 0 disables contrast limiting. Valid values are integers in the range 0-100. (optional, default 3) */
1671
1671
  maxSlope?: number | undefined;
1672
1672
  }
1673
1673
 
@@ -1777,6 +1777,8 @@ export interface OutputInfo {
1777
1777
  channels: Channels;
1778
1778
  /** indicating if premultiplication was used */
1779
1779
  premultiplied: boolean;
1780
+ /** Indicates if the output image has an alpha channel */
1781
+ hasAlpha: boolean;
1780
1782
  /** Only defined when using a crop strategy */
1781
1783
  cropOffsetLeft?: number | undefined;
1782
1784
  /** Only defined when using a crop strategy */
package/dist/input.cjs CHANGED
@@ -181,8 +181,8 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
181
181
  if (is.defined(inputOptions.raw)) {
182
182
  if (
183
183
  is.object(inputOptions.raw) &&
184
- is.integer(inputOptions.raw.width) && inputOptions.raw.width > 0 &&
185
- is.integer(inputOptions.raw.height) && inputOptions.raw.height > 0 &&
184
+ is.integer(inputOptions.raw.width) && is.inRange(inputOptions.raw.width, 1, 100000000) &&
185
+ is.integer(inputOptions.raw.height) && is.inRange(inputOptions.raw.height, 1, 100000000) &&
186
186
  is.integer(inputOptions.raw.channels) && is.inRange(inputOptions.raw.channels, 1, 4)
187
187
  ) {
188
188
  inputDescriptor.rawWidth = inputOptions.raw.width;
@@ -329,8 +329,8 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
329
329
  if (is.defined(inputOptions.create)) {
330
330
  if (
331
331
  is.object(inputOptions.create) &&
332
- is.integer(inputOptions.create.width) && inputOptions.create.width > 0 &&
333
- is.integer(inputOptions.create.height) && inputOptions.create.height > 0 &&
332
+ is.integer(inputOptions.create.width) && is.inRange(inputOptions.create.width, 1, 100000000) &&
333
+ is.integer(inputOptions.create.height) && is.inRange(inputOptions.create.height, 1, 100000000) &&
334
334
  is.integer(inputOptions.create.channels)
335
335
  ) {
336
336
  inputDescriptor.createWidth = inputOptions.create.width;
@@ -410,17 +410,17 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
410
410
  }
411
411
  }
412
412
  if (is.defined(inputOptions.text.width)) {
413
- if (is.integer(inputOptions.text.width) && inputOptions.text.width > 0) {
413
+ if (is.integer(inputOptions.text.width) && is.inRange(inputOptions.text.width, 1, 1000000)) {
414
414
  inputDescriptor.textWidth = inputOptions.text.width;
415
415
  } else {
416
- throw is.invalidParameterError('text.width', 'positive integer', inputOptions.text.width);
416
+ throw is.invalidParameterError('text.width', 'integer between 1 and 1000000', inputOptions.text.width);
417
417
  }
418
418
  }
419
419
  if (is.defined(inputOptions.text.height)) {
420
- if (is.integer(inputOptions.text.height) && inputOptions.text.height > 0) {
420
+ if (is.integer(inputOptions.text.height) && is.inRange(inputOptions.text.height, 1, 1000000)) {
421
421
  inputDescriptor.textHeight = inputOptions.text.height;
422
422
  } else {
423
- throw is.invalidParameterError('text.height', 'positive integer', inputOptions.text.height);
423
+ throw is.invalidParameterError('text.height', 'integer between 1 and 1000000', inputOptions.text.height);
424
424
  }
425
425
  }
426
426
  if (is.defined(inputOptions.text.align)) {
package/dist/input.mjs CHANGED
@@ -181,8 +181,8 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
181
181
  if (is.defined(inputOptions.raw)) {
182
182
  if (
183
183
  is.object(inputOptions.raw) &&
184
- is.integer(inputOptions.raw.width) && inputOptions.raw.width > 0 &&
185
- is.integer(inputOptions.raw.height) && inputOptions.raw.height > 0 &&
184
+ is.integer(inputOptions.raw.width) && is.inRange(inputOptions.raw.width, 1, 100000000) &&
185
+ is.integer(inputOptions.raw.height) && is.inRange(inputOptions.raw.height, 1, 100000000) &&
186
186
  is.integer(inputOptions.raw.channels) && is.inRange(inputOptions.raw.channels, 1, 4)
187
187
  ) {
188
188
  inputDescriptor.rawWidth = inputOptions.raw.width;
@@ -329,8 +329,8 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
329
329
  if (is.defined(inputOptions.create)) {
330
330
  if (
331
331
  is.object(inputOptions.create) &&
332
- is.integer(inputOptions.create.width) && inputOptions.create.width > 0 &&
333
- is.integer(inputOptions.create.height) && inputOptions.create.height > 0 &&
332
+ is.integer(inputOptions.create.width) && is.inRange(inputOptions.create.width, 1, 100000000) &&
333
+ is.integer(inputOptions.create.height) && is.inRange(inputOptions.create.height, 1, 100000000) &&
334
334
  is.integer(inputOptions.create.channels)
335
335
  ) {
336
336
  inputDescriptor.createWidth = inputOptions.create.width;
@@ -410,17 +410,17 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
410
410
  }
411
411
  }
412
412
  if (is.defined(inputOptions.text.width)) {
413
- if (is.integer(inputOptions.text.width) && inputOptions.text.width > 0) {
413
+ if (is.integer(inputOptions.text.width) && is.inRange(inputOptions.text.width, 1, 1000000)) {
414
414
  inputDescriptor.textWidth = inputOptions.text.width;
415
415
  } else {
416
- throw is.invalidParameterError('text.width', 'positive integer', inputOptions.text.width);
416
+ throw is.invalidParameterError('text.width', 'integer between 1 and 1000000', inputOptions.text.width);
417
417
  }
418
418
  }
419
419
  if (is.defined(inputOptions.text.height)) {
420
- if (is.integer(inputOptions.text.height) && inputOptions.text.height > 0) {
420
+ if (is.integer(inputOptions.text.height) && is.inRange(inputOptions.text.height, 1, 1000000)) {
421
421
  inputDescriptor.textHeight = inputOptions.text.height;
422
422
  } else {
423
- throw is.invalidParameterError('text.height', 'positive integer', inputOptions.text.height);
423
+ throw is.invalidParameterError('text.height', 'integer between 1 and 1000000', inputOptions.text.height);
424
424
  }
425
425
  }
426
426
  if (is.defined(inputOptions.text.align)) {
package/dist/is.cjs CHANGED
@@ -78,7 +78,7 @@ const string = (val) => typeof val === 'string' && val.length > 0;
78
78
  * Is this value a real number?
79
79
  * @private
80
80
  */
81
- const number = (val) => typeof val === 'number' && !Number.isNaN(val);
81
+ const number = (val) => typeof val === 'number' && Number.isFinite(val);
82
82
 
83
83
  /**
84
84
  * Is this value an integer?
package/dist/is.mjs CHANGED
@@ -78,7 +78,7 @@ const string = (val) => typeof val === 'string' && val.length > 0;
78
78
  * Is this value a real number?
79
79
  * @private
80
80
  */
81
- const number = (val) => typeof val === 'number' && !Number.isNaN(val);
81
+ const number = (val) => typeof val === 'number' && Number.isFinite(val);
82
82
 
83
83
  /**
84
84
  * Is this value an integer?
@@ -178,7 +178,13 @@ function flop (flop) {
178
178
  * @throws {Error} Invalid parameters
179
179
  */
180
180
  function affine (matrix, options) {
181
- const flatMatrix = Array.isArray(matrix) ? [].concat(...matrix) : [];
181
+ const isValidShape = Array.isArray(matrix) && (
182
+ // 1x4 array of numbers
183
+ (matrix.length === 4 && matrix.every(is.number)) ||
184
+ // 2x2 array of arrays of numbers
185
+ (matrix.length === 2 && matrix.every((row) => Array.isArray(row) && row.length === 2))
186
+ );
187
+ const flatMatrix = isValidShape ? matrix.flat() : [];
182
188
  if (flatMatrix.length === 4 && flatMatrix.every(is.number)) {
183
189
  this.options.affineMatrix = flatMatrix;
184
190
  } else {
@@ -646,23 +652,23 @@ function normalize (options) {
646
652
  * .toBuffer();
647
653
  *
648
654
  * @param {Object} options
649
- * @param {number} options.width - Integral width of the search window, in pixels.
650
- * @param {number} options.height - Integral height of the search window, in pixels.
655
+ * @param {number} options.width - Integral width of the search window, in pixels, between 1 and 65536.
656
+ * @param {number} options.height - Integral height of the search window, in pixels, between 1 and 65536.
651
657
  * @param {number} [options.maxSlope=3] - Integral level of brightening, between 0 and 100, where 0 disables contrast limiting.
652
658
  * @returns {Sharp}
653
659
  * @throws {Error} Invalid parameters
654
660
  */
655
661
  function clahe (options) {
656
662
  if (is.plainObject(options)) {
657
- if (is.integer(options.width) && options.width > 0) {
663
+ if (is.integer(options.width) && is.inRange(options.width, 1, 65536)) {
658
664
  this.options.claheWidth = options.width;
659
665
  } else {
660
- throw is.invalidParameterError('width', 'integer greater than zero', options.width);
666
+ throw is.invalidParameterError('width', 'integer between 1 and 65536', options.width);
661
667
  }
662
- if (is.integer(options.height) && options.height > 0) {
668
+ if (is.integer(options.height) && is.inRange(options.height, 1, 65536)) {
663
669
  this.options.claheHeight = options.height;
664
670
  } else {
665
- throw is.invalidParameterError('height', 'integer greater than zero', options.height);
671
+ throw is.invalidParameterError('height', 'integer between 1 and 65536', options.height);
666
672
  }
667
673
  if (is.defined(options.maxSlope)) {
668
674
  if (is.integer(options.maxSlope) && is.inRange(options.maxSlope, 0, 100)) {
@@ -706,7 +712,8 @@ function convolve (kernel) {
706
712
  if (!is.object(kernel) || !Array.isArray(kernel.kernel) ||
707
713
  !is.integer(kernel.width) || !is.integer(kernel.height) ||
708
714
  !is.inRange(kernel.width, 3, 1001) || !is.inRange(kernel.height, 3, 1001) ||
709
- kernel.height * kernel.width !== kernel.kernel.length
715
+ kernel.height * kernel.width !== kernel.kernel.length ||
716
+ !kernel.kernel.every(is.number)
710
717
  ) {
711
718
  // must pass in a kernel
712
719
  throw new Error('Invalid convolution kernel');
@@ -859,13 +866,14 @@ function recomb (inputMatrix) {
859
866
  if (!Array.isArray(inputMatrix)) {
860
867
  throw is.invalidParameterError('inputMatrix', 'array', inputMatrix);
861
868
  }
862
- if (inputMatrix.length !== 3 && inputMatrix.length !== 4) {
863
- throw is.invalidParameterError('inputMatrix', '3x3 or 4x4 array', inputMatrix.length);
869
+ const dimensions = inputMatrix.length;
870
+ if (dimensions !== 3 && dimensions !== 4) {
871
+ throw is.invalidParameterError('inputMatrix', '3x3 or 4x4 array', dimensions);
864
872
  }
865
- const recombMatrix = inputMatrix.flat();
866
- if (recombMatrix.length !== 9 && recombMatrix.length !== 16) {
867
- throw is.invalidParameterError('inputMatrix', 'cardinality of 9 or 16', recombMatrix.length);
873
+ if (!inputMatrix.every((row) => Array.isArray(row) && row.length === dimensions)) {
874
+ throw is.invalidParameterError('inputMatrix', `array of ${dimensions} arrays of length ${dimensions}`, inputMatrix);
868
875
  }
876
+ const recombMatrix = inputMatrix.flat();
869
877
  if (!recombMatrix.every(is.number)) {
870
878
  throw is.invalidParameterError('inputMatrix', 'array of numbers', recombMatrix);
871
879
  }
@@ -178,7 +178,13 @@ function flop (flop) {
178
178
  * @throws {Error} Invalid parameters
179
179
  */
180
180
  function affine (matrix, options) {
181
- const flatMatrix = Array.isArray(matrix) ? [].concat(...matrix) : [];
181
+ const isValidShape = Array.isArray(matrix) && (
182
+ // 1x4 array of numbers
183
+ (matrix.length === 4 && matrix.every(is.number)) ||
184
+ // 2x2 array of arrays of numbers
185
+ (matrix.length === 2 && matrix.every((row) => Array.isArray(row) && row.length === 2))
186
+ );
187
+ const flatMatrix = isValidShape ? matrix.flat() : [];
182
188
  if (flatMatrix.length === 4 && flatMatrix.every(is.number)) {
183
189
  this.options.affineMatrix = flatMatrix;
184
190
  } else {
@@ -646,23 +652,23 @@ function normalize (options) {
646
652
  * .toBuffer();
647
653
  *
648
654
  * @param {Object} options
649
- * @param {number} options.width - Integral width of the search window, in pixels.
650
- * @param {number} options.height - Integral height of the search window, in pixels.
655
+ * @param {number} options.width - Integral width of the search window, in pixels, between 1 and 65536.
656
+ * @param {number} options.height - Integral height of the search window, in pixels, between 1 and 65536.
651
657
  * @param {number} [options.maxSlope=3] - Integral level of brightening, between 0 and 100, where 0 disables contrast limiting.
652
658
  * @returns {Sharp}
653
659
  * @throws {Error} Invalid parameters
654
660
  */
655
661
  function clahe (options) {
656
662
  if (is.plainObject(options)) {
657
- if (is.integer(options.width) && options.width > 0) {
663
+ if (is.integer(options.width) && is.inRange(options.width, 1, 65536)) {
658
664
  this.options.claheWidth = options.width;
659
665
  } else {
660
- throw is.invalidParameterError('width', 'integer greater than zero', options.width);
666
+ throw is.invalidParameterError('width', 'integer between 1 and 65536', options.width);
661
667
  }
662
- if (is.integer(options.height) && options.height > 0) {
668
+ if (is.integer(options.height) && is.inRange(options.height, 1, 65536)) {
663
669
  this.options.claheHeight = options.height;
664
670
  } else {
665
- throw is.invalidParameterError('height', 'integer greater than zero', options.height);
671
+ throw is.invalidParameterError('height', 'integer between 1 and 65536', options.height);
666
672
  }
667
673
  if (is.defined(options.maxSlope)) {
668
674
  if (is.integer(options.maxSlope) && is.inRange(options.maxSlope, 0, 100)) {
@@ -706,7 +712,8 @@ function convolve (kernel) {
706
712
  if (!is.object(kernel) || !Array.isArray(kernel.kernel) ||
707
713
  !is.integer(kernel.width) || !is.integer(kernel.height) ||
708
714
  !is.inRange(kernel.width, 3, 1001) || !is.inRange(kernel.height, 3, 1001) ||
709
- kernel.height * kernel.width !== kernel.kernel.length
715
+ kernel.height * kernel.width !== kernel.kernel.length ||
716
+ !kernel.kernel.every(is.number)
710
717
  ) {
711
718
  // must pass in a kernel
712
719
  throw new Error('Invalid convolution kernel');
@@ -859,13 +866,14 @@ function recomb (inputMatrix) {
859
866
  if (!Array.isArray(inputMatrix)) {
860
867
  throw is.invalidParameterError('inputMatrix', 'array', inputMatrix);
861
868
  }
862
- if (inputMatrix.length !== 3 && inputMatrix.length !== 4) {
863
- throw is.invalidParameterError('inputMatrix', '3x3 or 4x4 array', inputMatrix.length);
869
+ const dimensions = inputMatrix.length;
870
+ if (dimensions !== 3 && dimensions !== 4) {
871
+ throw is.invalidParameterError('inputMatrix', '3x3 or 4x4 array', dimensions);
864
872
  }
865
- const recombMatrix = inputMatrix.flat();
866
- if (recombMatrix.length !== 9 && recombMatrix.length !== 16) {
867
- throw is.invalidParameterError('inputMatrix', 'cardinality of 9 or 16', recombMatrix.length);
873
+ if (!inputMatrix.every((row) => Array.isArray(row) && row.length === dimensions)) {
874
+ throw is.invalidParameterError('inputMatrix', `array of ${dimensions} arrays of length ${dimensions}`, inputMatrix);
868
875
  }
876
+ const recombMatrix = inputMatrix.flat();
869
877
  if (!recombMatrix.every(is.number)) {
870
878
  throw is.invalidParameterError('inputMatrix', 'array of numbers', recombMatrix);
871
879
  }
package/dist/output.cjs CHANGED
@@ -1103,10 +1103,10 @@ function trySetAnimationOptions (source, target) {
1103
1103
  * @param {string} [options.predictor='horizontal'] - compression predictor options: none, horizontal, float
1104
1104
  * @param {boolean} [options.pyramid=false] - write an image pyramid
1105
1105
  * @param {boolean} [options.tile=false] - write a tiled tiff
1106
- * @param {number} [options.tileWidth=256] - horizontal tile size
1107
- * @param {number} [options.tileHeight=256] - vertical tile size
1108
- * @param {number} [options.xres=1.0] - horizontal resolution in pixels/mm
1109
- * @param {number} [options.yres=1.0] - vertical resolution in pixels/mm
1106
+ * @param {number} [options.tileWidth=256] - horizontal tile size, valid values are integers in the range 1-32768
1107
+ * @param {number} [options.tileHeight=256] - vertical tile size, valid values are integers in the range 1-32768
1108
+ * @param {number} [options.xres=1.0] - horizontal resolution in pixels/mm, valid values are numbers in the range 0.001-1000000
1109
+ * @param {number} [options.yres=1.0] - vertical resolution in pixels/mm, valid values are numbers in the range 0.001-1000000
1110
1110
  * @param {string} [options.resolutionUnit='inch'] - resolution unit options: inch, cm
1111
1111
  * @param {number} [options.bitdepth=0] - reduce bitdepth to 1, 2 or 4 bit
1112
1112
  * @param {boolean} [options.miniswhite=false] - write 1-bit images as miniswhite
@@ -1134,17 +1134,17 @@ function tiff (options) {
1134
1134
  this._setBooleanOption('tiffTile', options.tile);
1135
1135
  }
1136
1136
  if (is.defined(options.tileWidth)) {
1137
- if (is.integer(options.tileWidth) && options.tileWidth > 0) {
1137
+ if (is.integer(options.tileWidth) && is.inRange(options.tileWidth, 1, 32768)) {
1138
1138
  this.options.tiffTileWidth = options.tileWidth;
1139
1139
  } else {
1140
- throw is.invalidParameterError('tileWidth', 'integer greater than zero', options.tileWidth);
1140
+ throw is.invalidParameterError('tileWidth', 'integer between 1 and 32768', options.tileWidth);
1141
1141
  }
1142
1142
  }
1143
1143
  if (is.defined(options.tileHeight)) {
1144
- if (is.integer(options.tileHeight) && options.tileHeight > 0) {
1144
+ if (is.integer(options.tileHeight) && is.inRange(options.tileHeight, 1, 32768)) {
1145
1145
  this.options.tiffTileHeight = options.tileHeight;
1146
1146
  } else {
1147
- throw is.invalidParameterError('tileHeight', 'integer greater than zero', options.tileHeight);
1147
+ throw is.invalidParameterError('tileHeight', 'integer between 1 and 32768', options.tileHeight);
1148
1148
  }
1149
1149
  }
1150
1150
  // miniswhite
@@ -1157,17 +1157,17 @@ function tiff (options) {
1157
1157
  }
1158
1158
  // resolution
1159
1159
  if (is.defined(options.xres)) {
1160
- if (is.number(options.xres) && options.xres > 0) {
1160
+ if (is.number(options.xres) && is.inRange(options.xres, 0.001, 1000000)) {
1161
1161
  this.options.tiffXres = options.xres;
1162
1162
  } else {
1163
- throw is.invalidParameterError('xres', 'number greater than zero', options.xres);
1163
+ throw is.invalidParameterError('xres', 'number between 0.001 and 1000000', options.xres);
1164
1164
  }
1165
1165
  }
1166
1166
  if (is.defined(options.yres)) {
1167
- if (is.number(options.yres) && options.yres > 0) {
1167
+ if (is.number(options.yres) && is.inRange(options.yres, 0.001, 1000000)) {
1168
1168
  this.options.tiffYres = options.yres;
1169
1169
  } else {
1170
- throw is.invalidParameterError('yres', 'number greater than zero', options.yres);
1170
+ throw is.invalidParameterError('yres', 'number between 0.001 and 1000000', options.yres);
1171
1171
  }
1172
1172
  }
1173
1173
  // compression
package/dist/output.mjs CHANGED
@@ -1103,10 +1103,10 @@ function trySetAnimationOptions (source, target) {
1103
1103
  * @param {string} [options.predictor='horizontal'] - compression predictor options: none, horizontal, float
1104
1104
  * @param {boolean} [options.pyramid=false] - write an image pyramid
1105
1105
  * @param {boolean} [options.tile=false] - write a tiled tiff
1106
- * @param {number} [options.tileWidth=256] - horizontal tile size
1107
- * @param {number} [options.tileHeight=256] - vertical tile size
1108
- * @param {number} [options.xres=1.0] - horizontal resolution in pixels/mm
1109
- * @param {number} [options.yres=1.0] - vertical resolution in pixels/mm
1106
+ * @param {number} [options.tileWidth=256] - horizontal tile size, valid values are integers in the range 1-32768
1107
+ * @param {number} [options.tileHeight=256] - vertical tile size, valid values are integers in the range 1-32768
1108
+ * @param {number} [options.xres=1.0] - horizontal resolution in pixels/mm, valid values are numbers in the range 0.001-1000000
1109
+ * @param {number} [options.yres=1.0] - vertical resolution in pixels/mm, valid values are numbers in the range 0.001-1000000
1110
1110
  * @param {string} [options.resolutionUnit='inch'] - resolution unit options: inch, cm
1111
1111
  * @param {number} [options.bitdepth=0] - reduce bitdepth to 1, 2 or 4 bit
1112
1112
  * @param {boolean} [options.miniswhite=false] - write 1-bit images as miniswhite
@@ -1134,17 +1134,17 @@ function tiff (options) {
1134
1134
  this._setBooleanOption('tiffTile', options.tile);
1135
1135
  }
1136
1136
  if (is.defined(options.tileWidth)) {
1137
- if (is.integer(options.tileWidth) && options.tileWidth > 0) {
1137
+ if (is.integer(options.tileWidth) && is.inRange(options.tileWidth, 1, 32768)) {
1138
1138
  this.options.tiffTileWidth = options.tileWidth;
1139
1139
  } else {
1140
- throw is.invalidParameterError('tileWidth', 'integer greater than zero', options.tileWidth);
1140
+ throw is.invalidParameterError('tileWidth', 'integer between 1 and 32768', options.tileWidth);
1141
1141
  }
1142
1142
  }
1143
1143
  if (is.defined(options.tileHeight)) {
1144
- if (is.integer(options.tileHeight) && options.tileHeight > 0) {
1144
+ if (is.integer(options.tileHeight) && is.inRange(options.tileHeight, 1, 32768)) {
1145
1145
  this.options.tiffTileHeight = options.tileHeight;
1146
1146
  } else {
1147
- throw is.invalidParameterError('tileHeight', 'integer greater than zero', options.tileHeight);
1147
+ throw is.invalidParameterError('tileHeight', 'integer between 1 and 32768', options.tileHeight);
1148
1148
  }
1149
1149
  }
1150
1150
  // miniswhite
@@ -1157,17 +1157,17 @@ function tiff (options) {
1157
1157
  }
1158
1158
  // resolution
1159
1159
  if (is.defined(options.xres)) {
1160
- if (is.number(options.xres) && options.xres > 0) {
1160
+ if (is.number(options.xres) && is.inRange(options.xres, 0.001, 1000000)) {
1161
1161
  this.options.tiffXres = options.xres;
1162
1162
  } else {
1163
- throw is.invalidParameterError('xres', 'number greater than zero', options.xres);
1163
+ throw is.invalidParameterError('xres', 'number between 0.001 and 1000000', options.xres);
1164
1164
  }
1165
1165
  }
1166
1166
  if (is.defined(options.yres)) {
1167
- if (is.number(options.yres) && options.yres > 0) {
1167
+ if (is.number(options.yres) && is.inRange(options.yres, 0.001, 1000000)) {
1168
1168
  this.options.tiffYres = options.yres;
1169
1169
  } else {
1170
- throw is.invalidParameterError('yres', 'number greater than zero', options.yres);
1170
+ throw is.invalidParameterError('yres', 'number between 0.001 and 1000000', options.yres);
1171
1171
  }
1172
1172
  }
1173
1173
  // compression