@revizly/sharp 0.34.1-revizly9 → 0.34.4-revizly3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # sharp
2
2
 
3
- <img src="https://cdn.jsdelivr.net/gh/lovell/sharp@main/docs/public/sharp-logo.svg" width="160" height="160" alt="sharp logo" align="right">
3
+ <img src="https://sharp.pixelplumbing.com/sharp-logo.svg" width="160" height="160" alt="sharp logo" align="right">
4
4
 
5
5
  The typical use case for this high speed Node-API module
6
6
  is to convert large images in common formats to
package/lib/channel.js CHANGED
@@ -74,6 +74,8 @@ function ensureAlpha (alpha) {
74
74
  /**
75
75
  * Extract a single channel from a multi-channel image.
76
76
  *
77
+ * The output colourspace will be either `b-w` (8-bit) or `grey16` (16-bit).
78
+ *
77
79
  * @example
78
80
  * // green.jpg is a greyscale image containing the green channel of the input
79
81
  * await sharp(input)
@@ -153,9 +153,6 @@ const debuglog = util.debuglog('sharp');
153
153
  * @param {number} [options.ignoreIcc=false] - should the embedded ICC profile, if any, be ignored.
154
154
  * @param {number} [options.pages=1] - Number of pages to extract for multi-page input (GIF, WebP, TIFF), use -1 for all pages.
155
155
  * @param {number} [options.page=0] - Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based.
156
- * @param {number} [options.subifd=-1] - subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image.
157
- * @param {number} [options.level=0] - level to extract from a multi-level input (OpenSlide), zero based.
158
- * @param {string|Object} [options.pdfBackground] - Background colour to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick.
159
156
  * @param {boolean} [options.animated=false] - Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`.
160
157
  * @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
161
158
  * @param {number} [options.raw.width] - integral number of pixels wide.
@@ -163,15 +160,17 @@ const debuglog = util.debuglog('sharp');
163
160
  * @param {number} [options.raw.channels] - integral number of channels, between 1 and 4.
164
161
  * @param {boolean} [options.raw.premultiplied] - specifies that the raw input has already been premultiplied, set to `true`
165
162
  * to avoid sharp premultiplying the image. (optional, default `false`)
163
+ * @param {number} [options.raw.pageHeight] - The pixel height of each page/frame for animated images, must be an integral factor of `raw.height`.
166
164
  * @param {Object} [options.create] - describes a new image to be created.
167
165
  * @param {number} [options.create.width] - integral number of pixels wide.
168
166
  * @param {number} [options.create.height] - integral number of pixels high.
169
167
  * @param {number} [options.create.channels] - integral number of channels, either 3 (RGB) or 4 (RGBA).
170
168
  * @param {string|Object} [options.create.background] - parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
169
+ * @param {number} [options.create.pageHeight] - The pixel height of each page/frame for animated images, must be an integral factor of `create.height`.
171
170
  * @param {Object} [options.create.noise] - describes a noise to be created.
172
171
  * @param {string} [options.create.noise.type] - type of generated noise, currently only `gaussian` is supported.
173
- * @param {number} [options.create.noise.mean] - mean of pixels in generated noise.
174
- * @param {number} [options.create.noise.sigma] - standard deviation of pixels in generated noise.
172
+ * @param {number} [options.create.noise.mean=128] - Mean value of pixels in the generated noise.
173
+ * @param {number} [options.create.noise.sigma=30] - Standard deviation of pixel values in the generated noise.
175
174
  * @param {Object} [options.text] - describes a new text image to be created.
176
175
  * @param {string} [options.text.text] - text to render as a UTF-8 string. It can contain Pango markup, for example `<i>Le</i>Monde`.
177
176
  * @param {string} [options.text.font] - font name to render with.
@@ -191,7 +190,17 @@ const debuglog = util.debuglog('sharp');
191
190
  * @param {string|Object} [options.join.background] - parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
192
191
  * @param {string} [options.join.halign='left'] - horizontal alignment style for images joined horizontally (`'left'`, `'centre'`, `'center'`, `'right'`).
193
192
  * @param {string} [options.join.valign='top'] - vertical alignment style for images joined vertically (`'top'`, `'centre'`, `'center'`, `'bottom'`).
194
- *
193
+ * @param {Object} [options.tiff] - Describes TIFF specific options.
194
+ * @param {number} [options.tiff.subifd=-1] - Sub Image File Directory to extract for OME-TIFF, defaults to main image.
195
+ * @param {Object} [options.svg] - Describes SVG specific options.
196
+ * @param {string} [options.svg.stylesheet] - Custom CSS for SVG input, applied with a User Origin during the CSS cascade.
197
+ * @param {boolean} [options.svg.highBitdepth=false] - Set to `true` to render SVG input at 32-bits per channel (128-bit) instead of 8-bits per channel (32-bit) RGBA.
198
+ * @param {Object} [options.pdf] - Describes PDF specific options. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick.
199
+ * @param {string|Object} [options.pdf.background] - Background colour to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
200
+ * @param {Object} [options.openSlide] - Describes OpenSlide specific options. Requires the use of a globally-installed libvips compiled with support for OpenSlide.
201
+ * @param {number} [options.openSlide.level=0] - Level to extract from a multi-level input, zero based.
202
+ * @param {Object} [options.jp2] - Describes JPEG 2000 specific options. Requires the use of a globally-installed libvips compiled with support for OpenJPEG.
203
+ * @param {boolean} [options.jp2.oneshot=false] - Set to `true` to decode tiled JPEG 2000 images in a single operation, improving compatibility.
195
204
  * @returns {Sharp}
196
205
  * @throws {Error} Invalid parameters
197
206
  */
@@ -221,7 +230,8 @@ const Sharp = function (input, options) {
221
230
  angle: 0,
222
231
  rotationAngle: 0,
223
232
  rotationBackground: [0, 0, 0, 255],
224
- rotateBeforePreExtract: false,
233
+ rotateBefore: false,
234
+ orientBefore: false,
225
235
  flip: false,
226
236
  flop: false,
227
237
  extendTop: 0,
@@ -297,6 +307,7 @@ const Sharp = function (input, options) {
297
307
  withIccProfile: '',
298
308
  withExif: {},
299
309
  withExifMerge: true,
310
+ withXmp: '',
300
311
  resolveWithObject: false,
301
312
  loop: -1,
302
313
  delay: [],
@@ -337,6 +348,7 @@ const Sharp = function (input, options) {
337
348
  gifDither: 1,
338
349
  gifInterFrameMaxError: 0,
339
350
  gifInterPaletteMaxError: 3,
351
+ gifKeepDuplicateFrames: false,
340
352
  gifReuse: true,
341
353
  gifProgressive: false,
342
354
  tiffQuality: 80,
package/lib/index.d.ts CHANGED
@@ -419,7 +419,7 @@ declare namespace sharp {
419
419
  * @returns {Sharp}
420
420
  */
421
421
  autoOrient(): Sharp
422
-
422
+
423
423
  /**
424
424
  * Flip the image about the vertical Y axis. This always occurs after rotation, if any.
425
425
  * The use of flip implies the removal of the EXIF Orientation tag, if any.
@@ -730,6 +730,20 @@ declare namespace sharp {
730
730
  */
731
731
  withIccProfile(icc: string, options?: WithIccProfileOptions): Sharp;
732
732
 
733
+ /**
734
+ * Keep all XMP metadata from the input image in the output image.
735
+ * @returns A sharp instance that can be used to chain operations
736
+ */
737
+ keepXmp(): Sharp;
738
+
739
+ /**
740
+ * Set XMP metadata in the output image.
741
+ * @param {string} xmp - String containing XMP metadata to be embedded in the output image.
742
+ * @returns A sharp instance that can be used to chain operations
743
+ * @throws {Error} Invalid parameters
744
+ */
745
+ withXmp(xmp: string): Sharp;
746
+
733
747
  /**
734
748
  * Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
735
749
  * The default behaviour, when withMetadata is not used, is to strip all metadata and convert to the device-independent sRGB colour space.
@@ -1003,12 +1017,22 @@ declare namespace sharp {
1003
1017
  pages?: number | undefined;
1004
1018
  /** Page number to start extracting from for multi-page input (GIF, TIFF, PDF), zero based. (optional, default 0) */
1005
1019
  page?: number | undefined;
1006
- /** subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image. (optional, default -1) */
1020
+ /** TIFF specific input options */
1021
+ tiff?: TiffInputOptions | undefined;
1022
+ /** SVG specific input options */
1023
+ svg?: SvgInputOptions | undefined;
1024
+ /** PDF specific input options */
1025
+ pdf?: PdfInputOptions | undefined;
1026
+ /** OpenSlide specific input options */
1027
+ openSlide?: OpenSlideInputOptions | undefined;
1028
+ /** JPEG 2000 specific input options */
1029
+ jp2?: Jp2InputOptions | undefined;
1030
+ /** Deprecated: use tiff.subifd instead */
1007
1031
  subifd?: number | undefined;
1008
- /** Level to extract from a multi-level input (OpenSlide), zero based. (optional, default 0) */
1009
- level?: number | undefined;
1010
- /** Background colour to use when PDF is partially transparent. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick. */
1032
+ /** Deprecated: use pdf.background instead */
1011
1033
  pdfBackground?: Colour | Color | undefined;
1034
+ /** Deprecated: use openSlide.level instead */
1035
+ level?: number | undefined;
1012
1036
  /** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default false) */
1013
1037
  animated?: boolean | undefined;
1014
1038
  /** Describes raw pixel input image data. See raw() for pixel ordering. */
@@ -1051,6 +1075,8 @@ declare namespace sharp {
1051
1075
  interface CreateRaw extends Raw {
1052
1076
  /** Specifies that the raw input has already been premultiplied, set to true to avoid sharp premultiplying the image. (optional, default false) */
1053
1077
  premultiplied?: boolean | undefined;
1078
+ /** The height of each page/frame for animated images, must be an integral factor of the overall image height. */
1079
+ pageHeight?: number | undefined;
1054
1080
  }
1055
1081
 
1056
1082
  type CreateChannels = 3 | 4;
@@ -1066,6 +1092,9 @@ declare namespace sharp {
1066
1092
  background: Colour | Color;
1067
1093
  /** Describes a noise to be created. */
1068
1094
  noise?: Noise | undefined;
1095
+ /** The height of each page/frame for animated images, must be an integral factor of the overall image height. */
1096
+ pageHeight?: number | undefined;
1097
+
1069
1098
  }
1070
1099
 
1071
1100
  interface CreateText {
@@ -1114,6 +1143,33 @@ declare namespace sharp {
1114
1143
  valign?: VerticalAlignment | undefined;
1115
1144
  }
1116
1145
 
1146
+ interface TiffInputOptions {
1147
+ /** Sub Image File Directory to extract, defaults to main image. Use -1 for all subifds. */
1148
+ subifd?: number | undefined;
1149
+ }
1150
+
1151
+ interface SvgInputOptions {
1152
+ /** Custom CSS for SVG input, applied with a User Origin during the CSS cascade. */
1153
+ stylesheet?: string | undefined;
1154
+ /** Set to `true` to render SVG input at 32-bits per channel (128-bit) instead of 8-bits per channel (32-bit) RGBA. */
1155
+ highBitdepth?: boolean | undefined;
1156
+ }
1157
+
1158
+ interface PdfInputOptions {
1159
+ /** Background colour to use when PDF is partially transparent. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick. */
1160
+ background?: Colour | Color | undefined;
1161
+ }
1162
+
1163
+ interface OpenSlideInputOptions {
1164
+ /** Level to extract from a multi-level input, zero based. (optional, default 0) */
1165
+ level?: number | undefined;
1166
+ }
1167
+
1168
+ interface Jp2InputOptions {
1169
+ /** Set to `true` to load JPEG 2000 images using [oneshot mode](https://github.com/libvips/libvips/issues/4205) */
1170
+ oneshot?: boolean | undefined;
1171
+ }
1172
+
1117
1173
  interface ExifDir {
1118
1174
  [k: string]: string;
1119
1175
  }
@@ -1146,13 +1202,13 @@ declare namespace sharp {
1146
1202
  /** Number value of the EXIF Orientation header, if present */
1147
1203
  orientation?: number | undefined;
1148
1204
  /** Name of decoder used to decompress image data e.g. jpeg, png, webp, gif, svg */
1149
- format?: keyof FormatEnum | undefined;
1205
+ format: keyof FormatEnum;
1150
1206
  /** Total size of image in bytes, for Stream and Buffer input only */
1151
1207
  size?: number | undefined;
1152
1208
  /** Number of pixels wide (EXIF orientation is not taken into consideration) */
1153
- width?: number | undefined;
1209
+ width: number;
1154
1210
  /** Number of pixels high (EXIF orientation is not taken into consideration) */
1155
- height?: number | undefined;
1211
+ height: number;
1156
1212
  /** Any changed metadata after the image orientation is applied. */
1157
1213
  autoOrient: {
1158
1214
  /** Number of pixels wide (EXIF orientation is taken into consideration) */
@@ -1161,19 +1217,19 @@ declare namespace sharp {
1161
1217
  height: number;
1162
1218
  };
1163
1219
  /** Name of colour space interpretation */
1164
- space?: keyof ColourspaceEnum | undefined;
1220
+ space: keyof ColourspaceEnum;
1165
1221
  /** Number of bands e.g. 3 for sRGB, 4 for CMYK */
1166
- channels?: Channels | undefined;
1222
+ channels: Channels;
1167
1223
  /** Name of pixel depth format e.g. uchar, char, ushort, float ... */
1168
- depth?: string | undefined;
1224
+ depth: keyof DepthEnum;
1169
1225
  /** Number of pixels per inch (DPI), if present */
1170
1226
  density?: number | undefined;
1171
1227
  /** String containing JPEG chroma subsampling, 4:2:0 or 4:4:4 for RGB, 4:2:0:4 or 4:4:4:4 for CMYK */
1172
1228
  chromaSubsampling?: string | undefined;
1173
1229
  /** Boolean indicating whether the image is interlaced using a progressive scan */
1174
- isProgressive?: boolean | undefined;
1230
+ isProgressive: boolean;
1175
1231
  /** Boolean indicating whether the image is palette-based (GIF, PNG). */
1176
- isPalette?: boolean | undefined;
1232
+ isPalette: boolean;
1177
1233
  /** Number of bits per sample for each channel (GIF, PNG). */
1178
1234
  bitsPerSample?: number | undefined;
1179
1235
  /** Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP */
@@ -1187,9 +1243,9 @@ declare namespace sharp {
1187
1243
  /** Number of the primary page in a HEIF image */
1188
1244
  pagePrimary?: number | undefined;
1189
1245
  /** Boolean indicating the presence of an embedded ICC profile */
1190
- hasProfile?: boolean | undefined;
1246
+ hasProfile: boolean;
1191
1247
  /** Boolean indicating the presence of an alpha transparency channel */
1192
- hasAlpha?: boolean | undefined;
1248
+ hasAlpha: boolean;
1193
1249
  /** Buffer containing raw EXIF data, if present */
1194
1250
  exif?: Buffer | undefined;
1195
1251
  /** Buffer containing raw ICC profile data, if present */
@@ -1198,6 +1254,8 @@ declare namespace sharp {
1198
1254
  iptc?: Buffer | undefined;
1199
1255
  /** Buffer containing raw XMP data, if present */
1200
1256
  xmp?: Buffer | undefined;
1257
+ /** String containing XMP data, if valid UTF-8 */
1258
+ xmpAsString?: string | undefined;
1201
1259
  /** Buffer containing raw TIFFTAG_PHOTOSHOP data, if present */
1202
1260
  tifftagPhotoshop?: Buffer | undefined;
1203
1261
  /** The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC) */
@@ -1336,6 +1394,8 @@ declare namespace sharp {
1336
1394
  nearLossless?: boolean | undefined;
1337
1395
  /** Use high quality chroma subsampling (optional, default false) */
1338
1396
  smartSubsample?: boolean | undefined;
1397
+ /** Auto-adjust the deblocking filter, slow but can improve low contrast edges (optional, default false) */
1398
+ smartDeblock?: boolean | undefined;
1339
1399
  /** Level of CPU effort to reduce file size, integer 0-6 (optional, default 4) */
1340
1400
  effort?: number | undefined;
1341
1401
  /** Prevent use of animation key frames to minimise file size (slow) (optional, default false) */
@@ -1388,9 +1448,11 @@ declare namespace sharp {
1388
1448
  /** Level of Floyd-Steinberg error diffusion, between 0 (least) and 1 (most) (optional, default 1.0) */
1389
1449
  dither?: number | undefined;
1390
1450
  /** Maximum inter-frame error for transparency, between 0 (lossless) and 32 (optional, default 0) */
1391
- interFrameMaxError?: number;
1451
+ interFrameMaxError?: number | undefined;
1392
1452
  /** Maximum inter-palette error for palette reuse, between 0 and 256 (optional, default 3) */
1393
- interPaletteMaxError?: number;
1453
+ interPaletteMaxError?: number | undefined;
1454
+ /** Keep duplicate frames in the output instead of combining them (optional, default false) */
1455
+ keepDuplicateFrames?: boolean | undefined;
1394
1456
  }
1395
1457
 
1396
1458
  interface TiffOptions extends OutputOptions {
@@ -1508,7 +1570,7 @@ declare namespace sharp {
1508
1570
 
1509
1571
  interface Noise {
1510
1572
  /** type of generated noise, currently only gaussian is supported. */
1511
- type?: 'gaussian' | undefined;
1573
+ type: 'gaussian';
1512
1574
  /** mean of pixels in generated noise. */
1513
1575
  mean?: number | undefined;
1514
1576
  /** standard deviation of pixels in generated noise. */
@@ -1722,9 +1784,12 @@ declare namespace sharp {
1722
1784
  interface KernelEnum {
1723
1785
  nearest: 'nearest';
1724
1786
  cubic: 'cubic';
1787
+ linear: 'linear';
1725
1788
  mitchell: 'mitchell';
1726
1789
  lanczos2: 'lanczos2';
1727
1790
  lanczos3: 'lanczos3';
1791
+ mks2013: 'mks2013';
1792
+ mks2021: 'mks2021';
1728
1793
  }
1729
1794
 
1730
1795
  interface PresetEnum {
@@ -1743,11 +1808,38 @@ declare namespace sharp {
1743
1808
  }
1744
1809
 
1745
1810
  interface ColourspaceEnum {
1746
- multiband: string;
1747
1811
  'b-w': string;
1748
- bw: string;
1812
+ cmc: string;
1749
1813
  cmyk: string;
1814
+ fourier: string;
1815
+ grey16: string;
1816
+ histogram: string;
1817
+ hsv: string;
1818
+ lab: string;
1819
+ labq: string;
1820
+ labs: string;
1821
+ lch: string;
1822
+ matrix: string;
1823
+ multiband: string;
1824
+ rgb: string;
1825
+ rgb16: string;
1826
+ scrgb: string;
1750
1827
  srgb: string;
1828
+ xyz: string;
1829
+ yxy: string;
1830
+ }
1831
+
1832
+ interface DepthEnum {
1833
+ char: string;
1834
+ complex: string;
1835
+ double: string;
1836
+ dpcomplex: string;
1837
+ float: string;
1838
+ int: string;
1839
+ short: string;
1840
+ uchar: string;
1841
+ uint: string;
1842
+ ushort: string;
1751
1843
  }
1752
1844
 
1753
1845
  type FailOnOptions = 'none' | 'truncated' | 'error' | 'warning';
@@ -1815,7 +1907,9 @@ declare namespace sharp {
1815
1907
 
1816
1908
  interface FormatEnum {
1817
1909
  avif: AvailableFormatInfo;
1910
+ dcraw: AvailableFormatInfo;
1818
1911
  dz: AvailableFormatInfo;
1912
+ exr: AvailableFormatInfo;
1819
1913
  fits: AvailableFormatInfo;
1820
1914
  gif: AvailableFormatInfo;
1821
1915
  heif: AvailableFormatInfo;
@@ -1829,6 +1923,7 @@ declare namespace sharp {
1829
1923
  pdf: AvailableFormatInfo;
1830
1924
  png: AvailableFormatInfo;
1831
1925
  ppm: AvailableFormatInfo;
1926
+ rad: AvailableFormatInfo;
1832
1927
  raw: AvailableFormatInfo;
1833
1928
  svg: AvailableFormatInfo;
1834
1929
  tiff: AvailableFormatInfo;
package/lib/input.js CHANGED
@@ -22,14 +22,27 @@ const align = {
22
22
  high: 'high'
23
23
  };
24
24
 
25
+ const inputStreamParameters = [
26
+ // Limits and error handling
27
+ 'failOn', 'limitInputPixels', 'unlimited',
28
+ // Format-generic
29
+ 'animated', 'autoOrient', 'density', 'ignoreIcc', 'page', 'pages', 'sequentialRead',
30
+ // Format-specific
31
+ 'jp2', 'openSlide', 'pdf', 'raw', 'svg', 'tiff',
32
+ // Deprecated
33
+ 'failOnError', 'openSlideLevel', 'pdfBackground', 'tiffSubifd'
34
+ ];
35
+
25
36
  /**
26
37
  * Extract input options, if any, from an object.
27
38
  * @private
28
39
  */
29
40
  function _inputOptionsFromObject (obj) {
30
- const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient } = obj;
31
- return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient].some(is.defined)
32
- ? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient }
41
+ const params = inputStreamParameters
42
+ .filter(p => is.defined(obj[p]))
43
+ .map(p => ([p, obj[p]]));
44
+ return params.length
45
+ ? Object.fromEntries(params)
33
46
  : undefined;
34
47
  }
35
48
 
@@ -172,8 +185,6 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
172
185
  inputDescriptor.rawWidth = inputOptions.raw.width;
173
186
  inputDescriptor.rawHeight = inputOptions.raw.height;
174
187
  inputDescriptor.rawChannels = inputOptions.raw.channels;
175
- inputDescriptor.rawPremultiplied = !!inputOptions.raw.premultiplied;
176
-
177
188
  switch (input.constructor) {
178
189
  case Uint8Array:
179
190
  case Uint8ClampedArray:
@@ -207,6 +218,25 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
207
218
  } else {
208
219
  throw new Error('Expected width, height and channels for raw pixel input');
209
220
  }
221
+ inputDescriptor.rawPremultiplied = false;
222
+ if (is.defined(inputOptions.raw.premultiplied)) {
223
+ if (is.bool(inputOptions.raw.premultiplied)) {
224
+ inputDescriptor.rawPremultiplied = inputOptions.raw.premultiplied;
225
+ } else {
226
+ throw is.invalidParameterError('raw.premultiplied', 'boolean', inputOptions.raw.premultiplied);
227
+ }
228
+ }
229
+ inputDescriptor.rawPageHeight = 0;
230
+ if (is.defined(inputOptions.raw.pageHeight)) {
231
+ if (is.integer(inputOptions.raw.pageHeight) && inputOptions.raw.pageHeight > 0 && inputOptions.raw.pageHeight <= inputOptions.raw.height) {
232
+ if (inputOptions.raw.height % inputOptions.raw.pageHeight !== 0) {
233
+ throw new Error(`Expected raw.height ${inputOptions.raw.height} to be a multiple of raw.pageHeight ${inputOptions.raw.pageHeight}`);
234
+ }
235
+ inputDescriptor.rawPageHeight = inputOptions.raw.pageHeight;
236
+ } else {
237
+ throw is.invalidParameterError('raw.pageHeight', 'positive integer', inputOptions.raw.pageHeight);
238
+ }
239
+ }
210
240
  }
211
241
  // Multi-page input (GIF, TIFF, PDF)
212
242
  if (is.defined(inputOptions.animated)) {
@@ -230,26 +260,68 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
230
260
  throw is.invalidParameterError('page', 'integer between 0 and 100000', inputOptions.page);
231
261
  }
232
262
  }
233
- // Multi-level input (OpenSlide)
234
- if (is.defined(inputOptions.level)) {
263
+ // OpenSlide specific options
264
+ if (is.object(inputOptions.openSlide) && is.defined(inputOptions.openSlide.level)) {
265
+ if (is.integer(inputOptions.openSlide.level) && is.inRange(inputOptions.openSlide.level, 0, 256)) {
266
+ inputDescriptor.openSlideLevel = inputOptions.openSlide.level;
267
+ } else {
268
+ throw is.invalidParameterError('openSlide.level', 'integer between 0 and 256', inputOptions.openSlide.level);
269
+ }
270
+ } else if (is.defined(inputOptions.level)) {
271
+ // Deprecated
235
272
  if (is.integer(inputOptions.level) && is.inRange(inputOptions.level, 0, 256)) {
236
- inputDescriptor.level = inputOptions.level;
273
+ inputDescriptor.openSlideLevel = inputOptions.level;
237
274
  } else {
238
275
  throw is.invalidParameterError('level', 'integer between 0 and 256', inputOptions.level);
239
276
  }
240
277
  }
241
- // Sub Image File Directory (TIFF)
242
- if (is.defined(inputOptions.subifd)) {
278
+ // TIFF specific options
279
+ if (is.object(inputOptions.tiff) && is.defined(inputOptions.tiff.subifd)) {
280
+ if (is.integer(inputOptions.tiff.subifd) && is.inRange(inputOptions.tiff.subifd, -1, 100000)) {
281
+ inputDescriptor.tiffSubifd = inputOptions.tiff.subifd;
282
+ } else {
283
+ throw is.invalidParameterError('tiff.subifd', 'integer between -1 and 100000', inputOptions.tiff.subifd);
284
+ }
285
+ } else if (is.defined(inputOptions.subifd)) {
286
+ // Deprecated
243
287
  if (is.integer(inputOptions.subifd) && is.inRange(inputOptions.subifd, -1, 100000)) {
244
- inputDescriptor.subifd = inputOptions.subifd;
288
+ inputDescriptor.tiffSubifd = inputOptions.subifd;
245
289
  } else {
246
290
  throw is.invalidParameterError('subifd', 'integer between -1 and 100000', inputOptions.subifd);
247
291
  }
248
292
  }
249
- // PDF background colour
250
- if (is.defined(inputOptions.pdfBackground)) {
293
+ // SVG specific options
294
+ if (is.object(inputOptions.svg)) {
295
+ if (is.defined(inputOptions.svg.stylesheet)) {
296
+ if (is.string(inputOptions.svg.stylesheet)) {
297
+ inputDescriptor.svgStylesheet = inputOptions.svg.stylesheet;
298
+ } else {
299
+ throw is.invalidParameterError('svg.stylesheet', 'string', inputOptions.svg.stylesheet);
300
+ }
301
+ }
302
+ if (is.defined(inputOptions.svg.highBitdepth)) {
303
+ if (is.bool(inputOptions.svg.highBitdepth)) {
304
+ inputDescriptor.svgHighBitdepth = inputOptions.svg.highBitdepth;
305
+ } else {
306
+ throw is.invalidParameterError('svg.highBitdepth', 'boolean', inputOptions.svg.highBitdepth);
307
+ }
308
+ }
309
+ }
310
+ // PDF specific options
311
+ if (is.object(inputOptions.pdf) && is.defined(inputOptions.pdf.background)) {
312
+ inputDescriptor.pdfBackground = this._getBackgroundColourOption(inputOptions.pdf.background);
313
+ } else if (is.defined(inputOptions.pdfBackground)) {
314
+ // Deprecated
251
315
  inputDescriptor.pdfBackground = this._getBackgroundColourOption(inputOptions.pdfBackground);
252
316
  }
317
+ // JPEG 2000 specific options
318
+ if (is.object(inputOptions.jp2) && is.defined(inputOptions.jp2.oneshot)) {
319
+ if (is.bool(inputOptions.jp2.oneshot)) {
320
+ inputDescriptor.jp2Oneshot = inputOptions.jp2.oneshot;
321
+ } else {
322
+ throw is.invalidParameterError('jp2.oneshot', 'boolean', inputOptions.jp2.oneshot);
323
+ }
324
+ }
253
325
  // Create new image
254
326
  if (is.defined(inputOptions.create)) {
255
327
  if (
@@ -261,27 +333,44 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
261
333
  inputDescriptor.createWidth = inputOptions.create.width;
262
334
  inputDescriptor.createHeight = inputOptions.create.height;
263
335
  inputDescriptor.createChannels = inputOptions.create.channels;
336
+ inputDescriptor.createPageHeight = 0;
337
+ if (is.defined(inputOptions.create.pageHeight)) {
338
+ if (is.integer(inputOptions.create.pageHeight) && inputOptions.create.pageHeight > 0 && inputOptions.create.pageHeight <= inputOptions.create.height) {
339
+ if (inputOptions.create.height % inputOptions.create.pageHeight !== 0) {
340
+ throw new Error(`Expected create.height ${inputOptions.create.height} to be a multiple of create.pageHeight ${inputOptions.create.pageHeight}`);
341
+ }
342
+ inputDescriptor.createPageHeight = inputOptions.create.pageHeight;
343
+ } else {
344
+ throw is.invalidParameterError('create.pageHeight', 'positive integer', inputOptions.create.pageHeight);
345
+ }
346
+ }
264
347
  // Noise
265
348
  if (is.defined(inputOptions.create.noise)) {
266
349
  if (!is.object(inputOptions.create.noise)) {
267
350
  throw new Error('Expected noise to be an object');
268
351
  }
269
- if (!is.inArray(inputOptions.create.noise.type, ['gaussian'])) {
352
+ if (inputOptions.create.noise.type !== 'gaussian') {
270
353
  throw new Error('Only gaussian noise is supported at the moment');
271
354
  }
355
+ inputDescriptor.createNoiseType = inputOptions.create.noise.type;
272
356
  if (!is.inRange(inputOptions.create.channels, 1, 4)) {
273
357
  throw is.invalidParameterError('create.channels', 'number between 1 and 4', inputOptions.create.channels);
274
358
  }
275
- inputDescriptor.createNoiseType = inputOptions.create.noise.type;
276
- if (is.number(inputOptions.create.noise.mean) && is.inRange(inputOptions.create.noise.mean, 0, 10000)) {
277
- inputDescriptor.createNoiseMean = inputOptions.create.noise.mean;
278
- } else {
279
- throw is.invalidParameterError('create.noise.mean', 'number between 0 and 10000', inputOptions.create.noise.mean);
359
+ inputDescriptor.createNoiseMean = 128;
360
+ if (is.defined(inputOptions.create.noise.mean)) {
361
+ if (is.number(inputOptions.create.noise.mean) && is.inRange(inputOptions.create.noise.mean, 0, 10000)) {
362
+ inputDescriptor.createNoiseMean = inputOptions.create.noise.mean;
363
+ } else {
364
+ throw is.invalidParameterError('create.noise.mean', 'number between 0 and 10000', inputOptions.create.noise.mean);
365
+ }
280
366
  }
281
- if (is.number(inputOptions.create.noise.sigma) && is.inRange(inputOptions.create.noise.sigma, 0, 10000)) {
282
- inputDescriptor.createNoiseSigma = inputOptions.create.noise.sigma;
283
- } else {
284
- throw is.invalidParameterError('create.noise.sigma', 'number between 0 and 10000', inputOptions.create.noise.sigma);
367
+ inputDescriptor.createNoiseSigma = 30;
368
+ if (is.defined(inputOptions.create.noise.sigma)) {
369
+ if (is.number(inputOptions.create.noise.sigma) && is.inRange(inputOptions.create.noise.sigma, 0, 10000)) {
370
+ inputDescriptor.createNoiseSigma = inputOptions.create.noise.sigma;
371
+ } else {
372
+ throw is.invalidParameterError('create.noise.sigma', 'number between 0 and 10000', inputOptions.create.noise.sigma);
373
+ }
285
374
  }
286
375
  } else if (is.defined(inputOptions.create.background)) {
287
376
  if (!is.inRange(inputOptions.create.channels, 3, 4)) {
@@ -516,6 +605,7 @@ function _isStreamInput () {
516
605
  * - `icc`: Buffer containing raw [ICC](https://www.npmjs.com/package/icc) profile data, if present
517
606
  * - `iptc`: Buffer containing raw IPTC data, if present
518
607
  * - `xmp`: Buffer containing raw XMP data, if present
608
+ * - `xmpAsString`: String containing XMP data, if valid UTF-8.
519
609
  * - `tifftagPhotoshop`: Buffer containing raw TIFFTAG_PHOTOSHOP data, if present
520
610
  * - `formatMagick`: String containing format for images loaded via *magick
521
611
  * - `comments`: Array of keyword/text pairs representing PNG text blocks, if present.
package/lib/libvips.js CHANGED
@@ -18,9 +18,9 @@ const minimumLibvipsVersion = semverCoerce(minimumLibvipsVersionLabelled).versio
18
18
 
19
19
  const prebuiltPlatforms = [
20
20
  'darwin-arm64', 'darwin-x64',
21
- 'linux-arm', 'linux-arm64', 'linux-s390x', 'linux-x64',
21
+ 'linux-arm', 'linux-arm64', 'linux-ppc64', 'linux-s390x', 'linux-x64',
22
22
  'linuxmusl-arm64', 'linuxmusl-x64',
23
- 'win32-ia32', 'win32-x64'
23
+ 'win32-arm64', 'win32-ia32', 'win32-x64'
24
24
  ];
25
25
 
26
26
  const spawnSyncOptions = {