sharp 0.34.5 → 0.35.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,7 +8,7 @@ smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF images of varying dimensions
8
8
 
9
9
  It can be used with all JavaScript runtimes
10
10
  that provide support for Node-API v9, including
11
- Node.js (^18.17.0 or >= 20.3.0), Deno and Bun.
11
+ Node.js (>= 20.9.0), Deno and Bun.
12
12
 
13
13
  Resizing an image is typically 4x-5x faster than using the
14
14
  quickest ImageMagick and GraphicsMagick settings
@@ -41,28 +41,20 @@ npm install sharp
41
41
  const sharp = require('sharp');
42
42
  ```
43
43
 
44
- ### Callback
45
-
46
44
  ```javascript
47
- sharp(inputBuffer)
48
- .resize(320, 240)
45
+ await sharp(inputBuffer)
46
+ .resize({ width: 320, height: 240 })
49
47
  .toFile('output.webp', (err, info) => { ... });
50
48
  ```
51
49
 
52
- ### Promise
53
-
54
50
  ```javascript
55
- sharp('input.jpg')
56
- .rotate()
57
- .resize(200)
51
+ const output = await sharp('input.jpg')
52
+ .autoOrient()
53
+ .resize({ width: 200 })
58
54
  .jpeg({ mozjpeg: true })
59
- .toBuffer()
60
- .then( data => { ... })
61
- .catch( err => { ... });
55
+ .toBuffer();
62
56
  ```
63
57
 
64
- ### Async/await
65
-
66
58
  ```javascript
