-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
index.d.ts
1759 lines (1584 loc) · 81.2 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright 2017 François Nguyen and others.
*
* Billy Kwok <https://github.com/billykwok>
* Bradley Odell <https://github.com/BTOdell>
* Espen Hovlandsdal <https://github.com/rexxars>
* Floris de Bijl <https://github.com/Fdebijl>
* François Nguyen <https://github.com/phurytw>
* Jamie Woodbury <https://github.com/JamieWoodbury>
* Wooseop Kim <https://github.com/wooseopkim>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// SPDX-License-Identifier: MIT
/// <reference types="node" />
import { Duplex } from 'stream';
//#region Constructor functions
/**
* Creates a sharp instance from an image
* @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.
* @param options Object with optional attributes.
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
declare function sharp(options?: sharp.SharpOptions): sharp.Sharp;
declare function sharp(
input?:
| Buffer
| ArrayBuffer
| Uint8Array
| Uint8ClampedArray
| Int8Array
| Uint16Array
| Int16Array
| Uint32Array
| Int32Array
| Float32Array
| Float64Array
| string,
options?: sharp.SharpOptions,
): sharp.Sharp;
declare namespace sharp {
/** Object containing nested boolean values representing the available input and output formats/methods. */
const format: FormatEnum;
/** An Object containing the version numbers of sharp, libvips and its dependencies. */
const versions: {
vips: string;
cairo?: string | undefined;
croco?: string | undefined;
exif?: string | undefined;
expat?: string | undefined;
ffi?: string | undefined;
fontconfig?: string | undefined;
freetype?: string | undefined;
gdkpixbuf?: string | undefined;
gif?: string | undefined;
glib?: string | undefined;
gsf?: string | undefined;
harfbuzz?: string | undefined;
jpeg?: string | undefined;
lcms?: string | undefined;
orc?: string | undefined;
pango?: string | undefined;
pixman?: string | undefined;
png?: string | undefined;
sharp?: string | undefined;
svg?: string | undefined;
tiff?: string | undefined;
webp?: string | undefined;
avif?: string | undefined;
heif?: string | undefined;
xml?: string | undefined;
zlib?: string | undefined;
};
/** An Object containing the available interpolators and their proper values */
const interpolators: Interpolators;
/** An EventEmitter that emits a change event when a task is either queued, waiting for libuv to provide a worker thread, complete */
const queue: NodeJS.EventEmitter;
//#endregion
//#region Utility functions
/**
* Gets or, when options are provided, sets the limits of libvips' operation cache.
* Existing entries in the cache will be trimmed after any change in limits.
* This method always returns cache statistics, useful for determining how much working memory is required for a particular task.
* @param options Object with the following attributes, or Boolean where true uses default cache settings and false removes all caching (optional, default true)
* @returns The cache results.
*/
function cache(options?: boolean | CacheOptions): CacheResult;
/**
* Gets or sets the number of threads libvips' should create to process each image.
* The default value is the number of CPU cores. A value of 0 will reset to this default.
* The maximum number of images that can be processed in parallel is limited by libuv's UV_THREADPOOL_SIZE environment variable.
* @param concurrency The new concurrency value.
* @returns The current concurrency value.
*/
function concurrency(concurrency?: number): number;
/**
* Provides access to internal task counters.
* @returns Object containing task counters
*/
function counters(): SharpCounters;
/**
* Get and set use of SIMD vector unit instructions. Requires libvips to have been compiled with highway support.
* 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.
* @param enable enable or disable use of SIMD vector unit instructions
* @returns true if usage of SIMD vector unit instructions is enabled
*/
function simd(enable?: boolean): boolean;
/**
* Block libvips operations at runtime.
*
* This is in addition to the `VIPS_BLOCK_UNTRUSTED` environment variable,
* which when set will block all "untrusted" operations.
*
* @since 0.32.4
*
* @example <caption>Block all TIFF input.</caption>
* sharp.block({
* operation: ['VipsForeignLoadTiff']
* });
*
* @param {Object} options
* @param {Array<string>} options.operation - List of libvips low-level operation names to block.
*/
function block(options: { operation: string[] }): void;
/**
* Unblock libvips operations at runtime.
*
* This is useful for defining a list of allowed operations.
*
* @since 0.32.4
*
* @example <caption>Block all input except WebP from the filesystem.</caption>
* sharp.block({
* operation: ['VipsForeignLoad']
* });
* sharp.unblock({
* operation: ['VipsForeignLoadWebpFile']
* });
*
* @example <caption>Block all input except JPEG and PNG from a Buffer or Stream.</caption>
* sharp.block({
* operation: ['VipsForeignLoad']
* });
* sharp.unblock({
* operation: ['VipsForeignLoadJpegBuffer', 'VipsForeignLoadPngBuffer']
* });
*
* @param {Object} options
* @param {Array<string>} options.operation - List of libvips low-level operation names to unblock.
*/
function unblock(options: { operation: string[] }): void;
//#endregion
const gravity: GravityEnum;
const strategy: StrategyEnum;
const kernel: KernelEnum;
const fit: FitEnum;
const bool: BoolEnum;
interface Sharp extends Duplex {
//#region Channel functions
/**
* Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
* @returns A sharp instance that can be used to chain operations
*/
removeAlpha(): Sharp;
/**
* 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.
* @param alpha transparency level (0=fully-transparent, 1=fully-opaque) (optional, default 1).
* @returns A sharp instance that can be used to chain operations
*/
ensureAlpha(alpha?: number): Sharp;
/**
* Extract a single channel from a multi-channel image.
* @param channel zero-indexed channel/band number to extract, or red, green, blue or alpha.
* @throws {Error} Invalid channel
* @returns A sharp instance that can be used to chain operations
*/
extractChannel(channel: 0 | 1 | 2 | 3 | 'red' | 'green' | 'blue' | 'alpha'): Sharp;
/**
* Join one or more channels to the image. The meaning of the added channels depends on the output colourspace, set with toColourspace().
* By default the output image will be web-friendly sRGB, with additional channels interpreted as alpha channels. Channel ordering follows vips convention:
* - sRGB: 0: Red, 1: Green, 2: Blue, 3: Alpha.
* - CMYK: 0: Magenta, 1: Cyan, 2: Yellow, 3: Black, 4: Alpha.
*
* Buffers may be any of the image formats supported by sharp.
* 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.
* @param images one or more images (file paths, Buffers).
* @param options image options, see sharp() constructor.
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
joinChannel(images: string | Buffer | ArrayLike<string | Buffer>, options?: SharpOptions): Sharp;
/**
* Perform a bitwise boolean operation on all input image channels (bands) to produce a single channel output image.
* @param boolOp one of "and", "or" or "eor" to perform that bitwise operation, like the C logic operators &, | and ^ respectively.
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
bandbool(boolOp: keyof BoolEnum): Sharp;
//#endregion
//#region Color functions
/**
* Tint the image using the provided colour.
* An alpha channel may be present and will be unchanged by the operation.
* @param tint Parsed by the color module.
* @returns A sharp instance that can be used to chain operations
*/
tint(tint: Colour | Color): Sharp;
/**
* Convert to 8-bit greyscale; 256 shades of grey.
* This is a linear operation.
* If the input image is in a non-linear colour space such as sRGB, use gamma() with greyscale() for the best results.
* By default the output image will be web-friendly sRGB and contain three (identical) colour channels.
* This may be overridden by other sharp operations such as toColourspace('b-w'), which will produce an output image containing one colour channel.
* An alpha channel may be present, and will be unchanged by the operation.
* @param greyscale true to enable and false to disable (defaults to true)
* @returns A sharp instance that can be used to chain operations
*/
greyscale(greyscale?: boolean): Sharp;
/**
* Alternative spelling of greyscale().
* @param grayscale true to enable and false to disable (defaults to true)
* @returns A sharp instance that can be used to chain operations
*/
grayscale(grayscale?: boolean): Sharp;
/**
* Set the pipeline colourspace.
* The input image will be converted to the provided colourspace at the start of the pipeline.
* All operations will use this colourspace before converting to the output colourspace, as defined by toColourspace.
* This feature is experimental and has not yet been fully-tested with all operations.
*
* @param colourspace pipeline colourspace e.g. rgb16, scrgb, lab, grey16 ...
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
pipelineColourspace(colourspace?: string): Sharp;
/**
* Alternative spelling of pipelineColourspace
* @param colorspace pipeline colourspace e.g. rgb16, scrgb, lab, grey16 ...
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
pipelineColorspace(colorspace?: string): Sharp;
/**
* Set the output colourspace.
* By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
* @param colourspace output colourspace e.g. srgb, rgb, cmyk, lab, b-w ...
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
toColourspace(colourspace?: string): Sharp;
/**
* Alternative spelling of toColourspace().
* @param colorspace output colorspace e.g. srgb, rgb, cmyk, lab, b-w ...
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
toColorspace(colorspace: string): Sharp;
//#endregion
//#region Composite functions
/**
* Composite image(s) over the processed (resized, extracted etc.) image.
*
* The images to composite must be the same size or smaller than the processed image.
* If both `top` and `left` options are provided, they take precedence over `gravity`.
* @param images - Ordered list of images to composite
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
composite(images: OverlayOptions[]): Sharp;
//#endregion
//#region Input functions
/**
* Take a "snapshot" of the Sharp instance, returning a new instance.
* Cloned instances inherit the input of their parent instance.
* This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream.
* @returns A sharp instance that can be used to chain operations
*/
clone(): Sharp;
/**
* Fast access to (uncached) image metadata without decoding any compressed image data.
* @returns A sharp instance that can be used to chain operations
*/
metadata(callback: (err: Error, metadata: Metadata) => void): Sharp;
/**
* Fast access to (uncached) image metadata without decoding any compressed image data.
* @returns A promise that resolves with a metadata object
*/
metadata(): Promise<Metadata>;
/**
* Keep all metadata (EXIF, ICC, XMP, IPTC) from the input image in the output image.
* @returns A sharp instance that can be used to chain operations
*/
keepMetadata(): Sharp;
/**
* Access to pixel-derived image statistics for every channel in the image.
* @returns A sharp instance that can be used to chain operations
*/
stats(callback: (err: Error, stats: Stats) => void): Sharp;
/**
* Access to pixel-derived image statistics for every channel in the image.
* @returns A promise that resolves with a stats object
*/
stats(): Promise<Stats>;
//#endregion
//#region Operation functions
/**
* Rotate the output image by either an explicit angle or auto-orient based on the EXIF Orientation tag.
*
* If an angle is provided, it is converted to a valid positive degree rotation. For example, -450 will produce a 270deg rotation.
*
* When rotating by an angle other than a multiple of 90, the background colour can be provided with the background option.
*
* If no angle is provided, it is determined from the EXIF data. Mirroring is supported and may infer the use of a flip operation.
*
* The use of rotate implies the removal of the EXIF Orientation tag, if any.
*
* 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).
* @param angle angle of rotation. (optional, default auto)
* @param options if present, is an Object with optional attributes.
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
rotate(angle?: number, options?: RotateOptions): Sharp;
/**
* Flip the image about the vertical Y axis. This always occurs after rotation, if any.
* The use of flip implies the removal of the EXIF Orientation tag, if any.
* @param flip true to enable and false to disable (defaults to true)
* @returns A sharp instance that can be used to chain operations
*/
flip(flip?: boolean): Sharp;
/**
* Flop the image about the horizontal X axis. This always occurs after rotation, if any.
* The use of flop implies the removal of the EXIF Orientation tag, if any.
* @param flop true to enable and false to disable (defaults to true)
* @returns A sharp instance that can be used to chain operations
*/
flop(flop?: boolean): Sharp;
/**
* Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
* You must provide an array of length 4 or a 2x2 affine transformation matrix.
* By default, new pixels are filled with a black background. You can provide a background colour with the `background` option.
* A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
*
* In the case of a 2x2 matrix, the transform is:
* X = matrix[0, 0] * (x + idx) + matrix[0, 1] * (y + idy) + odx
* Y = matrix[1, 0] * (x + idx) + matrix[1, 1] * (y + idy) + ody
*
* where:
*
* x and y are the coordinates in input image.
* X and Y are the coordinates in output image.
* (0,0) is the upper left corner.
*
* @param matrix Affine transformation matrix, may either by a array of length four or a 2x2 matrix array
* @param options if present, is an Object with optional attributes.
*
* @returns A sharp instance that can be used to chain operations
*/
affine(matrix: [number, number, number, number] | Matrix2x2, options?: AffineOptions): Sharp;
/**
* Sharpen the image.
* When used without parameters, performs a fast, mild sharpen of the output image.
* When a sigma is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.
* Fine-grained control over the level of sharpening in "flat" (m1) and "jagged" (m2) areas is available.
* @param options if present, is an Object with optional attributes
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
sharpen(options?: SharpenOptions): Sharp;
/**
* Sharpen the image.
* When used without parameters, performs a fast, mild sharpen of the output image.
* When a sigma is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.
* Fine-grained control over the level of sharpening in "flat" (m1) and "jagged" (m2) areas is available.
* @param sigma the sigma of the Gaussian mask, where sigma = 1 + radius / 2.
* @param flat the level of sharpening to apply to "flat" areas. (optional, default 1.0)
* @param jagged the level of sharpening to apply to "jagged" areas. (optional, default 2.0)
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*
* @deprecated Use the object parameter `sharpen({sigma, m1, m2, x1, y2, y3})` instead
*/
sharpen(sigma?: number, flat?: number, jagged?: number): Sharp;
/**
* Apply median filter. When used without parameters the default window is 3x3.
* @param size square mask size: size x size (optional, default 3)
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
median(size?: number): Sharp;
/**
* Blur the image.
* When used without parameters, performs a fast, mild blur of the output image.
* When a sigma is provided, performs a slower, more accurate Gaussian blur.
* When a boolean sigma is provided, ether blur mild or disable blur
* @param sigma a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where sigma = 1 + radius / 2.
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
blur(sigma?: number | boolean | BlurOptions): Sharp;
/**
* Merge alpha transparency channel, if any, with background.
* @param flatten true to enable and false to disable (defaults to true)
* @returns A sharp instance that can be used to chain operations
*/
flatten(flatten?: boolean | FlattenOptions): Sharp;
/**
* Ensure the image has an alpha channel with all white pixel values made fully transparent.
* Existing alpha channel values for non-white pixels remain unchanged.
* @returns A sharp instance that can be used to chain operations
*/
unflatten(): Sharp;
/**
* 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.
* This can improve the perceived brightness of a resized image in non-linear colour spaces.
* JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation when applying a gamma correction.
* Supply a second argument to use a different output gamma value, otherwise the first value is used in both cases.
* @param gamma value between 1.0 and 3.0. (optional, default 2.2)
* @param gammaOut value between 1.0 and 3.0. (optional, defaults to same as gamma)
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
gamma(gamma?: number, gammaOut?: number): Sharp;
/**
* Produce the "negative" of the image.
* @param negate true to enable and false to disable, or an object of options (defaults to true)
* @returns A sharp instance that can be used to chain operations
*/
negate(negate?: boolean | NegateOptions): Sharp;
/**
* Enhance output image contrast by stretching its luminance to cover a full dynamic range.
*
* Uses a histogram-based approach, taking a default range of 1% to 99% to reduce sensitivity to noise at the extremes.
*
* Luminance values below the `lower` percentile will be underexposed by clipping to zero.
* Luminance values above the `upper` percentile will be overexposed by clipping to the max pixel value.
*
* @param normalise options
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
normalise(normalise?: NormaliseOptions): Sharp;
/**
* Alternative spelling of normalise.
* @param normalize options
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
normalize(normalize?: NormaliseOptions): Sharp;
/**
* Perform contrast limiting adaptive histogram equalization (CLAHE)
*
* This will, in general, enhance the clarity of the image by bringing out
* darker details. Please read more about CLAHE here:
* https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE
*
* @param options clahe options
*/
clahe(options: ClaheOptions): Sharp;
/**
* Convolve the image with the specified kernel.
* @param kernel the specified kernel
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
convolve(kernel: Kernel): Sharp;
/**
* Any pixel value greather than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
* @param threshold a value in the range 0-255 representing the level at which the threshold will be applied. (optional, default 128)
* @param options threshold options
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
threshold(threshold?: number, options?: ThresholdOptions): Sharp;
/**
* Perform a bitwise boolean operation with operand image.
* 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.
* @param operand Buffer containing image data or String containing the path to an image file.
* @param operator one of "and", "or" or "eor" to perform that bitwise operation, like the C logic operators &, | and ^ respectively.
* @param options describes operand when using raw pixel data.
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
boolean(operand: string | Buffer, operator: keyof BoolEnum, options?: { raw: Raw }): Sharp;
/**
* Apply the linear formula a * input + b to the image (levels adjustment)
* @param a multiplier (optional, default 1.0)
* @param b offset (optional, default 0.0)
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
linear(a?: number | number[] | null, b?: number | number[]): Sharp;
/**
* Recomb the image with the specified matrix.
* @param inputMatrix 3x3 Recombination matrix or 4x4 Recombination matrix
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
recomb(inputMatrix: Matrix3x3 | Matrix4x4): Sharp;
/**
* Transforms the image using brightness, saturation, hue rotation and lightness.
* Brightness and lightness both operate on luminance, with the difference being that brightness is multiplicative whereas lightness is additive.
* @param options describes the modulation
* @returns A sharp instance that can be used to chain operations
*/
modulate(options?: {
brightness?: number | undefined;
saturation?: number | undefined;
hue?: number | undefined;
lightness?: number | undefined;
}): Sharp;
//#endregion
//#region Output functions
/**
* Write output image data to a file.
* 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.
* Note that raw pixel data is only supported for buffer output.
* @param fileOut The path to write the image data to.
* @param callback Callback function called on completion with two arguments (err, info). info contains the output image format, size (bytes), width, height and channels.
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
toFile(fileOut: string, callback: (err: Error, info: OutputInfo) => void): Sharp;
/**
* Write output image data to a file.
* @param fileOut The path to write the image data to.
* @throws {Error} Invalid parameters
* @returns A promise that fulfills with an object containing information on the resulting file
*/
toFile(fileOut: string): Promise<OutputInfo>;
/**
* Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
* By default, the format will match the input image, except SVG input which becomes PNG output.
* @param callback Callback function called on completion with three arguments (err, buffer, info).
* @returns A sharp instance that can be used to chain operations
*/
toBuffer(callback: (err: Error, buffer: Buffer, info: OutputInfo) => void): Sharp;
/**
* Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
* By default, the format will match the input image, except SVG input which becomes PNG output.
* @param options resolve options
* @param options.resolveWithObject Resolve the Promise with an Object containing data and info properties instead of resolving only with data.
* @returns A promise that resolves with the Buffer data.
*/
toBuffer(options?: { resolveWithObject: false }): Promise<Buffer>;
/**
* Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.
* By default, the format will match the input image, except SVG input which becomes PNG output.
* @param options resolve options
* @param options.resolveWithObject Resolve the Promise with an Object containing data and info properties instead of resolving only with data.
* @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
*/
toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer; info: OutputInfo }>;
/**
* Keep all EXIF metadata from the input image in the output image.
* EXIF metadata is unsupported for TIFF output.
* @returns A sharp instance that can be used to chain operations
*/
keepExif(): Sharp;
/**
* Set EXIF metadata in the output image, ignoring any EXIF in the input image.
* @param {Exif} exif Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data.
* @returns A sharp instance that can be used to chain operations
* @throws {Error} Invalid parameters
*/
withExif(exif: Exif): Sharp;
/**
* Update EXIF metadata from the input image in the output image.
* @param {Exif} exif Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data.
* @returns A sharp instance that can be used to chain operations
* @throws {Error} Invalid parameters
*/
withExifMerge(exif: Exif): Sharp;
/**
* Keep ICC profile from the input image in the output image where possible.
* @returns A sharp instance that can be used to chain operations
*/
keepIccProfile(): Sharp;
/**
* Transform using an ICC profile and attach to the output image.
* @param {string} icc - Absolute filesystem path to output ICC profile or built-in profile name (srgb, p3, cmyk).
* @returns A sharp instance that can be used to chain operations
* @throws {Error} Invalid parameters
*/
withIccProfile(icc: string, options?: WithIccProfileOptions): Sharp;
/**
* Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
* The default behaviour, when withMetadata is not used, is to strip all metadata and convert to the device-independent sRGB colour space.
* This will also convert to and add a web-friendly sRGB ICC profile.
* @param withMetadata
* @throws {Error} Invalid parameters.
*/
withMetadata(withMetadata?: WriteableMetadata): Sharp;
/**
* Use these JPEG options for output image.
* @param options Output options.
* @throws {Error} Invalid options
* @returns A sharp instance that can be used to chain operations
*/
jpeg(options?: JpegOptions): Sharp;
/**
* Use these JP2 (JPEG 2000) options for output image.
* @param options Output options.
* @throws {Error} Invalid options
* @returns A sharp instance that can be used to chain operations
*/
jp2(options?: Jp2Options): Sharp;
/**
* Use these JPEG-XL (JXL) options for output image.
* This feature is experimental, please do not use in production systems.
* Requires libvips compiled with support for libjxl.
* The prebuilt binaries do not include this.
* Image metadata (EXIF, XMP) is unsupported.
* @param options Output options.
* @throws {Error} Invalid options
* @returns A sharp instance that can be used to chain operations
*/
jxl(options?: JxlOptions): Sharp;
/**
* Use these PNG options for output image.
* PNG output is always full colour at 8 or 16 bits per pixel.
* Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
* @param options Output options.
* @throws {Error} Invalid options
* @returns A sharp instance that can be used to chain operations
*/
png(options?: PngOptions): Sharp;
/**
* Use these WebP options for output image.
* @param options Output options.
* @throws {Error} Invalid options
* @returns A sharp instance that can be used to chain operations
*/
webp(options?: WebpOptions): Sharp;
/**
* Use these GIF options for output image.
* Requires libvips compiled with support for ImageMagick or GraphicsMagick. The prebuilt binaries do not include this - see installing a custom libvips.
* @param options Output options.
* @throws {Error} Invalid options
* @returns A sharp instance that can be used to chain operations
*/
gif(options?: GifOptions): Sharp;
/**
* Use these AVIF options for output image.
* @param options Output options.
* @throws {Error} Invalid options
* @returns A sharp instance that can be used to chain operations
*/
avif(options?: AvifOptions): Sharp;
/**
* Use these HEIF options for output image.
* Support for patent-encumbered HEIC images requires the use of a globally-installed libvips compiled with support for libheif, libde265 and x265.
* @param options Output options.
* @throws {Error} Invalid options
* @returns A sharp instance that can be used to chain operations
*/
heif(options?: HeifOptions): Sharp;
/**
* Use these TIFF options for output image.
* @param options Output options.
* @throws {Error} Invalid options
* @returns A sharp instance that can be used to chain operations
*/
tiff(options?: TiffOptions): Sharp;
/**
* Force output to be raw, uncompressed uint8 pixel data.
* @param options Raw output options.
* @throws {Error} Invalid options
* @returns A sharp instance that can be used to chain operations
*/
raw(options?: RawOptions): Sharp;
/**
* Force output to a given format.
* @param format a String or an Object with an 'id' attribute
* @param options output options
* @throws {Error} Unsupported format or options
* @returns A sharp instance that can be used to chain operations
*/
toFormat(
format: keyof FormatEnum | AvailableFormatInfo,
options?:
| OutputOptions
| JpegOptions
| PngOptions
| WebpOptions
| AvifOptions
| HeifOptions
| JxlOptions
| GifOptions
| Jp2Options
| TiffOptions,
): Sharp;
/**
* Use tile-based deep zoom (image pyramid) output.
* Set the format and options for tile images via the toFormat, jpeg, png or webp functions.
* Use a .zip or .szi file extension with toFile to write to a compressed archive file format.
*
* Warning: multiple sharp instances concurrently producing tile output can expose a possible race condition in some versions of libgsf.
* @param tile tile options
* @throws {Error} Invalid options
* @returns A sharp instance that can be used to chain operations
*/
tile(tile?: TileOptions): Sharp;
/**
* Set a timeout for processing, in seconds. Use a value of zero to continue processing indefinitely, the default behaviour.
* The clock starts when libvips opens an input image for processing. Time spent waiting for a libuv thread to become available is not included.
* @param options Object with a `seconds` attribute between 0 and 3600 (number)
* @throws {Error} Invalid options
* @returns A sharp instance that can be used to chain operations
*/
timeout(options: TimeoutOptions): Sharp;
//#endregion
//#region Resize functions
/**
* Resize image to width, height or width x height.
*
* When both a width and height are provided, the possible methods by which the image should fit these are:
* - cover: Crop to cover both provided dimensions (the default).
* - contain: Embed within both provided dimensions.
* - fill: Ignore the aspect ratio of the input and stretch to both provided dimensions.
* - 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.
* - 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.
* Some of these values are based on the object-fit CSS property.
*
* When using a fit of cover or contain, the default position is centre. Other options are:
* - sharp.position: top, right top, right, right bottom, bottom, left bottom, left, left top.
* - sharp.gravity: north, northeast, east, southeast, south, southwest, west, northwest, center or centre.
* - 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.
*
* The experimental strategy-based approach resizes so one dimension is at its target length then repeatedly ranks edge regions,
* discarding the edge with the lowest score based on the selected strategy.
* - entropy: focus on the region with the highest Shannon entropy.
* - attention: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
*
* Possible interpolation kernels are:
* - nearest: Use nearest neighbour interpolation.
* - cubic: Use a Catmull-Rom spline.
* - lanczos2: Use a Lanczos kernel with a=2.
* - lanczos3: Use a Lanczos kernel with a=3 (the default).
*
* @param width pixels wide the resultant image should be. Use null or undefined to auto-scale the width to match the height.
* @param height pixels high the resultant image should be. Use null or undefined to auto-scale the height to match the width.
* @param options resize options
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
resize(widthOrOptions?: number | ResizeOptions | null, height?: number | null, options?: ResizeOptions): Sharp;
/**
* Shorthand for resize(null, null, options);
*
* @param options resize options
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
resize(options: ResizeOptions): Sharp;
/**
* Extend / pad / extrude one or more edges of the image with either
* the provided background colour or pixels derived from the image.
* This operation will always occur after resizing and extraction, if any.
* @param extend single pixel count to add to all edges or an Object with per-edge counts
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
extend(extend: number | ExtendOptions): Sharp;
/**
* Extract a region of the image.
* - Use extract() before resize() for pre-resize extraction.
* - Use extract() after resize() for post-resize extraction.
* - Use extract() before and after for both.
*
* @param region The region to extract
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
extract(region: Region): Sharp;
/**
* Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.
* Images with an alpha channel will use the combined bounding box of alpha and non-alpha channels.
* The info response Object will contain trimOffsetLeft and trimOffsetTop properties.
* @param options trim options
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
trim(options?: TrimOptions): Sharp;
//#endregion
}
interface SharpOptions {
/**
* When to abort processing of invalid pixel data, one of (in order of sensitivity):
* 'none' (least), 'truncated', 'error' or 'warning' (most), highers level imply lower levels, invalid metadata will always abort. (optional, default 'warning')
*/
failOn?: FailOnOptions | undefined;
/**
* By default halt processing and raise an error when loading invalid images.
* Set this flag to false if you'd rather apply a "best effort" to decode images,
* even if the data is corrupt or invalid. (optional, default true)
*
* @deprecated Use `failOn` instead
*/
failOnError?: boolean | undefined;
/**
* Do not process input images where the number of pixels (width x height) exceeds this limit.
* Assumes image dimensions contained in the input metadata can be trusted.
* An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). (optional, default 268402689)
*/
limitInputPixels?: number | boolean | undefined;
/** Set this to true to remove safety features that help prevent memory exhaustion (SVG, PNG). (optional, default false) */
unlimited?: boolean | undefined;
/** Set this to false to use random access rather than sequential read. Some operations will do this automatically. */
sequentialRead?: boolean | undefined;
/** Number representing the DPI for vector images in the range 1 to 100000. (optional, default 72) */
density?: number | undefined;
/** Should the embedded ICC profile, if any, be ignored. */
ignoreIcc?: boolean | undefined;
/** Number of pages to extract for multi-page input (GIF, TIFF, PDF), use -1 for all pages */
pages?: number | undefined;
/** Page number to start extracting from for multi-page input (GIF, TIFF, PDF), zero based. (optional, default 0) */
page?: number | undefined;
/** subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image. (optional, default -1) */
subifd?: number | undefined;
/** Level to extract from a multi-level input (OpenSlide), zero based. (optional, default 0) */
level?: number | undefined;
/** Background colour to use when PDF is partially transparent. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick. */
pdfBackground?: Colour | Color | undefined;
/** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default false) */
animated?: boolean | undefined;
/** Describes raw pixel input image data. See raw() for pixel ordering. */
raw?: CreateRaw | undefined;
/** Describes a new image to be created. */
create?: Create | undefined;
/** Describes a new text image to be created. */
text?: CreateText | undefined;
}
interface CacheOptions {
/** Is the maximum memory in MB to use for this cache (optional, default 50) */
memory?: number | undefined;
/** Is the maximum number of files to hold open (optional, default 20) */
files?: number | undefined;
/** Is the maximum number of operations to cache (optional, default 100) */
items?: number | undefined;
}
interface TimeoutOptions {
/** Number of seconds after which processing will be stopped (default 0, eg disabled) */
seconds: number;
}
interface SharpCounters {
/** The number of tasks this module has queued waiting for libuv to provide a worker thread from its pool. */
queue: number;
/** The number of resize tasks currently being processed. */
process: number;
}
interface Raw {
width: number;
height: number;
channels: Channels;
}
interface CreateRaw extends Raw {
/** Specifies that the raw input has already been premultiplied, set to true to avoid sharp premultiplying the image. (optional, default false) */
premultiplied?: boolean | undefined;
}
type CreateChannels = 3 | 4;
interface Create {
/** Number of pixels wide. */
width: number;
/** Number of pixels high. */
height: number;
/** Number of bands, 3 for RGB, 4 for RGBA */
channels: CreateChannels;
/** Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. */
background: Colour | Color;
/** Describes a noise to be created. */
noise?: Noise | undefined;
}
interface CreateText {
/** Text to render as a UTF-8 string. It can contain Pango markup, for example `<i>Le</i>Monde`. */
text: string;
/** Font name to render with. */