UNPKG

75.2 kBTypeScriptView Raw
1// Type definitions for sharp 0.31
2// Project: https://github.com/lovell/sharp
3// Definitions by: Wooseop Kim <https://github.com/wooseopkim>
4// Bradley Odell <https://github.com/BTOdell>
5// Jamie Woodbury <https://github.com/JamieWoodbury>
6// Floris de Bijl <https://github.com/Fdebijl>
7// Billy Kwok <https://github.com/billykwok>
8// Espen Hovlandsdal <https://github.com/rexxars>
9// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
10// TypeScript Version: 2.1
11
12/// <reference types="node" />
13
14import { Duplex } from 'stream';
15
16//#region Constructor functions
17
18/**
19 * Creates a sharp instance from an image
20 * @param input Buffer containing JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data, or String containing the path to an JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image file.
21 * @param options Object with optional attributes.
22 * @throws {Error} Invalid parameters
23 * @returns A sharp instance that can be used to chain operations
24 */
25declare function sharp(options?: sharp.SharpOptions): sharp.Sharp;
26declare function sharp(
27 input?:
28 | Buffer
29 | Uint8Array
30 | Uint8ClampedArray
31 | Int8Array
32 | Uint16Array
33 | Int16Array
34 | Uint32Array
35 | Int32Array
36 | Float32Array
37 | Float64Array
38 | string,
39 options?: sharp.SharpOptions,
40): sharp.Sharp;
41
42declare namespace sharp {
43 /** Object containing nested boolean values representing the available input and output formats/methods. */
44 const format: FormatEnum;
45
46 /** An Object containing the version numbers of libvips and its dependencies. */
47 const versions: {
48 vips: string;
49 cairo?: string | undefined;
50 croco?: string | undefined;
51 exif?: string | undefined;
52 expat?: string | undefined;
53 ffi?: string | undefined;
54 fontconfig?: string | undefined;
55 freetype?: string | undefined;
56 gdkpixbuf?: string | undefined;
57 gif?: string | undefined;
58 glib?: string | undefined;
59 gsf?: string | undefined;
60 harfbuzz?: string | undefined;
61 jpeg?: string | undefined;
62 lcms?: string | undefined;
63 orc?: string | undefined;
64 pango?: string | undefined;
65 pixman?: string | undefined;
66 png?: string | undefined;
67 svg?: string | undefined;
68 tiff?: string | undefined;
69 webp?: string | undefined;
70 avif?: string | undefined;
71 heif?: string | undefined;
72 xml?: string | undefined;
73 zlib?: string | undefined;
74 };
75
76 /** An Object containing the platform and architecture of the current and installed vendored binaries. */
77 const vendor: {
78 current: string;
79 installed: string[];
80 };
81
82 /** An Object containing the available interpolators and their proper values */
83 const interpolators: Interpolators;
84
85 /** An EventEmitter that emits a change event when a task is either queued, waiting for libuv to provide a worker thread, complete */
86 const queue: NodeJS.EventEmitter;
87
88 //#endregion
89
90 //#region Utility functions
91
92 /**
93 * Gets or, when options are provided, sets the limits of libvips' operation cache.
94 * Existing entries in the cache will be trimmed after any change in limits.
95 * This method always returns cache statistics, useful for determining how much working memory is required for a particular task.
96 * @param options Object with the following attributes, or Boolean where true uses default cache settings and false removes all caching (optional, default true)
97 * @returns The cache results.
98 */
99 function cache(options?: boolean | CacheOptions): CacheResult;
100
101 /**
102 * Gets or sets the number of threads libvips' should create to process each image.
103 * The default value is the number of CPU cores. A value of 0 will reset to this default.
104 * The maximum number of images that can be processed in parallel is limited by libuv's UV_THREADPOOL_SIZE environment variable.
105 * @param concurrency The new concurrency value.
106 * @returns The current concurrency value.
107 */
108 function concurrency(concurrency?: number): number;
109
110 /**
111 * Provides access to internal task counters.
112 * @returns Object containing task counters
113 */
114 function counters(): SharpCounters;
115
116 /**
117 * Get and set use of SIMD vector unit instructions. Requires libvips to have been compiled with liborc support.
118 * Improves the performance of resize, blur and sharpen operations by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
119 * @param enable enable or disable use of SIMD vector unit instructions
120 * @returns true if usage of SIMD vector unit instructions is enabled
121 */
122 function simd(enable?: boolean): boolean;
123
124 //#endregion
125
126 const gravity: GravityEnum;
127 const strategy: StrategyEnum;
128 const kernel: KernelEnum;
129 const fit: FitEnum;
130 const bool: BoolEnum;
131
132 interface Sharp extends Duplex {
133 //#region Channel functions
134
135 /**
136 * Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
137 * @returns A sharp instance that can be used to chain operations
138 */
139 removeAlpha(): Sharp;
140
141 /**
142 * Ensure alpha channel, if missing. The added alpha channel will be fully opaque. This is a no-op if the image already has an alpha channel.
143 * @param alpha transparency level (0=fully-transparent, 1=fully-opaque) (optional, default 1).
144 * @returns A sharp instance that can be used to chain operations
145 */
146 ensureAlpha(alpha?: number): Sharp;
147
148 /**
149 * Extract a single channel from a multi-channel image.
150 * @param channel zero-indexed channel/band number to extract, or red, green, blue or alpha.
151 * @throws {Error} Invalid channel
152 * @returns A sharp instance that can be used to chain operations
153 */
154 extractChannel(channel: 0 | 1 | 2 | 3 | 'red' | 'green' | 'blue' | 'alpha'): Sharp;
155
156 /**
157 * Join one or more channels to the image. The meaning of the added channels depends on the output colourspace, set with toColourspace().
158 * By default the output image will be web-friendly sRGB, with additional channels interpreted as alpha channels. Channel ordering follows vips convention:
159 * - sRGB: 0: Red, 1: Green, 2: Blue, 3: Alpha.
160 * - CMYK: 0: Magenta, 1: Cyan, 2: Yellow, 3: Black, 4: Alpha.
161 *
162 * Buffers may be any of the image formats supported by sharp.
163 * For raw pixel input, the options object should contain a raw attribute, which follows the format of the attribute of the same name in the sharp() constructor.
164 * @param images one or more images (file paths, Buffers).
165 * @param options image options, see sharp() constructor.
166 * @throws {Error} Invalid parameters
167 * @returns A sharp instance that can be used to chain operations
168 */
169 joinChannel(images: string | Buffer | ArrayLike<string | Buffer>, options?: SharpOptions): Sharp;
170
171 /**
172 * Perform a bitwise boolean operation on all input image channels (bands) to produce a single channel output image.
173 * @param boolOp one of "and", "or" or "eor" to perform that bitwise operation, like the C logic operators &, | and ^ respectively.
174 * @throws {Error} Invalid parameters
175 * @returns A sharp instance that can be used to chain operations
176 */
177 bandbool(boolOp: keyof BoolEnum): Sharp;
178
179 //#endregion
180
181 //#region Color functions
182
183 /**
184 * Tint the image using the provided chroma while preserving the image luminance.
185 * An alpha channel may be present and will be unchanged by the operation.
186 * @param rgb Parsed by the color module to extract chroma values.
187 * @returns A sharp instance that can be used to chain operations
188 */
189 tint(rgb: Color): Sharp;
190
191 /**
192 * Convert to 8-bit greyscale; 256 shades of grey.
193 * This is a linear operation.
194 * If the input image is in a non-linear colour space such as sRGB, use gamma() with greyscale() for the best results.
195 * By default the output image will be web-friendly sRGB and contain three (identical) color channels.
196 * This may be overridden by other sharp operations such as toColourspace('b-w'), which will produce an output image containing one color channel.
197 * An alpha channel may be present, and will be unchanged by the operation.
198 * @param greyscale true to enable and false to disable (defaults to true)
199 * @returns A sharp instance that can be used to chain operations
200 */
201 greyscale(greyscale?: boolean): Sharp;
202
203 /**
204 * Alternative spelling of greyscale().
205 * @param grayscale true to enable and false to disable (defaults to true)
206 * @returns A sharp instance that can be used to chain operations
207 */
208 grayscale(grayscale?: boolean): Sharp;
209
210 /**
211 * Set the pipeline colourspace.
212 * The input image will be converted to the provided colourspace at the start of the pipeline.
213 * All operations will use this colourspace before converting to the output colourspace, as defined by toColourspace.
214 * This feature is experimental and has not yet been fully-tested with all operations.
215 *
216 * @param colourspace pipeline colourspace e.g. rgb16, scrgb, lab, grey16 ...
217 * @throws {Error} Invalid parameters
218 * @returns A sharp instance that can be used to chain operations
219 */
220 pipelineColourspace(colourspace?: string): Sharp;
221
222 /**
223 * Alternative spelling of pipelineColourspace
224 * @param colorspace pipeline colourspace e.g. rgb16, scrgb, lab, grey16 ...
225 * @throws {Error} Invalid parameters
226 * @returns A sharp instance that can be used to chain operations
227 */
228 pipelineColorspace(colorspace?: string): Sharp;
229
230 /**
231 * Set the output colourspace.
232 * By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
233 * @param colourspace output colourspace e.g. srgb, rgb, cmyk, lab, b-w ...
234 * @throws {Error} Invalid parameters
235 * @returns A sharp instance that can be used to chain operations
236 */
237 toColourspace(colourspace?: string): Sharp;
238
239 /**
240 * Alternative spelling of toColourspace().
241 * @param colorspace output colorspace e.g. srgb, rgb, cmyk, lab, b-w ...
242 * @throws {Error} Invalid parameters
243 * @returns A sharp instance that can be used to chain operations
244 */
245 toColorspace(colorspace: string): Sharp;
246
247 //#endregion
248
249 //#region Composite functions
250
251 /**
252 * Composite image(s) over the processed (resized, extracted etc.) image.
253 *
254 * The images to composite must be the same size or smaller than the processed image.
255 * If both `top` and `left` options are provided, they take precedence over `gravity`.
256 * @param images - Ordered list of images to composite
257 * @throws {Error} Invalid parameters
258 * @returns A sharp instance that can be used to chain operations
259 */
260 composite(images: OverlayOptions[]): Sharp;
261
262 //#endregion
263
264 //#region Input functions
265
266 /**
267 * Take a "snapshot" of the Sharp instance, returning a new instance.
268 * Cloned instances inherit the input of their parent instance.
269 * This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream.
270 * @returns A sharp instance that can be used to chain operations
271 */
272 clone(): Sharp;
273
274 /**
275 * Fast access to (uncached) image metadata without decoding any compressed image data.
276 * @returns A sharp instance that can be used to chain operations
277 */
278 metadata(callback: (err: Error, metadata: Metadata) => void): Sharp;
279
280 /**
281 * Fast access to (uncached) image metadata without decoding any compressed image data.
282 * @returns A promise that resolves with a metadata object
283 */
284 metadata(): Promise<Metadata>;
285
286 /**
287 * Access to pixel-derived image statistics for every channel in the image.
288 * @returns A sharp instance that can be used to chain operations
289 */
290 stats(callback: (err: Error, stats: Stats) => void): Sharp;
291
292 /**
293 * Access to pixel-derived image statistics for every channel in the image.
294 * @returns A promise that resolves with a stats object
295 */
296 stats(): Promise<Stats>;
297
298 //#endregion
299
300 //#region Operation functions
301
302 /**
303 * Rotate the output image by either an explicit angle or auto-orient based on the EXIF Orientation tag.
304 *
305 * If an angle is provided, it is converted to a valid positive degree rotation. For example, -450 will produce a 270deg rotation.
306 *
307 * When rotating by an angle other than a multiple of 90, the background colour can be provided with the background option.
308 *
309 * If no angle is provided, it is determined from the EXIF data. Mirroring is supported and may infer the use of a flip operation.
310 *
311 * The use of rotate implies the removal of the EXIF Orientation tag, if any.
312 *
313 * Method order is important when both rotating and extracting regions, for example rotate(x).extract(y) will produce a different result to extract(y).rotate(x).
314 * @param angle angle of rotation. (optional, default auto)
315 * @param options if present, is an Object with optional attributes.
316 * @throws {Error} Invalid parameters
317 * @returns A sharp instance that can be used to chain operations
318 */
319 rotate(angle?: number, options?: RotateOptions): Sharp;
320
321 /**
322 * Flip the image about the vertical Y axis. This always occurs after rotation, if any.
323 * The use of flip implies the removal of the EXIF Orientation tag, if any.
324 * @param flip true to enable and false to disable (defaults to true)
325 * @returns A sharp instance that can be used to chain operations
326 */
327 flip(flip?: boolean): Sharp;
328
329 /**
330 * Flop the image about the horizontal X axis. This always occurs after rotation, if any.
331 * The use of flop implies the removal of the EXIF Orientation tag, if any.
332 * @param flop true to enable and false to disable (defaults to true)
333 * @returns A sharp instance that can be used to chain operations
334 */
335 flop(flop?: boolean): Sharp;
336
337 /**
338 * Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
339 * You must provide an array of length 4 or a 2x2 affine transformation matrix.
340 * By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
341 * A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolator` Object e.g. `sharp.interpolator.nohalo`.
342 *
343 * In the case of a 2x2 matrix, the transform is:
344 * X = matrix[0, 0] * (x + idx) + matrix[0, 1] * (y + idy) + odx
345 * Y = matrix[1, 0] * (x + idx) + matrix[1, 1] * (y + idy) + ody
346 *
347 * where:
348 *
349 * x and y are the coordinates in input image.
350 * X and Y are the coordinates in output image.
351 * (0,0) is the upper left corner.
352 *
353 * @param matrix Affine transformation matrix, may either by a array of length four or a 2x2 matrix array
354 * @param options if present, is an Object with optional attributes.
355 *
356 * @returns A sharp instance that can be used to chain operations
357 */
358 affine(matrix: [number, number, number, number] | Matrix2x2, options?: AffineOptions): Sharp;
359
360 /**
361 * Sharpen the image.
362 * When used without parameters, performs a fast, mild sharpen of the output image.
363 * When a sigma is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.
364 * Fine-grained control over the level of sharpening in "flat" (m1) and "jagged" (m2) areas is available.
365 * @param options if present, is an Object with optional attributes
366 * @throws {Error} Invalid parameters
367 * @returns A sharp instance that can be used to chain operations
368 */
369 sharpen(options?: SharpenOptions): Sharp;
370
371 /**
372 * Sharpen the image.
373 * When used without parameters, performs a fast, mild sharpen of the output image.
374 * When a sigma is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.
375 * Fine-grained control over the level of sharpening in "flat" (m1) and "jagged" (m2) areas is available.
376 * @param sigma the sigma of the Gaussian mask, where sigma = 1 + radius / 2.
377 * @param flat the level of sharpening to apply to "flat" areas. (optional, default 1.0)
378 * @param jagged the level of sharpening to apply to "jagged" areas. (optional, default 2.0)
379 * @throws {Error} Invalid parameters
380 * @returns A sharp instance that can be used to chain operations
381 *
382 * @deprecated Use the object parameter `sharpen({sigma, m1, m2, x1, y2, y3})` instead
383 */
384 sharpen(sigma?: number, flat?: number, jagged?: number): Sharp;
385
386 /**
387 * Apply median filter. When used without parameters the default window is 3x3.
388 * @param size square mask size: size x size (optional, default 3)
389 * @throws {Error} Invalid parameters
390 * @returns A sharp instance that can be used to chain operations
391 */
392 median(size?: number): Sharp;
393
394 /**
395 * Blur the image.
396 * When used without parameters, performs a fast, mild blur of the output image.
397 * When a sigma is provided, performs a slower, more accurate Gaussian blur.
398 * When a boolean sigma is provided, ether blur mild or disable blur
399 * @param sigma a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where sigma = 1 + radius / 2.
400 * @throws {Error} Invalid parameters
401 * @returns A sharp instance that can be used to chain operations
402 */
403 blur(sigma?: number | boolean): Sharp;
404
405 /**
406 * Merge alpha transparency channel, if any, with background.
407 * @param flatten true to enable and false to disable (defaults to true)
408 * @returns A sharp instance that can be used to chain operations
409 */
410 flatten(flatten?: boolean | FlattenOptions): Sharp;
411
412 /**
413 * Apply a gamma correction by reducing the encoding (darken) pre-resize at a factor of 1/gamma then increasing the encoding (brighten) post-resize at a factor of gamma.
414 * This can improve the perceived brightness of a resized image in non-linear colour spaces.
415 * JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation when applying a gamma correction.
416 * Supply a second argument to use a different output gamma value, otherwise the first value is used in both cases.
417 * @param gamma value between 1.0 and 3.0. (optional, default 2.2)
418 * @param gammaOut value between 1.0 and 3.0. (optional, defaults to same as gamma)
419 * @throws {Error} Invalid parameters
420 * @returns A sharp instance that can be used to chain operations
421 */
422 gamma(gamma?: number, gammaOut?: number): Sharp;
423
424 /**
425 * Produce the "negative" of the image.
426 * @param negate true to enable and false to disable, or an object of options (defaults to true)
427 * @returns A sharp instance that can be used to chain operations
428 */
429 negate(negate?: boolean | NegateOptions): Sharp;
430
431 /**
432 * Enhance output image contrast by stretching its luminance to cover the full dynamic range.
433 * @param normalise true to enable and false to disable (defaults to true)
434 * @returns A sharp instance that can be used to chain operations
435 */
436 normalise(normalise?: boolean): Sharp;
437
438 /**
439 * Alternative spelling of normalise.
440 * @param normalize true to enable and false to disable (defaults to true)
441 * @returns A sharp instance that can be used to chain operations
442 */
443 normalize(normalize?: boolean): Sharp;
444
445 /**
446 * Perform contrast limiting adaptive histogram equalization (CLAHE)
447 *
448 * This will, in general, enhance the clarity of the image by bringing out
449 * darker details. Please read more about CLAHE here:
450 * https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE
451 *
452 * @param options clahe options
453 */
454 clahe(options: ClaheOptions): Sharp;
455
456 /**
457 * Convolve the image with the specified kernel.
458 * @param kernel the specified kernel
459 * @throws {Error} Invalid parameters
460 * @returns A sharp instance that can be used to chain operations
461 */
462 convolve(kernel: Kernel): Sharp;
463
464 /**
465 * Any pixel value greather than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
466 * @param threshold a value in the range 0-255 representing the level at which the threshold will be applied. (optional, default 128)
467 * @param options threshold options
468 * @throws {Error} Invalid parameters
469 * @returns A sharp instance that can be used to chain operations
470 */
471 threshold(threshold?: number, options?: ThresholdOptions): Sharp;
472
473 /**
474 * Perform a bitwise boolean operation with operand image.
475 * This operation creates an output image where each pixel is the result of the selected bitwise boolean operation between the corresponding pixels of the input images.
476 * @param operand Buffer containing image data or String containing the path to an image file.
477 * @param operator one of "and", "or" or "eor" to perform that bitwise operation, like the C logic operators &, | and ^ respectively.
478 * @param options describes operand when using raw pixel data.
479 * @throws {Error} Invalid parameters
480 * @returns A sharp instance that can be used to chain operations
481 */
482 boolean(operand: string | Buffer, operator: keyof BoolEnum, options?: { raw: Raw }): Sharp;
483
484 /**
485 * Apply the linear formula a * input + b to the image (levels adjustment)
486 * @param a multiplier (optional, default 1.0)
487 * @param b offset (optional, default 0.0)
488 * @throws {Error} Invalid parameters
489 * @returns A sharp instance that can be used to chain operations
490 */
491 linear(a?: number | number[] | null, b?: number | number[]): Sharp;
492
493 /**
494 * Recomb the image with the specified matrix.
495 * @param inputMatrix 3x3 Recombination matrix
496 * @throws {Error} Invalid parameters
497 * @returns A sharp instance that can be used to chain operations
498 */
499 recomb(inputMatrix: Matrix3x3): Sharp;
500
501 /**
502 * Transforms the image using brightness, saturation, hue rotation and lightness.
503 * Brightness and lightness both operate on luminance, with the difference being that brightness is multiplicative whereas lightness is additive.
504 * @param options describes the modulation
505 * @returns A sharp instance that can be used to chain operations
506 */
507 modulate(options?: {
508 brightness?: number | undefined;
509 saturation?: number | undefined;
510 hue?: number | undefined;
511 lightness?: number | undefined;
512 }): Sharp;
513
514 //#endregion
515
516 //#region Output functions
517
518 /**
519 * Write output image data to a file.
520 * If an explicit output format is not selected, it will be inferred from the extension, with JPEG, PNG, WebP, AVIF, TIFF, DZI, and libvips' V format supported.
521 * Note that raw pixel data is only supported for buffer output.
522 * @param fileOut The path to write the image data to.
523 * @param callback Callback function called on completion with two arguments (err, info). info contains the output image format, size (bytes), width, height and channels.
524 * @throws {Error} Invalid parameters
525 * @returns A sharp instance that can be used to chain operations
526 */
527 toFile(fileOut: string, callback: (err: Error, info: OutputInfo) => void): Sharp;
528
529 /**
530 * Write output image data to a file.
531 * @param fileOut The path to write the image data to.
532 * @throws {Error} Invalid parameters
533 * @returns A promise that fulfills with an object containing information on the resulting file
534 */
535 toFile(fileOut: string): Promise<OutputInfo>;
536
537 /**
538 * Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
539 * By default, the format will match the input image, except SVG input which becomes PNG output.
540 * @param callback Callback function called on completion with three arguments (err, buffer, info).
541 * @returns A sharp instance that can be used to chain operations
542 */
543 toBuffer(callback: (err: Error, buffer: Buffer, info: OutputInfo) => void): Sharp;
544
545 /**
546 * Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
547 * By default, the format will match the input image, except SVG input which becomes PNG output.
548 * @param options resolve options
549 * @param options.resolveWithObject Resolve the Promise with an Object containing data and info properties instead of resolving only with data.
550 * @returns A promise that resolves with the Buffer data.
551 */
552 toBuffer(options?: { resolveWithObject: false }): Promise<Buffer>;
553
554 /**
555 * Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
556 * By default, the format will match the input image, except SVG input which becomes PNG output.
557 * @param options resolve options
558 * @param options.resolveWithObject Resolve the Promise with an Object containing data and info properties instead of resolving only with data.
559 * @returns A promise that resolves with an object containing the Buffer data and an info object containing the output image format, size (bytes), width, height and channels
560 */
561 toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer; info: OutputInfo }>;
562
563 /**
564 * Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
565 * The default behaviour, when withMetadata is not used, is to strip all metadata and convert to the device-independent sRGB colour space.
566 * This will also convert to and add a web-friendly sRGB ICC profile.
567 * @param withMetadata
568 * @throws {Error} Invalid parameters.
569 */
570 withMetadata(withMetadata?: WriteableMetadata): Sharp;
571
572 /**
573 * Use these JPEG options for output image.
574 * @param options Output options.
575 * @throws {Error} Invalid options
576 * @returns A sharp instance that can be used to chain operations
577 */
578 jpeg(options?: JpegOptions): Sharp;
579
580 /**
581 * Use these JP2 (JPEG 2000) options for output image.
582 * @param options Output options.
583 * @throws {Error} Invalid options
584 * @returns A sharp instance that can be used to chain operations
585 */
586 jp2(options?: Jp2Options): Sharp;
587
588 /**
589 * Use these JPEG-XL (JXL) options for output image.
590 * This feature is experimental, please do not use in production systems.
591 * Requires libvips compiled with support for libjxl.
592 * The prebuilt binaries do not include this.
593 * Image metadata (EXIF, XMP) is unsupported.
594 * @param options Output options.
595 * @throws {Error} Invalid options
596 * @returns A sharp instance that can be used to chain operations
597 */
598 jxl(options?: JxlOptions): Sharp;
599
600 /**
601 * Use these PNG options for output image.
602 * PNG output is always full colour at 8 or 16 bits per pixel.
603 * Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
604 * @param options Output options.
605 * @throws {Error} Invalid options
606 * @returns A sharp instance that can be used to chain operations
607 */
608 png(options?: PngOptions): Sharp;
609
610 /**
611 * Use these WebP options for output image.
612 * @param options Output options.
613 * @throws {Error} Invalid options
614 * @returns A sharp instance that can be used to chain operations
615 */
616 webp(options?: WebpOptions): Sharp;
617
618 /**
619 * Use these GIF options for output image.
620 * Requires libvips compiled with support for ImageMagick or GraphicsMagick. The prebuilt binaries do not include this - see installing a custom libvips.
621 * @param options Output options.
622 * @throws {Error} Invalid options
623 * @returns A sharp instance that can be used to chain operations
624 */
625 gif(options?: GifOptions): Sharp;
626
627 /**
628 * Use these AVIF options for output image.
629 * Whilst it is possible to create AVIF images smaller than 16x16 pixels, most web browsers do not display these properly.
630 * @param options Output options.
631 * @throws {Error} Invalid options
632 * @returns A sharp instance that can be used to chain operations
633 */
634 avif(options?: AvifOptions): Sharp;
635
636 /**
637 * Use these HEIF options for output image.
638 * Support for patent-encumbered HEIC images requires the use of a globally-installed libvips compiled with support for libheif, libde265 and x265.
639 * @param options Output options.
640 * @throws {Error} Invalid options
641 * @returns A sharp instance that can be used to chain operations
642 */
643 heif(options?: HeifOptions): Sharp;
644
645 /**
646 * Use these TIFF options for output image.
647 * @param options Output options.
648 * @throws {Error} Invalid options
649 * @returns A sharp instance that can be used to chain operations
650 */
651 tiff(options?: TiffOptions): Sharp;
652
653 /**
654 * Force output to be raw, uncompressed uint8 pixel data.
655 * @param options Raw output options.
656 * @throws {Error} Invalid options
657 * @returns A sharp instance that can be used to chain operations
658 */
659 raw(options?: RawOptions): Sharp;
660
661 /**
662 * Force output to a given format.
663 * @param format a String or an Object with an 'id' attribute
664 * @param options output options
665 * @throws {Error} Unsupported format or options
666 * @returns A sharp instance that can be used to chain operations
667 */
668 toFormat(
669 format: keyof FormatEnum | AvailableFormatInfo,
670 options?:
671 | OutputOptions
672 | JpegOptions
673 | PngOptions
674 | WebpOptions
675 | AvifOptions
676 | HeifOptions
677 | JxlOptions
678 | GifOptions
679 | Jp2Options
680 | TiffOptions,
681 ): Sharp;
682
683 /**
684 * Use tile-based deep zoom (image pyramid) output.
685 * Set the format and options for tile images via the toFormat, jpeg, png or webp functions.
686 * Use a .zip or .szi file extension with toFile to write to a compressed archive file format.
687 *
688 * Warning: multiple sharp instances concurrently producing tile output can expose a possible race condition in some versions of libgsf.
689 * @param tile tile options
690 * @throws {Error} Invalid options
691 * @returns A sharp instance that can be used to chain operations
692 */
693 tile(tile?: TileOptions): Sharp;
694
695 /**
696 * Set a timeout for processing, in seconds. Use a value of zero to continue processing indefinitely, the default behaviour.
697 * The clock starts when libvips opens an input image for processing. Time spent waiting for a libuv thread to become available is not included.
698 * @param options Object with a `seconds` attribute between 0 and 3600 (number)
699 * @throws {Error} Invalid options
700 * @returns A sharp instance that can be used to chain operations
701 */
702 timeout(options: TimeoutOptions): Sharp;
703
704 //#endregion
705
706 //#region Resize functions
707
708 /**
709 * Resize image to width, height or width x height.
710 *
711 * When both a width and height are provided, the possible methods by which the image should fit these are:
712 * - cover: Crop to cover both provided dimensions (the default).
713 * - contain: Embed within both provided dimensions.
714 * - fill: Ignore the aspect ratio of the input and stretch to both provided dimensions.
715 * - inside: Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to both those specified.
716 * - outside: Preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to both those specified.
717 * Some of these values are based on the object-fit CSS property.
718 *
719 * When using a fit of cover or contain, the default position is centre. Other options are:
720 * - sharp.position: top, right top, right, right bottom, bottom, left bottom, left, left top.
721 * - sharp.gravity: north, northeast, east, southeast, south, southwest, west, northwest, center or centre.
722 * - 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.
723 *
724 * The experimental strategy-based approach resizes so one dimension is at its target length then repeatedly ranks edge regions,
725 * discarding the edge with the lowest score based on the selected strategy.
726 * - entropy: focus on the region with the highest Shannon entropy.
727 * - attention: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
728 *
729 * Possible interpolation kernels are:
730 * - nearest: Use nearest neighbour interpolation.
731 * - cubic: Use a Catmull-Rom spline.
732 * - lanczos2: Use a Lanczos kernel with a=2.
733 * - lanczos3: Use a Lanczos kernel with a=3 (the default).
734 *
735 * @param width pixels wide the resultant image should be. Use null or undefined to auto-scale the width to match the height.
736 * @param height pixels high the resultant image should be. Use null or undefined to auto-scale the height to match the width.
737 * @param options resize options
738 * @throws {Error} Invalid parameters
739 * @returns A sharp instance that can be used to chain operations
740 */
741 resize(width?: number | null, height?: number | null, options?: ResizeOptions): Sharp;
742
743 /**
744 * Shorthand for resize(null, null, options);
745 *
746 * @param options resize options
747 * @throws {Error} Invalid parameters
748 * @returns A sharp instance that can be used to chain operations
749 */
750 resize(options: ResizeOptions): Sharp;
751
752 /**
753 * Extends/pads the edges of the image with the provided background colour.
754 * This operation will always occur after resizing and extraction, if any.
755 * @param extend single pixel count to add to all edges or an Object with per-edge counts
756 * @throws {Error} Invalid parameters
757 * @returns A sharp instance that can be used to chain operations
758 */
759 extend(extend: number | ExtendOptions): Sharp;
760
761 /**
762 * Extract a region of the image.
763 * - Use extract() before resize() for pre-resize extraction.
764 * - Use extract() after resize() for post-resize extraction.
765 * - Use extract() before and after for both.
766 *
767 * @param region The region to extract
768 * @throws {Error} Invalid parameters
769 * @returns A sharp instance that can be used to chain operations
770 */
771 extract(region: Region): Sharp;
772
773 /**
774 * Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.
775 * Images with an alpha channel will use the combined bounding box of alpha and non-alpha channels.
776 * The info response Object will contain trimOffsetLeft and trimOffsetTop properties.
777 * @param trim The specific background colour to trim, the threshold for doing so or an Object with both.
778 * @throws {Error} Invalid parameters
779 * @returns A sharp instance that can be used to chain operations
780 */
781 trim(trim?: string | number | TrimOptions): Sharp;
782
783 //#endregion
784 }
785
786 interface SharpOptions {
787 /**
788 * When to abort processing of invalid pixel data, one of (in order of sensitivity):
789 * 'none' (least), 'truncated', 'error' or 'warning' (most), highers level imply lower levels, invalid metadata will always abort. (optional, default 'warning')
790 */
791 failOn?: FailOnOptions | undefined;
792 /**
793 * By default halt processing and raise an error when loading invalid images.
794 * Set this flag to false if you'd rather apply a "best effort" to decode images,
795 * even if the data is corrupt or invalid. (optional, default true)
796 *
797 * @deprecated Use `failOn` instead
798 */
799 failOnError?: boolean | undefined;
800 /**
801 * Do not process input images where the number of pixels (width x height) exceeds this limit.
802 * Assumes image dimensions contained in the input metadata can be trusted.
803 * An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). (optional, default 268402689)
804 */
805 limitInputPixels?: number | boolean | undefined;
806 /** Set this to true to remove safety features that help prevent memory exhaustion (SVG, PNG). (optional, default false) */
807 unlimited?: boolean | undefined;
808 /** Set this to true to use sequential rather than random access where possible. This can reduce memory usage and might improve performance on some systems. (optional, default false) */
809 sequentialRead?: boolean | undefined;
810 /** Number representing the DPI for vector images in the range 1 to 100000. (optional, default 72) */
811 density?: number | undefined;
812 /** Number of pages to extract for multi-page input (GIF, TIFF, PDF), use -1 for all pages */
813 pages?: number | undefined;
814 /** Page number to start extracting from for multi-page input (GIF, TIFF, PDF), zero based. (optional, default 0) */
815 page?: number | undefined;
816 /** subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image. (optional, default -1) */
817 subifd?: number | undefined;
818 /** Level to extract from a multi-level input (OpenSlide), zero based. (optional, default 0) */
819 level?: number | undefined;
820 /** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default false) */
821 animated?: boolean | undefined;
822 /** Describes raw pixel input image data. See raw() for pixel ordering. */
823 raw?: CreateRaw | undefined;
824 /** Describes a new image to be created. */
825 create?: Create | undefined;
826 /** Describes a new text image to be created. */
827 text?: CreateText | undefined;
828 }
829
830 interface CacheOptions {
831 /** Is the maximum memory in MB to use for this cache (optional, default 50) */
832 memory?: number | undefined;
833 /** Is the maximum number of files to hold open (optional, default 20) */
834 files?: number | undefined;
835 /** Is the maximum number of operations to cache (optional, default 100) */
836 items?: number | undefined;
837 }
838
839 interface TimeoutOptions {
840 /** Number of seconds after which processing will be stopped (default 0, eg disabled) */
841 seconds: number;
842 }
843
844 interface SharpCounters {
845 /** The number of tasks this module has queued waiting for libuv to provide a worker thread from its pool. */
846 queue: number;
847 /** The number of resize tasks currently being processed. */
848 process: number;
849 }
850
851 interface Raw {
852 width: number;
853 height: number;
854 channels: 1 | 2 | 3 | 4;
855 }
856
857 interface CreateRaw extends Raw {
858 /** Specifies that the raw input has already been premultiplied, set to true to avoid sharp premultiplying the image. (optional, default false) */
859 premultiplied?: boolean | undefined;
860 }
861
862 interface Create {
863 /** Number of pixels wide. */
864 width: number;
865 /** Number of pixels high. */
866 height: number;
867 /** Number of bands e.g. 3 for RGB, 4 for RGBA */
868 channels: Channels;
869 /** Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. */
870 background: Color;
871 /** Describes a noise to be created. */
872 noise?: Noise | undefined;
873 }
874
875 interface CreateText {
876 /** Text to render as a UTF-8 string. It can contain Pango markup, for example `<i>Le</i>Monde`. */
877 text: string;
878 /** Font name to render with. */
879 font?: string;
880 /** Absolute filesystem path to a font file that can be used by `font`. */
881 fontfile?: string;
882 /** Integral number of pixels to word-wrap at. Lines of text wider than this will be broken at word boundaries. (optional, default `0`) */
883 width?: number;
884 /**
885 * Integral number of pixels high. When defined, `dpi` will be ignored and the text will automatically fit the pixel resolution
886 * defined by `width` and `height`. Will be ignored if `width` is not specified or set to 0. (optional, default `0`)
887 */
888 height?: number;
889 /** Text alignment ('left', 'centre', 'center', 'right'). (optional, default 'left') */
890 align?: TextAlign;
891 /** Set this to true to apply justification to the text. (optional, default `false`) */
892 justify?: boolean;
893 /** The resolution (size) at which to render the text. Does not take effect if `height` is specified. (optional, default `72`) */
894 dpi?: number;
895 /**
896 * Set this to true to enable RGBA output. This is useful for colour emoji rendering,
897 * or support for pango markup features like `<span foreground="red">Red!</span>`. (optional, default `false`)
898 */
899 rgba?: boolean;
900 /** Text line height in points. Will use the font line height if none is specified. (optional, default `0`) */
901 spacing?: number;
902 }
903
904 interface WriteableMetadata {
905 /** Value between 1 and 8, used to update the EXIF Orientation tag. */
906 orientation?: number | undefined;
907 /** Filesystem path to output ICC profile, defaults to sRGB. */
908 icc?: string | undefined;
909 /** Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data. (optional, default {}) */
910 exif?: Record<string, any> | undefined;
911 /** Number of pixels per inch (DPI) */
912 density?: number | undefined;
913 }
914
915 interface Metadata {
916 /** Number value of the EXIF Orientation header, if present */
917 orientation?: number | undefined;
918 /** Name of decoder used to decompress image data e.g. jpeg, png, webp, gif, svg */
919 format?: keyof FormatEnum | undefined;
920 /** Total size of image in bytes, for Stream and Buffer input only */
921 size?: number | undefined;
922 /** Number of pixels wide (EXIF orientation is not taken into consideration) */
923 width?: number | undefined;
924 /** Number of pixels high (EXIF orientation is not taken into consideration) */
925 height?: number | undefined;
926 /** Name of colour space interpretation */
927 space?: keyof ColourspaceEnum | undefined;
928 /** Number of bands e.g. 3 for sRGB, 4 for CMYK */
929 channels?: Channels | undefined;
930 /** Name of pixel depth format e.g. uchar, char, ushort, float ... */
931 depth?: string | undefined;
932 /** Number of pixels per inch (DPI), if present */
933 density?: number | undefined;
934 /** 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 */
935 chromaSubsampling: string;
936 /** Boolean indicating whether the image is interlaced using a progressive scan */
937 isProgressive?: boolean | undefined;
938 /** Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP */
939 pages?: number | undefined;
940 /** Number of pixels high each page in a multi-page image will be. */
941 pageHeight?: number | undefined;
942 /** Number of times to loop an animated image, zero refers to a continuous loop. */
943 loop?: number | undefined;
944 /** Delay in ms between each page in an animated image, provided as an array of integers. */
945 delay?: number[] | undefined;
946 /** Number of the primary page in a HEIF image */
947 pagePrimary?: number | undefined;
948 /** Boolean indicating the presence of an embedded ICC profile */
949 hasProfile?: boolean | undefined;
950 /** Boolean indicating the presence of an alpha transparency channel */
951 hasAlpha?: boolean | undefined;
952 /** Buffer containing raw EXIF data, if present */
953 exif?: Buffer | undefined;
954 /** Buffer containing raw ICC profile data, if present */
955 icc?: Buffer | undefined;
956 /** Buffer containing raw IPTC data, if present */
957 iptc?: Buffer | undefined;
958 /** Buffer containing raw XMP data, if present */
959 xmp?: Buffer | undefined;
960 /** Buffer containing raw TIFFTAG_PHOTOSHOP data, if present */
961 tifftagPhotoshop?: Buffer | undefined;
962 /** The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC) */
963 compression?: 'av1' | 'hevc';
964 /** Default background colour, if present, for PNG (bKGD) and GIF images, either an RGB Object or a single greyscale value */
965 background?: { r: number; g: number; b: number } | number;
966 /** Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide */
967 levels?: LevelMetadata[] | undefined;
968 /** Number of Sub Image File Directories in an OME-TIFF image */
969 subifds?: number | undefined;
970 /** The unit of resolution (density) */
971 resolutionUnit?: 'inch' | 'cm' | undefined;
972 }
973
974 interface LevelMetadata {
975 width: number;
976 height: number;
977 }
978
979 interface Stats {
980 /** Array of channel statistics for each channel in the image. */
981 channels: ChannelStats[];
982 /** Value to identify if the image is opaque or transparent, based on the presence and use of alpha channel */
983 isOpaque: boolean;
984 /** Histogram-based estimation of greyscale entropy, discarding alpha channel if any (experimental) */
985 entropy: number;
986 /** Estimation of greyscale sharpness based on the standard deviation of a Laplacian convolution, discarding alpha channel if any (experimental) */
987 sharpness: number;
988 /** Object containing most dominant sRGB colour based on a 4096-bin 3D histogram (experimental) */
989 dominant: { r: number; g: number; b: number };
990 }
991
992 interface ChannelStats {
993 /** minimum value in the channel */
994 min: number;
995 /** maximum value in the channel */
996 max: number;
997 /** sum of all values in a channel */
998 sum: number;
999 /** sum of squared values in a channel */
1000 squaresSum: number;
1001 /** mean of the values in a channel */
1002 mean: number;
1003 /** standard deviation for the values in a channel */
1004 stdev: number;
1005 /** x-coordinate of one of the pixel where the minimum lies */
1006 minX: number;
1007 /** y-coordinate of one of the pixel where the minimum lies */
1008 minY: number;
1009 /** x-coordinate of one of the pixel where the maximum lies */
1010 maxX: number;
1011 /** y-coordinate of one of the pixel where the maximum lies */
1012 maxY: number;
1013 }
1014
1015 interface OutputOptions {
1016 /** Force format output, otherwise attempt to use input format (optional, default true) */
1017 force?: boolean | undefined;
1018 }
1019
1020 interface JpegOptions extends OutputOptions {
1021 /** Quality, integer 1-100 (optional, default 80) */
1022 quality?: number | undefined;
1023 /** Use progressive (interlace) scan (optional, default false) */
1024 progressive?: boolean | undefined;
1025 /** Set to '4:4:4' to prevent chroma subsampling when quality <= 90 (optional, default '4:2:0') */
1026 chromaSubsampling?: string | undefined;
1027 /** Apply trellis quantisation (optional, default false) */
1028 trellisQuantisation?: boolean | undefined;
1029 /** Apply overshoot deringing (optional, default false) */
1030 overshootDeringing?: boolean | undefined;
1031 /** Optimise progressive scans, forces progressive (optional, default false) */
1032 optimiseScans?: boolean | undefined;
1033 /** Alternative spelling of optimiseScans (optional, default false) */
1034 optimizeScans?: boolean | undefined;
1035 /** Optimise Huffman coding tables (optional, default true) */
1036 optimiseCoding?: boolean | undefined;
1037 /** Alternative spelling of optimiseCoding (optional, default true) */
1038 optimizeCoding?: boolean | undefined;
1039 /** Quantization table to use, integer 0-8 (optional, default 0) */
1040 quantisationTable?: number | undefined;
1041 /** Alternative spelling of quantisationTable (optional, default 0) */
1042 quantizationTable?: number | undefined;
1043 /** Use mozjpeg defaults (optional, default false) */
1044 mozjpeg?: boolean | undefined;
1045 }
1046
1047 interface Jp2Options extends OutputOptions {
1048 /** Quality, integer 1-100 (optional, default 80) */
1049 quality?: number;
1050 /** Use lossless compression mode (optional, default false) */
1051 lossless?: boolean;
1052 /** Horizontal tile size (optional, default 512) */
1053 tileWidth?: number;
1054 /** Vertical tile size (optional, default 512) */
1055 tileHeight?: number;
1056 /** Set to '4:2:0' to enable chroma subsampling (optional, default '4:4:4') */
1057 chromaSubsampling?: '4:4:4' | '4:2:0';
1058 }
1059
1060 interface JxlOptions extends OutputOptions {
1061 /** Maximum encoding error, between 0 (highest quality) and 15 (lowest quality) (optional, default 1.0) */
1062 distance?: number;
1063 /** Calculate distance based on JPEG-like quality, between 1 and 100, overrides distance if specified */
1064 quality?: number;
1065 /** Target decode speed tier, between 0 (highest quality) and 4 (lowest quality) (optional, default 0) */
1066 decodingTier?: number;
1067 /** Use lossless compression (optional, default false) */
1068 lossless?: boolean;
1069 /** CPU effort, between 3 (fastest) and 9 (slowest) (optional, default 7) */
1070 effort?: number | undefined;
1071 }
1072
1073 interface WebpOptions extends OutputOptions, AnimationOptions {
1074 /** Quality, integer 1-100 (optional, default 80) */
1075 quality?: number | undefined;
1076 /** Quality of alpha layer, number from 0-100 (optional, default 100) */
1077 alphaQuality?: number | undefined;
1078 /** Use lossless compression mode (optional, default false) */
1079 lossless?: boolean | undefined;
1080 /** Use near_lossless compression mode (optional, default false) */
1081 nearLossless?: boolean | undefined;
1082 /** Use high quality chroma subsampling (optional, default false) */
1083 smartSubsample?: boolean | undefined;
1084 /** Level of CPU effort to reduce file size, integer 0-6 (optional, default 4) */
1085 effort?: number | undefined;
1086 /** Prevent use of animation key frames to minimise file size (slow) (optional, default false) */
1087 minSize?: number;
1088 /** Allow mixture of lossy and lossless animation frames (slow) (optional, default false) */
1089 mixed?: boolean;
1090 }
1091
1092 interface AvifOptions extends OutputOptions {
1093 /** quality, integer 1-100 (optional, default 50) */
1094 quality?: number | undefined;
1095 /** use lossless compression (optional, default false) */
1096 lossless?: boolean | undefined;
1097 /** Level of CPU effort to reduce file size, between 0 (fastest) and 9 (slowest) (optional, default 4) */
1098 effort?: number | undefined;
1099 /** set to '4:2:0' to use chroma subsampling, requires libvips v8.11.0 (optional, default '4:4:4') */
1100 chromaSubsampling?: string | undefined;
1101 }
1102
1103 interface HeifOptions extends OutputOptions {
1104 /** quality, integer 1-100 (optional, default 50) */
1105 quality?: number | undefined;
1106 /** compression format: av1, hevc (optional, default 'av1') */
1107 compression?: 'av1' | 'hevc' | undefined;
1108 /** use lossless compression (optional, default false) */
1109 lossless?: boolean | undefined;
1110 /** Level of CPU effort to reduce file size, between 0 (fastest) and 9 (slowest) (optional, default 4) */
1111 effort?: number | undefined;
1112 /** set to '4:2:0' to use chroma subsampling (optional, default '4:4:4') */
1113 chromaSubsampling?: string | undefined;
1114 }
1115
1116 interface GifOptions extends OutputOptions, AnimationOptions {
1117 /** Always generate new palettes (slow), re-use existing by default (optional, default false) */
1118 reoptimise?: boolean | undefined;
1119 /** Alternative spelling of "reoptimise" (optional, default false) */
1120 reoptimize?: boolean | undefined;
1121 /** Maximum number of palette entries, including transparency, between 2 and 256 (optional, default 256) */
1122 colours?: number | undefined;
1123 /** Alternative spelling of "colours". Maximum number of palette entries, including transparency, between 2 and 256 (optional, default 256) */
1124 colors?: number | undefined;
1125 /** Level of CPU effort to reduce file size, between 1 (fastest) and 10 (slowest) (optional, default 7) */
1126 effort?: number | undefined;
1127 /** Level of Floyd-Steinberg error diffusion, between 0 (least) and 1 (most) (optional, default 1.0) */
1128 dither?: number | undefined;
1129 /** Maximum inter-frame error for transparency, between 0 (lossless) and 32 (optional, default 0) */
1130 interFrameMaxError?: number;
1131 /** Maximum inter-palette error for palette reuse, between 0 and 256 (optional, default 3) */
1132 interPaletteMaxError?: number;
1133 }
1134
1135 interface TiffOptions extends OutputOptions {
1136 /** Quality, integer 1-100 (optional, default 80) */
1137 quality?: number | undefined;
1138 /** Compression options: none, jpeg, deflate, packbits, ccittfax4, lzw, webp, zstd, jp2k (optional, default 'jpeg') */
1139 compression?: string | undefined;
1140 /** Compression predictor options: none, horizontal, float (optional, default 'horizontal') */
1141 predictor?: string | undefined;
1142 /** Write an image pyramid (optional, default false) */
1143 pyramid?: boolean | undefined;
1144 /** Write a tiled tiff (optional, default false) */
1145 tile?: boolean | undefined;
1146 /** Horizontal tile size (optional, default 256) */
1147 tileWidth?: number | undefined;
1148 /** Vertical tile size (optional, default 256) */
1149 tileHeight?: number | undefined;
1150 /** Horizontal resolution in pixels/mm (optional, default 1.0) */
1151 xres?: number | undefined;
1152 /** Vertical resolution in pixels/mm (optional, default 1.0) */
1153 yres?: number | undefined;
1154 /** Reduce bitdepth to 1, 2 or 4 bit (optional, default 8) */
1155 bitdepth?: 1 | 2 | 4 | 8 | undefined;
1156 /** Resolution unit options: inch, cm (optional, default 'inch') */
1157 resolutionUnit?: 'inch' | 'cm' | undefined;
1158 }
1159
1160 interface PngOptions extends OutputOptions {
1161 /** Use progressive (interlace) scan (optional, default false) */
1162 progressive?: boolean | undefined;
1163 /** zlib compression level, 0-9 (optional, default 6) */
1164 compressionLevel?: number | undefined;
1165 /** Use adaptive row filtering (optional, default false) */
1166 adaptiveFiltering?: boolean | undefined;
1167 /** Use the lowest number of colours needed to achieve given quality (optional, default `100`) */
1168 quality?: number | undefined;
1169 /** Level of CPU effort to reduce file size, between 1 (fastest) and 10 (slowest), sets palette to true (optional, default 7) */
1170 effort?: number | undefined;
1171 /** Quantise to a palette-based image with alpha transparency support (optional, default false) */
1172 palette?: boolean | undefined;
1173 /** Maximum number of palette entries (optional, default 256) */
1174 colours?: number | undefined;
1175 /** Alternative Spelling of "colours". Maximum number of palette entries (optional, default 256) */
1176 colors?: number | undefined;
1177 /** Level of Floyd-Steinberg error diffusion (optional, default 1.0) */
1178 dither?: number | undefined;
1179 }
1180
1181 interface RotateOptions {
1182 /** parsed by the color module to extract values for red, green, blue and alpha. (optional, default "#000000") */
1183 background?: Color | undefined;
1184 }
1185
1186 interface FlattenOptions {
1187 /** background colour, parsed by the color module, defaults to black. (optional, default {r:0,g:0,b:0}) */
1188 background?: Color | undefined;
1189 }
1190
1191 interface NegateOptions {
1192 /** whether or not to negate any alpha channel. (optional, default true) */
1193 alpha?: boolean | undefined;
1194 }
1195
1196 interface ResizeOptions {
1197 /** Alternative means of specifying width. If both are present this takes priority. */
1198 width?: number | undefined;
1199 /** Alternative means of specifying height. If both are present this takes priority. */
1200 height?: number | undefined;
1201 /** How the image should be resized to fit both provided dimensions, one of cover, contain, fill, inside or outside. (optional, default 'cover') */
1202 fit?: keyof FitEnum | undefined;
1203 /** Position, gravity or strategy to use when fit is cover or contain. (optional, default 'centre') */
1204 position?: number | string | undefined;
1205 /** 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}) */
1206 background?: Color | undefined;
1207 /** The kernel to use for image reduction. (optional, default 'lanczos3') */
1208 kernel?: keyof KernelEnum | undefined;
1209 /** Do not enlarge if the width or height are already less than the specified dimensions, equivalent to GraphicsMagick's > geometry option. (optional, default false) */
1210 withoutEnlargement?: boolean | undefined;
1211 /** Do not reduce if the width or height are already greater than the specified dimensions, equivalent to GraphicsMagick's < geometry option. (optional, default false) */
1212 withoutReduction?: boolean | undefined;
1213 /** Take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern on some images. (optional, default true) */
1214 fastShrinkOnLoad?: boolean | undefined;
1215 }
1216
1217 interface Region {
1218 /** zero-indexed offset from left edge */
1219 left: number;
1220 /** zero-indexed offset from top edge */
1221 top: number;
1222 /** dimension of extracted image */
1223 width: number;
1224 /** dimension of extracted image */
1225 height: number;
1226 }
1227
1228 interface Noise {
1229 /** type of generated noise, currently only gaussian is supported. */
1230 type?: 'gaussian' | undefined;
1231 /** mean of pixels in generated noise. */
1232 mean?: number | undefined;
1233 /** standard deviation of pixels in generated noise. */
1234 sigma?: number | undefined;
1235 }
1236
1237 interface ExtendOptions {
1238 /** single pixel count to top edge (optional, default 0) */
1239 top?: number | undefined;
1240 /** single pixel count to left edge (optional, default 0) */
1241 left?: number | undefined;
1242 /** single pixel count to bottom edge (optional, default 0) */
1243 bottom?: number | undefined;
1244 /** single pixel count to right edge (optional, default 0) */
1245 right?: number | undefined;
1246 /** background colour, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
1247 background?: Color | undefined;
1248 }
1249
1250 interface TrimOptions {
1251 /** background colour, parsed by the color module, defaults to that of the top-left pixel. (optional) */
1252 background?: Color | undefined;
1253 /** the allowed difference from the above colour, a positive number. (optional, default `10`) */
1254 threshold?: number | undefined;
1255 }
1256
1257 interface RawOptions {
1258 depth?: 'char' | 'uchar' | 'short' | 'ushort' | 'int' | 'uint' | 'float' | 'complex' | 'double' | 'dpcomplex';
1259 }
1260
1261 /** 3 for sRGB, 4 for CMYK */
1262 type Channels = 3 | 4;
1263
1264 interface RGBA {
1265 r?: number | undefined;
1266 g?: number | undefined;
1267 b?: number | undefined;
1268 alpha?: number | undefined;
1269 }
1270
1271 type Color = string | RGBA;
1272
1273 interface Kernel {
1274 /** width of the kernel in pixels. */
1275 width: number;
1276 /** height of the kernel in pixels. */
1277 height: number;
1278 /** Array of length width*height containing the kernel values. */
1279 kernel: ArrayLike<number>;
1280 /** the scale of the kernel in pixels. (optional, default sum) */
1281 scale?: number | undefined;
1282 /** the offset of the kernel in pixels. (optional, default 0) */
1283 offset?: number | undefined;
1284 }
1285
1286 interface ClaheOptions {
1287 /** width of the region */
1288 width: number;
1289 /** height of the region */
1290 height: number;
1291 /** 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) */
1292 maxSlope?: number | undefined;
1293 }
1294
1295 interface ThresholdOptions {
1296 /** convert to single channel greyscale. (optional, default true) */
1297 greyscale?: boolean | undefined;
1298 /** alternative spelling for greyscale. (optional, default true) */
1299 grayscale?: boolean | undefined;
1300 }
1301
1302 interface OverlayOptions {
1303 /** Buffer containing image data, String containing the path to an image file, or Create object */
1304 input?: string | Buffer | { create: Create } | { text: CreateText } | undefined;
1305 /** how to blend this image with the image below. (optional, default `'over'`) */
1306 blend?: Blend | undefined;
1307 /** gravity at which to place the overlay. (optional, default 'centre') */
1308 gravity?: Gravity | undefined;
1309 /** the pixel offset from the top edge. */
1310 top?: number | undefined;
1311 /** the pixel offset from the left edge. */
1312 left?: number | undefined;
1313 /** set to true to repeat the overlay image across the entire image with the given gravity. (optional, default false) */
1314 tile?: boolean | undefined;
1315 /** number representing the DPI for vector overlay image. (optional, default 72) */
1316 density?: number | undefined;
1317 /** describes overlay when using raw pixel data. */
1318 raw?: Raw | undefined;
1319 /** Set to true to avoid premultipling the image below. Equivalent to the --premultiplied vips option. */
1320 premultiplied?: boolean | undefined;
1321 /** Set to true to read all frames/pages of an animated image. (optional, default false). */
1322 animated?: boolean | undefined;
1323 /**
1324 * When to abort processing of invalid pixel data, one of (in order of sensitivity):
1325 * 'none' (least), 'truncated', 'error' or 'warning' (most), highers level imply lower levels, invalid metadata will always abort. (optional, default 'warning')
1326 */
1327 failOn?: FailOnOptions | undefined;
1328 /**
1329 * Do not process input images where the number of pixels (width x height) exceeds this limit.
1330 * Assumes image dimensions contained in the input metadata can be trusted.
1331 * An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). (optional, default 268402689)
1332 */
1333 limitInputPixels?: number | boolean | undefined;
1334 }
1335
1336 interface TileOptions {
1337 /** Tile size in pixels, a value between 1 and 8192. (optional, default 256) */
1338 size?: number | undefined;
1339 /** Tile overlap in pixels, a value between 0 and 8192. (optional, default 0) */
1340 overlap?: number | undefined;
1341 /** Tile angle of rotation, must be a multiple of 90. (optional, default 0) */
1342 angle?: number | undefined;
1343 /** background colour, parsed by the color module, defaults to white without transparency. (optional, default {r:255,g:255,b:255,alpha:1}) */
1344 background?: string | RGBA | undefined;
1345 /** How deep to make the pyramid, possible values are "onepixel", "onetile" or "one" (default based on layout) */
1346 depth?: string | undefined;
1347 /** Threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images */
1348 skipBlanks?: number | undefined;
1349 /** Tile container, with value fs (filesystem) or zip (compressed file). (optional, default 'fs') */
1350 container?: TileContainer | undefined;
1351 /** Filesystem layout, possible values are dz, iiif, iiif3, zoomify or google. (optional, default 'dz') */
1352 layout?: TileLayout | undefined;
1353 /** Centre image in tile. (optional, default false) */
1354 centre?: boolean | undefined;
1355 /** Alternative spelling of centre. (optional, default false) */
1356 center?: boolean | undefined;
1357 /** When layout is iiif/iiif3, sets the @id/id attribute of info.json (optional, default 'https://example.com/iiif') */
1358 id?: string | undefined;
1359 /** The name of the directory within the zip file when container is `zip`. */
1360 basename?: string | undefined;
1361 }
1362
1363 interface AnimationOptions {
1364 /** Number of animation iterations, a value between 0 and 65535. Use 0 for infinite animation. (optional, default 0) */
1365 loop?: number | undefined;
1366 /** delay(s) between animation frames (in milliseconds), each value between 0 and 65535. (optional) */
1367 delay?: number | number[] | undefined;
1368 }
1369
1370 interface SharpenOptions {
1371 /** The sigma of the Gaussian mask, where sigma = 1 + radius / 2, between 0.000001 and 10000 */
1372 sigma: number;
1373 /** The level of sharpening to apply to "flat" areas, between 0 and 1000000 (optional, default 1.0) */
1374 m1?: number | undefined;
1375 /** The level of sharpening to apply to "jagged" areas, between 0 and 1000000 (optional, default 2.0) */
1376 m2?: number | undefined;
1377 /** Threshold between "flat" and "jagged", between 0 and 1000000 (optional, default 2.0) */
1378 x1?: number | undefined;
1379 /** Maximum amount of brightening, between 0 and 1000000 (optional, default 10.0) */
1380 y2?: number | undefined;
1381 /** Maximum amount of darkening, between 0 and 1000000 (optional, default 20.0) */
1382 y3?: number | undefined;
1383 }
1384
1385 interface AffineOptions {
1386 /** Parsed by the color module to extract values for red, green, blue and alpha. (optional, default "#000000") */
1387 background?: string | object | undefined;
1388 /** Input horizontal offset (optional, default 0) */
1389 idx?: number | undefined;
1390 /** Input vertical offset (optional, default 0) */
1391 idy?: number | undefined;
1392 /** Output horizontal offset (optional, default 0) */
1393 odx?: number | undefined;
1394 /** Output horizontal offset (optional, default 0) */
1395 ody?: number | undefined;
1396 /** Interpolator (optional, default sharp.interpolators.bicubic) */
1397 interpolator?: Interpolators[keyof Interpolators] | undefined;
1398 }
1399
1400 interface OutputInfo {
1401 format: string;
1402 size: number;
1403 width: number;
1404 height: number;
1405 channels: 1 | 2 | 3 | 4;
1406 /** indicating if premultiplication was used */
1407 premultiplied: boolean;
1408 /** Only defined when using a crop strategy */
1409 cropOffsetLeft?: number | undefined;
1410 /** Only defined when using a crop strategy */
1411 cropOffsetTop?: number | undefined;
1412 /** Only defined when using a trim method */
1413 trimOffsetLeft?: number | undefined;
1414 /** Only defined when using a trim method */
1415 trimOffsetTop?: number | undefined;
1416 /** DPI the font was rendered at, only defined when using `text` input */
1417 textAutofitDpi?: number | undefined;
1418 }
1419
1420 interface AvailableFormatInfo {
1421 id: string;
1422 input: { file: boolean; buffer: boolean; stream: boolean; fileSuffix?: string[] };
1423 output: { file: boolean; buffer: boolean; stream: boolean; alias?: string[] };
1424 }
1425
1426 interface FitEnum {
1427 contain: 'contain';
1428 cover: 'cover';
1429 fill: 'fill';
1430 inside: 'inside';
1431 outside: 'outside';
1432 }
1433
1434 interface KernelEnum {
1435 nearest: 'nearest';
1436 cubic: 'cubic';
1437 mitchell: 'mitchell';
1438 lanczos2: 'lanczos2';
1439 lanczos3: 'lanczos3';
1440 }
1441
1442 interface BoolEnum {
1443 and: 'and';
1444 or: 'or';
1445 eor: 'eor';
1446 }
1447
1448 interface ColourspaceEnum {
1449 multiband: string;
1450 'b-w': string;
1451 bw: string;
1452 cmyk: string;
1453 srgb: string;
1454 }
1455
1456 type FailOnOptions = 'none' | 'truncated' | 'error' | 'warning';
1457
1458 type TextAlign = 'left' | 'centre' | 'center' | 'right';
1459
1460 type TileContainer = 'fs' | 'zip';
1461
1462 type TileLayout = 'dz' | 'iiif' | 'iiif3' | 'zoomify' | 'google';
1463
1464 type Blend =
1465 | 'clear'
1466 | 'source'
1467 | 'over'
1468 | 'in'
1469 | 'out'
1470 | 'atop'
1471 | 'dest'
1472 | 'dest-over'
1473 | 'dest-in'
1474 | 'dest-out'
1475 | 'dest-atop'
1476 | 'xor'
1477 | 'add'
1478 | 'saturate'
1479 | 'multiply'
1480 | 'screen'
1481 | 'overlay'
1482 | 'darken'
1483 | 'lighten'
1484 | 'color-dodge'
1485 | 'colour-dodge'
1486 | 'color-burn'
1487 | 'colour-burn'
1488 | 'hard-light'
1489 | 'soft-light'
1490 | 'difference'
1491 | 'exclusion';
1492
1493 type Gravity = number | string;
1494
1495 interface GravityEnum {
1496 north: number;
1497 northeast: number;
1498 southeast: number;
1499 south: number;
1500 southwest: number;
1501 west: number;
1502 northwest: number;
1503 east: number;
1504 center: number;
1505 centre: number;
1506 }
1507
1508 interface StrategyEnum {
1509 entropy: number;
1510 attention: number;
1511 }
1512
1513 interface FormatEnum {
1514 avif: AvailableFormatInfo;
1515 dz: AvailableFormatInfo;
1516 fits: AvailableFormatInfo;
1517 gif: AvailableFormatInfo;
1518 heif: AvailableFormatInfo;
1519 input: AvailableFormatInfo;
1520 jpeg: AvailableFormatInfo;
1521 jpg: AvailableFormatInfo;
1522 jp2: AvailableFormatInfo;
1523 jxl: AvailableFormatInfo;
1524 magick: AvailableFormatInfo;
1525 openslide: AvailableFormatInfo;
1526 pdf: AvailableFormatInfo;
1527 png: AvailableFormatInfo;
1528 ppm: AvailableFormatInfo;
1529 raw: AvailableFormatInfo;
1530 svg: AvailableFormatInfo;
1531 tiff: AvailableFormatInfo;
1532 tif: AvailableFormatInfo;
1533 v: AvailableFormatInfo;
1534 webp: AvailableFormatInfo;
1535 }
1536
1537 interface CacheResult {
1538 memory: { current: number; high: number; max: number };
1539 files: { current: number; max: number };
1540 items: { current: number; max: number };
1541 }
1542
1543 interface Interpolators {
1544 /** [Nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation). Suitable for image enlargement only. */
1545 nearest: 'nearest';
1546 /** [Bilinear interpolation](http://en.wikipedia.org/wiki/Bilinear_interpolation). Faster than bicubic but with less smooth results. */
1547 bilinear: 'bilinear';
1548 /** [Bicubic interpolation](http://en.wikipedia.org/wiki/Bicubic_interpolation) (the default). */
1549 bicubic: 'bicubic';
1550 /**
1551 * [LBB interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/lbb.cpp#L100).
1552 * Prevents some "[acutance](http://en.wikipedia.org/wiki/Acutance)" but typically reduces performance by a factor of 2.
1553 */
1554 locallyBoundedBicubic: 'lbb';
1555 /** [Nohalo interpolation](http://eprints.soton.ac.uk/268086/). Prevents acutance but typically reduces performance by a factor of 3. */
1556 nohalo: 'nohalo';
1557 /** [VSQBS interpolation](https://github.com/libvips/libvips/blob/master/libvips/resample/vsqbs.cpp#L48). Prevents "staircasing" when enlarging. */
1558 vertexSplitQuadraticBasisSpline: 'vsqbs';
1559 }
1560
1561 type Matrix2x2 = [[number, number], [number, number]];
1562 type Matrix3x3 = [[number, number, number], [number, number, number], [number, number, number]];
1563}
1564
1565export = sharp;