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