67
59
  const semiTransparentRedPng = await sharp({
68
60
  create: {
@@ -76,8 +68,6 @@ const semiTransparentRedPng = await sharp({
76
68
  .toBuffer();
77
69
  ```
78
70
 
79
- ### Stream
80
-
81
71
  ```javascript
82
72
  const roundedCorners = Buffer.from(
83
73
  '<svg><rect x="0" y="0" width="200" height="200" rx="50" ry="50"/></svg>'
package/install/build.js CHANGED
@@ -10,7 +10,7 @@ const {
10
10
  spawnRebuild,
11
11
  } = require('../lib/libvips');
12
12
 
13
- log('Attempting to build from source via node-gyp');
13
+ log('Building from source');
14
14
  log('See https://sharp.pixelplumbing.com/install#building-from-source');
15
15
 
16
16
  try {
@@ -29,7 +29,7 @@ try {
29
29
  }
30
30
 
31
31
  if (useGlobalLibvips(log)) {
32
- log(`Detected globally-installed libvips v${globalLibvipsVersion()}`);
32
+ log(`Found globally-installed libvips v${globalLibvipsVersion()}`);
33
33
  }
34
34
 
35
35
  const status = spawnRebuild();
@@ -153,7 +153,7 @@ const queueListener = (queueLength) => {
153
153
  * @param {boolean} [options.unlimited=false] - Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF).
154
154
  * @param {boolean} [options.autoOrient=false] - Set this to `true` to rotate/flip the image to match EXIF `Orientation`, if any.
155
155
  * @param {boolean} [options.sequentialRead=true] - Set this to `false` to use random access rather than sequential read. Some operations will do this automatically.
156
- * @param {number} [options.density=72] - number representing the DPI for vector images in the range 1 to 100000.
156
+ * @param {number} [options.density=72] - The DPI at which to render SVG and PDF images, in the range 1 to 100000.
157
157
  * @param {number} [options.ignoreIcc=false] - should the embedded ICC profile, if any, be ignored.
158
158
  * @param {number} [options.pages=1] - Number of pages to extract for multi-page input (GIF, WebP, TIFF), use -1 for all pages.
159
159
  * @param {number} [options.page=0] - Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based.
@@ -278,6 +278,7 @@ const Sharp = function (input, options) {
278
278
  trimBackground: [],
279
279
  trimThreshold: -1,
280
280
  trimLineArt: false,
281
+ trimMargin: 0,
281
282
  dilateWidth: 0,
282
283
  erodeWidth: 0,
283
284
  gamma: 0,
@@ -306,6 +307,7 @@ const Sharp = function (input, options) {
306
307
  fileOut: '',
307
308
  formatOut: 'input',
308
309
  streamOut: false,
310
+ typedArrayOut: false,
309
311
  keepMetadata: 0,
310
312
  withMetadataOrientation: -1,
311
313
  withMetadataDensity: 0,
@@ -313,6 +315,8 @@ const Sharp = function (input, options) {
313
315
  withExif: {},
314
316
  withExifMerge: true,
315
317
  withXmp: '',
318
+ keepGainMap: false,
319
+ withGainMap: false,
316
320
  resolveWithObject: false,
317
321
  loop: -1,
318
322
  delay: [],
@@ -348,6 +352,7 @@ const Sharp = function (input, options) {
348
352
  webpEffort: 4,
349
353
  webpMinSize: false,
350
354
  webpMixed: false,
355
+ webpExact: false,
351
356
  gifBitdepth: 8,
352
357
  gifEffort: 7,
353
358
  gifDither: 1,
@@ -362,7 +367,7 @@ const Sharp = function (input, options) {
362
367
  tiffPredictor: 'horizontal',
363
368
  tiffPyramid: false,
364
369
  tiffMiniswhite: false,
365
- tiffBitdepth: 8,
370
+ tiffBitdepth: 0,
366
371
  tiffTile: false,
367
372
  tiffTileHeight: 256,
368
373
  tiffTileWidth: 256,
@@ -375,6 +380,7 @@ const Sharp = function (input, options) {
375
380
  heifEffort: 4,
376
381
  heifChromaSubsampling: '4:4:4',
377
382
  heifBitdepth: 8,
383
+ heifTune: 'ssim',
378
384
  jxlDistance: 1,
379
385
  jxlDecodingTier: 0,
380
386
  jxlEffort: 7,
package/lib/index.d.ts CHANGED
@@ -28,6 +28,7 @@
28
28
  /// <reference types="node" />
29
29
 
30
30
  import type { Duplex } from 'node:stream';
31
+ import { ColorLike } from '@img/colour';
31
32
 
32
33
  //#region Constructor functions
33
34
 
@@ -234,7 +235,7 @@ declare namespace sharp {
234
235
  * @param tint Parsed by the color module.
235
236
  * @returns A sharp instance that can be used to chain operations
236
237
  */
237
- tint(tint: Colour | Color): Sharp;
238
+ tint(tint: ColorLike): Sharp;
238
239
 
239
240
  /**
240
241
  * Convert to 8-bit greyscale; 256 shades of grey.
@@ -259,7 +260,6 @@ declare namespace sharp {
259
260
  * Set the pipeline colourspace.
260
261
  * The input image will be converted to the provided colourspace at the start of the pipeline.
261
262
  * All operations will use this colourspace before converting to the output colourspace, as defined by toColourspace.
262
- * This feature is experimental and has not yet been fully-tested with all operations.
263
263
  *
264
264
  * @param colourspace pipeline colourspace e.g. rgb16, scrgb, lab, grey16 ...
265
265
  * @throws {Error} Invalid parameters
@@ -470,21 +470,6 @@ declare namespace sharp {
470
470
  */
471
471
  sharpen(options?: SharpenOptions): Sharp;
472
472
 
473
- /**
474
- * Sharpen the image.
475
- * When used without parameters, performs a fast, mild sharpen of the output image.
476
- * When a sigma is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.
477
- * Fine-grained control over the level of sharpening in "flat" (m1) and "jagged" (m2) areas is available.
478
- * @param sigma the sigma of the Gaussian mask, where sigma = 1 + radius / 2.
479
- * @param flat the level of sharpening to apply to "flat" areas. (optional, default 1.0)
480
- * @param jagged the level of sharpening to apply to "jagged" areas. (optional, default 2.0)
481
- * @throws {Error} Invalid parameters
482
- * @returns A sharp instance that can be used to chain operations
483
- *
484
- * @deprecated Use the object parameter `sharpen({sigma, m1, m2, x1, y2, y3})` instead
485
- */
486
- sharpen(sigma?: number, flat?: number, jagged?: number): Sharp;
487
-
488
473
  /**
489
474
  * Apply median filter. When used without parameters the default window is 3x3.
490
475
  * @param size square mask size: size x size (optional, default 3)
@@ -693,6 +678,21 @@ declare namespace sharp {
693
678
  */
694
679
  toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer; info: OutputInfo }>;
695
680
 
681
+ /**
682
+ * Write output to a Uint8Array backed by a transferable ArrayBuffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
683
+ * By default, the format will match the input image, except SVG input which becomes PNG output.
684
+ * @returns A promise that resolves with an object containing the Uint8Array data and an info object containing the output image format, size (bytes), width, height and channels
685
+ */
686
+ toUint8Array(): Promise<{ data: Uint8Array; info: OutputInfo }>;
687
+
688
+ /**
689
+ * Set output density (DPI) in EXIF metadata.
690
+ * @param density Density in dots per inch (DPI).
691
+ * @returns A sharp instance that can be used to chain operations
692
+ * @throws {Error} Invalid parameters
693
+ */
694
+ withDensity(density: number): Sharp;
695
+
696
696
  /**
697
697
  * Keep all EXIF metadata from the input image in the output image.
698
698
  * EXIF metadata is unsupported for TIFF output.
@@ -849,7 +849,7 @@ declare namespace sharp {
849
849
  * @returns A sharp instance that can be used to chain operations
850
850
  */
851
851
  toFormat(
852
- format: keyof FormatEnum | AvailableFormatInfo,
852
+ format: keyof FormatEnum | AvailableFormatInfo | "avif",
853
853
  options?:
854
854
  | OutputOptions
855
855
  | JpegOptions
@@ -903,7 +903,7 @@ declare namespace sharp {
903
903
  * - sharp.gravity: north, northeast, east, southeast, south, southwest, west, northwest, center or centre.
904
904
  * - sharp.strategy: cover only, dynamically crop using either the entropy or attention strategy. Some of these values are based on the object-position CSS property.
905
905
  *
906
- * The experimental strategy-based approach resizes so one dimension is at its target length then repeatedly ranks edge regions,
906
+ * The strategy-based approach resizes so one dimension is at its target length then repeatedly ranks edge regions,
907
907
  * discarding the edge with the lowest score based on the selected strategy.
908
908
  * - entropy: focus on the region with the highest Shannon entropy.
909
909
  * - attention: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
@@ -992,14 +992,6 @@ declare namespace sharp {
992
992
  * 'none' (least), 'truncated', 'error' or 'warning' (most), highers level imply lower levels, invalid metadata will always abort. (optional, default 'warning')
993
993
  */
994
994
  failOn?: FailOnOptions | undefined;
995
- /**
996
- * By default halt processing and raise an error when loading invalid images.
997
- * Set this flag to false if you'd rather apply a "best effort" to decode images,
998
- * even if the data is corrupt or invalid. (optional, default true)
999
- *
1000
- * @deprecated Use `failOn` instead
1001
- */
1002
- failOnError?: boolean | undefined;
1003
995
  /**
1004
996
  * Do not process input images where the number of pixels (width x height) exceeds this limit.
1005
997
  * Assumes image dimensions contained in the input metadata can be trusted.
@@ -1010,7 +1002,7 @@ declare namespace sharp {
1010
1002
  unlimited?: boolean | undefined;
1011
1003
  /** Set this to false to use random access rather than sequential read. Some operations will do this automatically. */
1012
1004
  sequentialRead?: boolean | undefined;
1013
- /** Number representing the DPI for vector images in the range 1 to 100000. (optional, default 72) */
1005
+ /** The DPI at which to render SVG and PDF images, in the range 1 to 100000. (optional, default 72) */
1014
1006
  density?: number | undefined;
1015
1007
  /** Should the embedded ICC profile, if any, be ignored. */
1016
1008
  ignoreIcc?: boolean | undefined;
@@ -1028,11 +1020,11 @@ declare namespace sharp {
1028
1020
  openSlide?: OpenSlideInputOptions | undefined;
1029
1021
  /** JPEG 2000 specific input options */
1030
1022
  jp2?: Jp2InputOptions | undefined;
1031
- /** Deprecated: use tiff.subifd instead */
1023
+ /** @deprecated Use {@link SharpOptions.tiff} instead */
1032
1024
  subifd?: number | undefined;
1033
- /** Deprecated: use pdf.background instead */
1034
- pdfBackground?: Colour | Color | undefined;
1035
- /** Deprecated: use openSlide.level instead */
1025
+ /** @deprecated Use {@link SharpOptions.pdf} instead */
1026
+ pdfBackground?: ColorLike | undefined;
1027
+ /** @deprecated Use {@link SharpOptions.openSlide} instead */
1036
1028
  level?: number | undefined;
1037
1029
  /** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default false) */
1038
1030
  animated?: boolean | undefined;
@@ -1090,7 +1082,7 @@ declare namespace sharp {
1090
1082
  /** Number of bands, 3 for RGB, 4 for RGBA */
1091
1083
  channels: CreateChannels;
1092
1084
  /** Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. */
1093
- background: Colour | Color;
1085
+ background: ColorLike;
1094
1086
  /** Describes a noise to be created. */
1095
1087
  noise?: Noise | undefined;
1096
1088
  /** The height of each page/frame for animated images, must be an integral factor of the overall image height. */
@@ -1137,7 +1129,7 @@ declare namespace sharp {
1137
1129
  /** Space between images, in pixels. */
1138
1130
  shim?: number | undefined;
1139
1131
  /** Background colour. */
1140
- background?: Colour | Color | undefined;
1132
+ background?: ColorLike | undefined;
1141
1133
  /** Horizontal alignment. */
1142
1134
  halign?: HorizontalAlignment | undefined;
1143
1135
  /** Vertical alignment. */
@@ -1158,7 +1150,7 @@ declare namespace sharp {
1158
1150
 
1159
1151
  interface PdfInputOptions {
1160
1152
  /** 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. */
1161
- background?: Colour | Color | undefined;
1153
+ background?: ColorLike | undefined;
1162
1154
  }
1163
1155
 
1164
1156
  interface OpenSlideInputOptions {
@@ -1184,6 +1176,8 @@ declare namespace sharp {
1184
1176
 
1185
1177
  type HeifCompression = 'av1' | 'hevc';
1186
1178
 
1179
+ type HeifTune = 'iq' | 'ssim' | 'psnr';
1180
+
1187
1181
  type Unit = 'inch' | 'cm';
1188
1182
 
1189
1183
  interface WriteableMetadata {
@@ -1277,6 +1271,8 @@ declare namespace sharp {
1277
1271
  formatMagick?: string | undefined;
1278
1272
  /** Array of keyword/text pairs representing PNG text blocks, if present. */
1279
1273
  comments?: CommentsMetadata[] | undefined;
1274
+ /** HDR gain map, if present */
1275
+ gainMap?: GainMapMetadata | undefined;
1280
1276
  }
1281
1277
 
1282
1278
  interface LevelMetadata {
@@ -1289,16 +1285,21 @@ declare namespace sharp {
1289
1285
  text: string;
1290
1286
  }
1291
1287
 
1288
+ interface GainMapMetadata {
1289
+ /** JPEG image */
1290
+ image: Buffer;
1291
+ }
1292
+
1292
1293
  interface Stats {
1293
1294
  /** Array of channel statistics for each channel in the image. */
1294
1295
  channels: ChannelStats[];
1295
1296
  /** Value to identify if the image is opaque or transparent, based on the presence and use of alpha channel */
1296
1297
  isOpaque: boolean;
1297
- /** Histogram-based estimation of greyscale entropy, discarding alpha channel if any (experimental) */
1298
+ /** Histogram-based estimation of greyscale entropy, discarding alpha channel if any */
1298
1299
  entropy: number;
1299
- /** Estimation of greyscale sharpness based on the standard deviation of a Laplacian convolution, discarding alpha channel if any (experimental) */
1300
+ /** Estimation of greyscale sharpness based on the standard deviation of a Laplacian convolution, discarding alpha channel if any */
1300
1301
  sharpness: number;
1301
- /** Object containing most dominant sRGB colour based on a 4096-bin 3D histogram (experimental) */
1302
+ /** Object containing most dominant sRGB colour based on a 4096-bin 3D histogram */
1302
1303
  dominant: { r: number; g: number; b: number };
1303
1304
  }
1304
1305
 
@@ -1404,11 +1405,13 @@ declare namespace sharp {
1404
1405
  /** Level of CPU effort to reduce file size, integer 0-6 (optional, default 4) */
1405
1406
  effort?: number | undefined;
1406
1407
  /** Prevent use of animation key frames to minimise file size (slow) (optional, default false) */
1407
- minSize?: boolean;
1408
+ minSize?: boolean | undefined;
1408
1409
  /** Allow mixture of lossy and lossless animation frames (slow) (optional, default false) */
1409
- mixed?: boolean;
1410
+ mixed?: boolean | undefined;
1410
1411
  /** Preset options: one of default, photo, picture, drawing, icon, text (optional, default 'default') */
1411
1412
  preset?: keyof PresetEnum | undefined;
1413
+ /** Preserve the colour data in transparent pixels (optional, default false) */
1414
+ exact?: boolean | undefined;
1412
1415
  }
1413
1416
 
1414
1417
  interface AvifOptions extends OutputOptions {
@@ -1422,6 +1425,8 @@ declare namespace sharp {
1422
1425
  chromaSubsampling?: string | undefined;
1423
1426
  /** Set bitdepth to 8, 10 or 12 bit (optional, default 8) */
1424
1427
  bitdepth?: 8 | 10 | 12 | undefined;
1428
+ /** Tune output for a quality metric, one of 'iq', 'ssim' or 'psnr' (optional, default 'iq') */
1429
+ tune?: HeifTune | undefined;
1425
1430
  }
1426
1431
 
1427
1432
  interface HeifOptions extends OutputOptions {
@@ -1437,6 +1442,8 @@ declare namespace sharp {
1437
1442
  chromaSubsampling?: string | undefined;
1438
1443
  /** Set bitdepth to 8, 10 or 12 bit (optional, default 8) */
1439
1444
  bitdepth?: 8 | 10 | 12 | undefined;
1445
+ /** Tune output for a quality metric, one of 'ssim', 'psnr' or 'iq' (optional, default 'ssim') */
1446
+ tune?: HeifTune | undefined;
1440
1447
  }
1441
1448
 
1442
1449
  interface GifOptions extends OutputOptions, AnimationOptions {
@@ -1481,8 +1488,8 @@ declare namespace sharp {
1481
1488
  xres?: number | undefined;
1482
1489
  /** Vertical resolution in pixels/mm (optional, default 1.0) */
1483
1490
  yres?: number | undefined;
1484
- /** Reduce bitdepth to 1, 2 or 4 bit (optional, default 8) */
1485
- bitdepth?: 1 | 2 | 4 | 8 | undefined;
1491
+ /** Reduce bitdepth to 1, 2 or 4 bit (optional) */
1492
+ bitdepth?: 1 | 2 | 4 | undefined;
1486
1493
  /** Write 1-bit images as miniswhite (optional, default false) */
1487
1494
  miniswhite?: boolean | undefined;
1488
1495
  /** Resolution unit options: inch, cm (optional, default 'inch') */
@@ -1512,7 +1519,7 @@ declare namespace sharp {
1512
1519
 
1513
1520
  interface RotateOptions {
1514
1521
  /** parsed by the color module to extract values for red, green, blue and alpha. (optional, default "#000000") */
1515
- background?: Colour | Color | undefined;
1522
+ background?: ColorLike | undefined;
1516
1523
  }
1517
1524
 
1518
1525
  type Precision = 'integer' | 'float' | 'approximate';
@@ -1528,7 +1535,7 @@ declare namespace sharp {
1528
1535
 
1529
1536
  interface FlattenOptions {
1530
1537
  /** background colour, parsed by the color module, defaults to black. (optional, default {r:0,g:0,b:0}) */
1531
- background?: Colour | Color | undefined;
1538
+ background?: ColorLike | undefined;
1532
1539
  }
1533
1540
 
1534
1541
  interface NegateOptions {
@@ -1553,7 +1560,7 @@ declare namespace sharp {
1553
1560
  /** Position, gravity or strategy to use when fit is cover or contain. (optional, default 'centre') */
1554
1561
  position?: number | string | undefined;
1555
1562
  /** Background colour when using a fit of contain, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
1556
- background?: Colour | Color | undefined;
1563
+ background?: ColorLike | undefined;
1557
1564
  /** The kernel to use for image reduction. (optional, default 'lanczos3') */
1558
1565
  kernel?: keyof KernelEnum | undefined;
1559
1566
  /** Do not enlarge if the width or height are already less than the specified dimensions, equivalent to GraphicsMagick's > geometry option. (optional, default false) */
@@ -1596,18 +1603,20 @@ declare namespace sharp {
1596
1603
  /** single pixel count to right edge (optional, default 0) */
1597
1604
  right?: number | undefined;
1598
1605
  /** background colour, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
1599
- background?: Colour | Color | undefined;
1606
+ background?: ColorLike | undefined;
1600
1607
  /** how the extension is done, one of: "background", "copy", "repeat", "mirror" (optional, default `'background'`) */
1601
1608
  extendWith?: ExtendWith | undefined;
1602
1609
  }
1603
1610
 
1604
1611
  interface TrimOptions {
1605
1612
  /** Background colour, parsed by the color module, defaults to that of the top-left pixel. (optional) */
1606
- background?: Colour | Color | undefined;
1613
+ background?: ColorLike | undefined;
1607
1614
  /** Allowed difference from the above colour, a positive number. (optional, default 10) */
1608
1615
  threshold?: number | undefined;
1609
1616
  /** Does the input more closely resemble line art (e.g. vector) rather than being photographic? (optional, default false) */
1610
1617
  lineArt?: boolean | undefined;
1618
+ /** Leave a margin around trimmed content, value is in pixels. (optional, default 0) */
1619
+ margin?: number | undefined;
1611
1620
  }
1612
1621
 
1613
1622
  interface RawOptions {
@@ -1617,15 +1626,8 @@ declare namespace sharp {
1617
1626
  /** 1 for grayscale, 2 for grayscale + alpha, 3 for sRGB, 4 for CMYK or RGBA */
1618
1627
  type Channels = 1 | 2 | 3 | 4;
1619
1628
 
1620
- interface RGBA {
1621
- r?: number | undefined;
1622
- g?: number | undefined;
1623
- b?: number | undefined;
1624
- alpha?: number | undefined;
1625
- }
1626
-
1627
- type Colour = string | RGBA;
1628
- type Color = Colour;
1629
+ type Colour = ColorLike;
1630
+ type Color = ColorLike;
1629
1631
 
1630
1632
  interface Kernel {
1631
1633
  /** width of the kernel in pixels. */
@@ -1691,7 +1693,7 @@ declare namespace sharp {
1691
1693
  /** Tile angle of rotation, must be a multiple of 90. (optional, default 0) */
1692
1694
  angle?: number | undefined;
1693
1695
  /** background colour, parsed by the color module, defaults to white without transparency. (optional, default {r:255,g:255,b:255,alpha:1}) */
1694
- background?: string | RGBA | undefined;
1696
+ background?: ColorLike | undefined;
1695
1697
  /** How deep to make the pyramid, possible values are "onepixel", "onetile" or "one" (default based on layout) */
1696
1698
  depth?: string | undefined;
1697
1699
  /** Threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images */
@@ -1913,16 +1915,13 @@ declare namespace sharp {
1913
1915
  }
1914
1916
 
1915
1917
  interface FormatEnum {
1916
- avif: AvailableFormatInfo;
1917
1918
  dcraw: AvailableFormatInfo;
1918
1919
  dz: AvailableFormatInfo;
1919
1920
  exr: AvailableFormatInfo;
1920
1921
  fits: AvailableFormatInfo;
1921
1922
  gif: AvailableFormatInfo;
1922
1923
  heif: AvailableFormatInfo;
1923
- input: AvailableFormatInfo;
1924
1924
  jpeg: AvailableFormatInfo;
1925
- jpg: AvailableFormatInfo;
1926
1925
  jp2: AvailableFormatInfo;
1927
1926
  jxl: AvailableFormatInfo;
1928
1927
  magick: AvailableFormatInfo;
@@ -1934,8 +1933,7 @@ declare namespace sharp {
1934
1933
  raw: AvailableFormatInfo;
1935
1934
  svg: AvailableFormatInfo;
1936
1935
  tiff: AvailableFormatInfo;
1937
- tif: AvailableFormatInfo;
1938
- v: AvailableFormatInfo;
1936
+ vips: AvailableFormatInfo;
1939
1937
  webp: AvailableFormatInfo;
1940
1938
  }
1941
1939
 
package/lib/input.js CHANGED
@@ -30,7 +30,7 @@ const inputStreamParameters = [
30
30
  // Format-specific
31
31
  'jp2', 'openSlide', 'pdf', 'raw', 'svg', 'tiff',
32
32
  // Deprecated
33
- 'failOnError', 'openSlideLevel', 'pdfBackground', 'tiffSubifd'
33
+ 'openSlideLevel', 'pdfBackground', 'tiffSubifd'
34
34
  ];
35
35
 
36
36
  /**
@@ -106,14 +106,6 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
106
106
  }`);
107
107
  }
108
108
  if (is.object(inputOptions)) {
109
- // Deprecated: failOnError
110
- if (is.defined(inputOptions.failOnError)) {
111
- if (is.bool(inputOptions.failOnError)) {
112
- inputDescriptor.failOn = inputOptions.failOnError ? 'warning' : 'none';
113
- } else {
114
- throw is.invalidParameterError('failOnError', 'boolean', inputOptions.failOnError);
115
- }
116
- }
117
109
  // failOn
118
110
  if (is.defined(inputOptions.failOn)) {
119
111
  if (is.string(inputOptions.failOn) && is.inArray(inputOptions.failOn, ['none', 'truncated', 'error', 'warning'])) {
@@ -574,7 +566,8 @@ function _isStreamInput () {
574
566
  *
575
567
  * A `Promise` is returned when `callback` is not provided.
576
568
  *
577
- * - `format`: Name of decoder used to decompress image data e.g. `jpeg`, `png`, `webp`, `gif`, `svg`
569
+ * - `format`: Name of decoder used to parse image e.g. `jpeg`, `png`, `webp`, `gif`, `svg`, `heif`, `tiff`
570
+ * - `mediaType`: Media Type (MIME Type) e.g. `image/jpeg`, `image/png`, `image/svg+xml`, `image/avif`
578
571
  * - `size`: Total size of image in bytes, for Stream and Buffer input only
579
572
  * - `width`: Number of pixels wide (EXIF orientation is not taken into consideration, see example below)
580
573
  * - `height`: Number of pixels high (EXIF orientation is not taken into consideration, see example below)
@@ -607,6 +600,7 @@ function _isStreamInput () {
607
600
  * - `tifftagPhotoshop`: Buffer containing raw TIFFTAG_PHOTOSHOP data, if present
608
601
  * - `formatMagick`: String containing format for images loaded via *magick
609
602
  * - `comments`: Array of keyword/text pairs representing PNG text blocks, if present.
603
+ * - `gainMap.image`: HDR gain map, if present, as compressed JPEG image.
610
604
  *
611
605
  * @example
612
606
  * const metadata = await sharp(input).metadata();
package/lib/libvips.js CHANGED
@@ -18,7 +18,8 @@ const minimumLibvipsVersion = semverCoerce(minimumLibvipsVersionLabelled).versio
18
18
 
19
19
  const prebuiltPlatforms = [
20
20
  'darwin-arm64', 'darwin-x64',
21
- 'linux-arm', 'linux-arm64', 'linux-ppc64', 'linux-riscv64', 'linux-s390x', 'linux-x64',
21
+ 'freebsd-arm64', 'freebsd-x64',
22
+ 'linux-arm', 'linux-arm64', 'linux-ppc64', 'linux-riscv64', 'linux-s390x', 'linux-wasm32', 'linux-x64',
22
23
  'linuxmusl-arm64', 'linuxmusl-x64',
23
24
  'win32-arm64', 'win32-ia32', 'win32-x64'
24
25
  ];
@@ -36,13 +37,13 @@ const log = (item) => {
36
37
  }
37
38
  };
38
39
 
39
- /* node:coverage ignore next */
40
+ /* node:coverage disable */
41
+
40
42
  const runtimeLibc = () => detectLibc.isNonGlibcLinuxSync() ? detectLibc.familySync() : '';
41
43
 
42
44
  const runtimePlatformArch = () => `${process.platform}${runtimeLibc()}-${process.arch}`;
43
45
 
44
46
  const buildPlatformArch = () => {
45
- /* node:coverage ignore next 3 */
46
47
  if (isEmscripten()) {
47
48
  return 'wasm32';
48
49
  }
@@ -55,7 +56,6 @@ const buildSharpLibvipsIncludeDir = () => {
55
56
  try {
56
57
  return require(`@img/sharp-libvips-dev-${buildPlatformArch()}/include`);
57
58
  } catch {
58
- /* node:coverage ignore next 5 */
59
59
  try {
60
60
  return require('@img/sharp-libvips-dev/include');
61
61
  } catch {}
@@ -64,7 +64,6 @@ const buildSharpLibvipsIncludeDir = () => {
64
64
  };
65
65
 
66
66
  const buildSharpLibvipsCPlusPlusDir = () => {
67
- /* node:coverage ignore next 4 */
68
67
  try {
69
68
  return require('@img/sharp-libvips-dev/cplusplus');
70
69
  } catch {}
@@ -75,7 +74,6 @@ const buildSharpLibvipsLibDir = () => {
75
74
  try {
76
75
  return require(`@img/sharp-libvips-dev-${buildPlatformArch()}/lib`);
77
76
  } catch {
78
- /* node:coverage ignore next 5 */
79
77
  try {
80
78
  return require(`@img/sharp-libvips-${buildPlatformArch()}/lib`);
81
79
  } catch {}
@@ -83,8 +81,6 @@ const buildSharpLibvipsLibDir = () => {
83
81
  return '';
84
82
  };
85
83
 
86
- /* node:coverage disable */
87
-
88
84
  const isUnsupportedNodeRuntime = () => {
89
85
  if (process.release?.name === 'node' && process.versions) {
90
86
  if (!semverSatisfies(process.versions.node, engines.node)) {
@@ -144,22 +140,34 @@ const globalLibvipsVersion = () => {
144
140
  }
145
141
  };
146
142
 
143
+ const getBrewPkgConfigPath = () => {
144
+ try {
145
+ const brewPrefix = (spawnSync('brew', ['--prefix'], { encoding: 'utf8' }).stdout || '').trim();
146
+ if (brewPrefix) {
147
+ return `${brewPrefix}/lib/pkgconfig`;
148
+ }
149
+ } catch (_err) {}
150
+ return undefined;
151
+ };
152
+
153
+ const getPkgConfigPath = () => {
154
+ try {
155
+ const pkgConfigPath = (spawnSync('pkg-config', ['--variable', 'pc_path', 'pkg-config'], { encoding: 'utf8' }).stdout || '').trim();
156
+ if (pkgConfigPath) {
157
+ return pkgConfigPath;
158
+ }
159
+ } catch (_err) {}
160
+ return undefined;
161
+ };
162
+
147
163
  /* node:coverage enable */
148
164
 
149
165
  const pkgConfigPath = () => {
150
166
  if (process.platform !== 'win32') {
151
- /* node:coverage ignore next 4 */
152
- const brewPkgConfigPath = spawnSync(
153
- 'which brew >/dev/null 2>&1 && brew environment --plain | grep PKG_CONFIG_LIBDIR | cut -d" " -f2',
154
- spawnSyncOptions
155
- ).stdout || '';
156
167
  return [
157
- brewPkgConfigPath.trim(),
158
- process.env.PKG_CONFIG_PATH,
159
- '/usr/local/lib/pkgconfig',
160
- '/usr/lib/pkgconfig',
161
- '/usr/local/libdata/pkgconfig',
162
- '/usr/libdata/pkgconfig'
168
+ getBrewPkgConfigPath(),
169
+ getPkgConfigPath(),
170
+ process.env.PKG_CONFIG_PATH
163
171
  ].filter(Boolean).join(':');
164
172
  } else {
165
173
  return '';