jimp 0.17.9 → 0.17.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/types/index.d.ts CHANGED
@@ -1,607 +1,53 @@
1
- // TypeScript Version: 2.8
2
-
3
- declare const DepreciatedJimp: DepreciatedJimp;
4
-
5
- export = DepreciatedJimp;
6
-
7
- /**
8
- * @deprecated Jimp typings for TS <3.1 are being depreciated. Please upgrade your TypeScript version
9
- */
10
- interface DepreciatedJimp {
11
- // Constructors
12
- new (path: string, cb?: ImageCallback): this;
13
- new (urlOptions: URLOptions, cb?: ImageCallback): this;
14
- new (image: DepreciatedJimp, cb?: ImageCallback): this;
15
- new (data: Buffer | Bitmap, cb?: ImageCallback): this;
16
- new (w: number, h: number, cb?: ImageCallback): this;
17
- new (
18
- w: number,
19
- h: number,
20
- background?: number | string,
21
- cb?: ImageCallback
22
- ): this;
23
- // For custom constructors when using Jimp.appendConstructorOption
24
- new (...args: any[]): this;
25
- prototype: this;
26
-
27
- // Constants
28
- AUTO: -1;
29
-
30
- // supported mime types
31
- MIME_PNG: "image/png";
32
- MIME_TIFF: "image/tiff";
33
- MIME_JPEG: "image/jpeg";
34
- MIME_JGD: "image/jgd";
35
- MIME_BMP: "image/bmp";
36
- MIME_X_MS_BMP: "image/x-ms-bmp";
37
- MIME_GIF: "image/gif";
38
- // PNG filter types
39
- PNG_FILTER_AUTO: -1;
40
- PNG_FILTER_NONE: 0;
41
- PNG_FILTER_SUB: 1;
42
- PNG_FILTER_UP: 2;
43
- PNG_FILTER_AVERAGE: 3;
44
- PNG_FILTER_PATH: 4;
45
-
46
- // resize methods
47
- RESIZE_NEAREST_NEIGHBOR: "nearestNeighbor";
48
- RESIZE_BILINEAR: "bilinearInterpolation";
49
- RESIZE_BICUBIC: "bicubicInterpolation";
50
- RESIZE_HERMITE: "hermiteInterpolation";
51
- RESIZE_BEZIER: "bezierInterpolation";
52
-
53
- // blend modes
54
- BLEND_SOURCE_OVER: string;
55
- BLEND_DESTINATION_OVER: string;
56
- BLEND_MULTIPLY: string;
57
- BLEND_SCREEN: string;
58
- BLEND_OVERLAY: string;
59
- BLEND_DARKEN: string;
60
- BLEND_LIGHTEN: string;
61
- BLEND_HARDLIGHT: string;
62
- BLEND_DIFFERENCE: string;
63
- BLEND_EXCLUSION: string;
64
-
65
- // Align modes for cover, contain, bit masks
66
- HORIZONTAL_ALIGN_LEFT: 1;
67
- HORIZONTAL_ALIGN_CENTER: 2;
68
- HORIZONTAL_ALIGN_RIGHT: 4;
69
-
70
- VERTICAL_ALIGN_TOP: 8;
71
- VERTICAL_ALIGN_MIDDLE: 16;
72
- VERTICAL_ALIGN_BOTTOM: 32;
73
-
74
- // Font locations
75
- FONT_SANS_8_BLACK: string;
76
- FONT_SANS_10_BLACK: string;
77
- FONT_SANS_12_BLACK: string;
78
- FONT_SANS_14_BLACK: string;
79
- FONT_SANS_16_BLACK: string;
80
- FONT_SANS_32_BLACK: string;
81
- FONT_SANS_64_BLACK: string;
82
- FONT_SANS_128_BLACK: string;
83
-
84
- FONT_SANS_8_WHITE: string;
85
- FONT_SANS_16_WHITE: string;
86
- FONT_SANS_32_WHITE: string;
87
- FONT_SANS_64_WHITE: string;
88
- FONT_SANS_128_WHITE: string;
89
-
90
- // Edge Handling
91
- EDGE_EXTEND: 1;
92
- EDGE_WRAP: 2;
93
- EDGE_CROP: 3;
94
-
95
- // Properties
96
- bitmap: Bitmap;
97
-
98
- _quality: number;
99
- _deflateLevel: number;
100
- _deflateStrategy: number;
101
- _filterType: number;
102
- _rgba: boolean;
103
- _background: number;
104
- _originalMime: string;
105
-
106
- // Methods
107
- on<T extends ListenableName>(
108
- event: T,
109
- cb: (data: ListenerData<T>) => any
110
- ): any;
111
- parseBitmap(
112
- data: Buffer,
113
- path: string | null | undefined,
114
- cb?: ImageCallback
115
- ): void;
116
- hasAlpha(): boolean;
117
- getHeight(): number;
118
- getWidth(): number;
119
- inspect(): string;
120
- toString(): string;
121
- getMIME(): string;
122
- getExtension(): string;
123
- distanceFromHash(hash: string): number;
124
- write(path: string, cb?: ImageCallback): this;
125
- writeAsync(path: string): Promise<this>;
126
- deflateLevel(l: number, cb?: ImageCallback): this;
127
- deflateStrategy(s: number, cb?: ImageCallback): this;
128
- colorType(s: number, cb?: ImageCallback): this;
129
- filterType(f: number, cb?: ImageCallback): this;
130
- rgba(bool: boolean, cb?: ImageCallback): this;
131
- quality(n: number, cb?: ImageCallback): this;
132
- getBase64(mime: string, cb: GenericCallback<string, any, this>): this;
133
- getBase64Async(mime: string): Promise<string>;
134
- hash(cb?: GenericCallback<string, any, this>): string;
135
- hash(
136
- base: number | null | undefined,
137
- cb?: GenericCallback<string, any, this>
138
- ): string;
139
- getBuffer(mime: string, cb: GenericCallback<Buffer>): this;
140
- getBufferAsync(mime: string): Promise<Buffer>;
141
- getPixelIndex(
142
- x: number,
143
- y: number,
144
- cb?: GenericCallback<number, any, this>
145
- ): number;
146
- getPixelIndex(
147
- x: number,
148
- y: number,
149
- edgeHandling: number,
150
- cb?: GenericCallback<number, any, this>
151
- ): number;
152
- getPixelColor(
153
- x: number,
154
- y: number,
155
- cb?: GenericCallback<number, any, this>
156
- ): number;
157
- getPixelColour(
158
- x: number,
159
- y: number,
160
- cb?: GenericCallback<number, any, this>
161
- ): number;
162
- setPixelColor(hex: number, x: number, y: number, cb?: ImageCallback): this;
163
- setPixelColour(hex: number, x: number, y: number, cb?: ImageCallback): this;
164
- clone(cb?: ImageCallback): this;
165
- cloneQuiet(cb?: ImageCallback): this;
166
- background(hex: number, cb?: ImageCallback): this;
167
- backgroundQuiet(hex: number, cb?: ImageCallback): this;
168
- scan(
169
- x: number,
170
- y: number,
171
- w: number,
172
- h: number,
173
- f: (this: this, x: number, y: number, idx: number) => any,
174
- cb?: ImageCallback
175
- ): this;
176
- scanQuiet(
177
- x: number,
178
- y: number,
179
- w: number,
180
- h: number,
181
- f: (this: this, x: number, y: number, idx: number) => any,
182
- cb?: ImageCallback
183
- ): this;
184
- scanIterator(
185
- x: number,
186
- y: number,
187
- w: number,
188
- h: number
189
- ): IterableIterator<{
190
- x: number;
191
- y: number;
192
- idx: number;
193
- image: DepreciatedJimp;
194
- }>;
195
- crop(x: number, y: number, w: number, h: number, cb?: ImageCallback): this;
196
- cropQuiet(
197
- x: number,
198
- y: number,
199
- w: number,
200
- h: number,
201
- cb?: ImageCallback
202
- ): this;
203
-
204
- // Color methods
205
- brightness(val: number, cb?: ImageCallback): this;
206
- contrast(val: number, cb?: ImageCallback): this;
207
- posterize(n: number, cb?: ImageCallback): this;
208
- greyscale(cb?: ImageCallback): this;
209
- grayscale(cb?: ImageCallback): this;
210
- opacity(f: number, cb?: ImageCallback): this;
211
- sepia(cb?: ImageCallback): this;
212
- fade(f: number, cb?: ImageCallback): this;
213
- convolution(kernel: number[][], cb?: ImageCallback): this;
214
- convolution<T>(
215
- kernel: number[][],
216
- edgeHandling: number,
217
- cb?: ImageCallback
218
- ): this;
219
- opaque(cb?: ImageCallback): this;
220
- pixelate(size: number, cb?: ImageCallback): this;
221
- pixelate(
222
- size: number,
223
- x: number,
224
- y: number,
225
- w: number,
226
- h: number,
227
- cb?: ImageCallback
228
- ): this;
229
- convolute(kernel: number[][], cb?: ImageCallback): this;
230
- convolute(
231
- kernel: number[][],
232
- x: number,
233
- y: number,
234
- w: number,
235
- h: number,
236
- cb?: ImageCallback
237
- ): this;
238
- color(actions: ColorAction[], cb?: ImageCallback): this;
239
- colour(actions: ColorAction[], cb?: ImageCallback): this;
240
-
241
- // Shape methods
242
- rotate(deg: number, cb?: ImageCallback): this;
243
- rotate(deg: number, mode: string | boolean, cb?: ImageCallback): this;
244
- flip(horizontal: boolean, vertical: boolean, cb?: ImageCallback): this;
245
- mirror(horizontal: boolean, vertical: boolean, cb?: ImageCallback): this;
246
- resize(w: number, h: number, cb?: ImageCallback): this;
247
- resize(w: number, h: number, mode?: string, cb?: ImageCallback): this;
248
- cover(w: number, h: number, cb?: ImageCallback): this;
249
- cover(w: number, h: number, alignBits?: number, cb?: ImageCallback): this;
250
- cover(
251
- w: number,
252
- h: number,
253
- alignBits?: number,
254
- mode?: string,
255
- cb?: ImageCallback
256
- ): this;
257
- contain(w: number, h: number, cb?: ImageCallback): this;
258
- contain(w: number, h: number, mode?: string, cb?: ImageCallback): this;
259
- contain(w: number, h: number, alignBits?: number, cb?: ImageCallback): this;
260
- contain(
261
- w: number,
262
- h: number,
263
- alignBits?: number,
264
- mode?: string,
265
- cb?: ImageCallback
266
- ): this;
267
- scale(f: number, cb?: ImageCallback): this;
268
- scale(f: number, mode?: string, cb?: ImageCallback): this;
269
- scaleToFit(w: number, h: number, cb?: ImageCallback): this;
270
- scaleToFit(w: number, h: number, mode?: string, cb?: ImageCallback): this;
271
- displace(map: DepreciatedJimp, offset: number, cb?: ImageCallback): this;
272
- autocrop(tolerance?: number, cb?: ImageCallback): this;
273
- autocrop(cropOnlyFrames?: boolean, cb?: ImageCallback): this;
274
- autocrop(
275
- tolerance?: number,
276
- cropOnlyFrames?: boolean,
277
- cb?: ImageCallback
278
- ): this;
279
- autocrop(
280
- options: {
281
- tolerance?: number;
282
- cropOnlyFrames?: boolean;
283
- cropSymmetric?: boolean;
284
- leaveBorder?: number;
285
- },
286
- cb?: ImageCallback
287
- ): this;
288
-
289
- // Text methods
290
- print(
291
- font: Font,
292
- x: number,
293
- y: number,
294
- text: PrintableText,
295
- cb?: ImageCallback
296
- ): this;
297
- print(
298
- font: Font,
299
- x: number,
300
- y: number,
301
- text: PrintableText,
302
- maxWidth?: number,
303
- cb?: ImageCallback
304
- ): this;
305
- print(
306
- font: Font,
307
- x: number,
308
- y: number,
309
- text: PrintableText,
310
- maxWidth?: number,
311
- maxHeight?: number,
312
- cb?: ImageCallback
313
- ): this;
314
-
315
- // Effect methods
316
- blur(r: number, cb?: ImageCallback): this;
317
- dither565(cb?: ImageCallback): this;
318
- dither16(cb?: ImageCallback): this;
319
- histogram(): {
320
- r: number[];
321
- g: number[];
322
- b: number[];
1
+ // Minimum TypeScript Version: 3.1
2
+
3
+ /**
4
+ * While there is nothing in these typings that prevent it from running in TS 2.8 even,
5
+ * due to the complexity of the typings anything lower than TS 3.1 will only see
6
+ * Jimp as `any`. In order to test the strict versions of these types in our typing
7
+ * test suite, the version has been bumped to 3.1
8
+ */
9
+
10
+ import {
11
+ Jimp as JimpType,
12
+ Bitmap,
13
+ RGB,
14
+ RGBA,
15
+ UnionToIntersection,
16
+ GetPluginVal,
17
+ GetPluginConst,
18
+ GetPluginEncoders,
19
+ GetPluginDecoders,
20
+ JimpConstructors,
21
+ } from "@jimp/core";
22
+ import typeFn from "@jimp/types";
23
+ import pluginFn from "@jimp/plugins";
24
+
25
+ type Types = ReturnType<typeof typeFn>;
26
+ type Plugins = ReturnType<typeof pluginFn>;
27
+
28
+ type IntersectedPluginTypes = UnionToIntersection<
29
+ GetPluginVal<Types> | GetPluginVal<Plugins>
30
+ >;
31
+
32
+ type IntersectedPluginConsts = UnionToIntersection<
33
+ GetPluginConst<Types> | GetPluginConst<Plugins>
34
+ >;
35
+
36
+ type IntersectedPluginEncoders = UnionToIntersection<
37
+ GetPluginEncoders<Types> | GetPluginEncoders<Plugins>
38
+ >;
39
+
40
+ type IntersectedPluginDecoders = UnionToIntersection<
41
+ GetPluginDecoders<Types> | GetPluginDecoders<Plugins>
42
+ >;
43
+
44
+ type Jimp = JimpType & IntersectedPluginTypes;
45
+
46
+ declare const Jimp: JimpConstructors &
47
+ IntersectedPluginConsts & {
48
+ prototype: Jimp;
49
+ encoders: IntersectedPluginEncoders;
50
+ decoders: IntersectedPluginDecoders;
323
51
  };
324
- normalize(cb?: ImageCallback): this;
325
- invert(cb?: ImageCallback): this;
326
- gaussian(r: number, cb?: ImageCallback): this;
327
- composite(
328
- src: DepreciatedJimp,
329
- x: number,
330
- y: number,
331
- options?: BlendMode,
332
- cb?: ImageCallback
333
- ): this;
334
- blit(src: DepreciatedJimp, x: number, y: number, cb?: ImageCallback): this;
335
- blit(
336
- src: DepreciatedJimp,
337
- x: number,
338
- y: number,
339
- srcx: number,
340
- srcy: number,
341
- srcw: number,
342
- srch: number,
343
- cb?: ImageCallback
344
- ): this;
345
- mask(src: this, x: number, y: number, cb?: ImageCallback): this;
346
-
347
- // Functions
348
- /**
349
- * I'd like to make `Args` generic and used in `run` and `test` but alas,
350
- * it's not possible RN:
351
- * https://github.com/microsoft/TypeScript/issues/26113
352
- */
353
- appendConstructorOption<Args extends any[]>(
354
- name: string,
355
- test: (...args: any[]) => boolean,
356
- run: (
357
- this: this,
358
- resolve: (jimp?: this) => any,
359
- reject: (reason: Error) => any,
360
- ...args: any[]
361
- ) => any
362
- ): void;
363
- read(path: string, cb?: ImageCallback): Promise<this>;
364
- read(image: this, cb?: ImageCallback): Promise<this>;
365
- read(data: Buffer, cb?: ImageCallback): Promise<this>;
366
- read(
367
- w: number,
368
- h: number,
369
- background?: number | string,
370
- cb?: ImageCallback
371
- ): Promise<this>;
372
- create(path: string): Promise<this>;
373
- create(image: this): Promise<this>;
374
- create(data: Buffer): Promise<this>;
375
- create(w: number, h: number, background?: number | string): Promise<this>;
376
- rgbaToInt(
377
- r: number,
378
- g: number,
379
- b: number,
380
- a: number,
381
- cb: GenericCallback<number, any, this>
382
- ): number;
383
- intToRGBA(i: number, cb?: GenericCallback<RGBA>): RGBA;
384
- cssColorToHex(cssColor: string): number;
385
- limit255(n: number): number;
386
- diff(
387
- img1: this,
388
- img2: this,
389
- threshold?: number
390
- ): {
391
- percent: number;
392
- image: DepreciatedJimp;
393
- };
394
- distance(img1: this, img2: this): number;
395
- compareHashes(hash1: string, hash2: string): number;
396
- colorDiff(rgba1: RGB, rgba2: RGB): number;
397
- colorDiff(rgba1: RGBA, rgba2: RGBA): number;
398
- loadFont(file: string): Promise<Font>;
399
- loadFont(file: string, cb: GenericCallback<Font, any, any>): Promise<never>;
400
- measureText(font: Font, text: PrintableText): number;
401
- measureTextHeight(font: Font, text: PrintableText, maxWidth: number): number;
402
- circle(
403
- options?: {
404
- radius: number;
405
- x: number;
406
- y: number;
407
- },
408
- cb?: ImageCallback
409
- ): this;
410
- circle(cb?: ImageCallback): this;
411
- fishEye(opts?: { r: number }, cb?: ImageCallback): this;
412
- fishEye(cb?: ImageCallback): this;
413
- shadow(
414
- options?: {
415
- size?: number;
416
- opacity?: number;
417
- x?: number;
418
- y?: number;
419
- },
420
- cb?: ImageCallback
421
- ): this;
422
- shadow(cb?: ImageCallback): this;
423
- threshold(
424
- opts: {
425
- max: number;
426
- replace?: number;
427
- autoGreyscale?: boolean;
428
- },
429
- cb?: ImageCallback
430
- ): this;
431
- }
432
-
433
- type GenericCallback<T, U = any, TThis = any> = (
434
- this: TThis,
435
- err: Error | null,
436
- value: T
437
- ) => U;
438
-
439
- type ImageCallback<U = any> = (
440
- this: DepreciatedJimp,
441
- err: Error | null,
442
- value: DepreciatedJimp,
443
- coords: {
444
- x: number;
445
- y: number;
446
- }
447
- ) => U;
448
-
449
- type ColorActionName =
450
- | "mix"
451
- | "tint"
452
- | "shade"
453
- | "xor"
454
- | "red"
455
- | "green"
456
- | "blue"
457
- | "hue";
458
-
459
- type ColorAction = {
460
- apply: ColorActionName;
461
- params: any;
462
- };
463
-
464
- type BlendMode = {
465
- mode: string;
466
- opacitySource: number;
467
- opacityDest: number;
468
- };
469
52
 
470
- type ChangeName = "background" | "scan" | "crop";
471
-
472
- type ListenableName =
473
- | "any"
474
- | "initialized"
475
- | "before-change"
476
- | "changed"
477
- | "before-clone"
478
- | "cloned"
479
- | ChangeName;
480
-
481
- type ListenerData<T extends ListenableName> = T extends "any"
482
- ? any
483
- : T extends ChangeName
484
- ? {
485
- eventName: "before-change" | "changed";
486
- methodName: T;
487
- [key: string]: any;
488
- }
489
- : {
490
- eventName: T;
491
- methodName: T extends "initialized"
492
- ? "constructor"
493
- : T extends "before-change" | "changed"
494
- ? ChangeName
495
- : T extends "before-clone" | "cloned"
496
- ? "clone"
497
- : any;
498
- };
499
-
500
- type PrintableText =
501
- | any
502
- | {
503
- text: string;
504
- alignmentX: number;
505
- alignmentY: number;
506
- };
507
-
508
- type URLOptions = {
509
- url: string;
510
- compression?: boolean;
511
- headers: {
512
- [key: string]: any;
513
- };
514
- };
515
-
516
- /**
517
- * @deprecated Jimp typings for TS <3.1 are being depreciated. Please upgrade your TypeScript version
518
- */
519
- interface Bitmap {
520
- data: Buffer;
521
- width: number;
522
- height: number;
523
- }
524
- /**
525
- * @deprecated Jimp typings for TS <3.1 are being depreciated. Please upgrade your TypeScript version
526
- */
527
- interface RGB {
528
- r: number;
529
- g: number;
530
- b: number;
531
- }
532
-
533
- /**
534
- * @deprecated Jimp typings for TS <3.1 are being depreciated. Please upgrade your TypeScript version
535
- */
536
- interface RGBA {
537
- r: number;
538
- g: number;
539
- b: number;
540
- a: number;
541
- }
542
-
543
- /**
544
- * @deprecated Jimp typings for TS <3.1 are being depreciated. Please upgrade your TypeScript version
545
- */
546
- interface FontChar {
547
- id: number;
548
- x: number;
549
- y: number;
550
- width: number;
551
- height: number;
552
- xoffset: number;
553
- yoffset: number;
554
- xadvance: number;
555
- page: number;
556
- chnl: number;
557
- }
558
-
559
- /**
560
- * @deprecated Jimp typings for TS <3.1 are being depreciated. Please upgrade your TypeScript version
561
- */
562
- interface FontInfo {
563
- face: string;
564
- size: number;
565
- bold: number;
566
- italic: number;
567
- charset: string;
568
- unicode: number;
569
- stretchH: number;
570
- smooth: number;
571
- aa: number;
572
- padding: [number, number, number, number];
573
- spacing: [number, number];
574
- }
575
-
576
- /**
577
- * @deprecated Jimp typings for TS <3.1 are being depreciated. Please upgrade your TypeScript version
578
- */
579
- interface FontCommon {
580
- lineHeight: number;
581
- base: number;
582
- scaleW: number;
583
- scaleH: number;
584
- pages: number;
585
- packed: number;
586
- alphaChnl: number;
587
- redChnl: number;
588
- greenChnl: number;
589
- blueChnl: number;
590
- }
591
-
592
- /**
593
- * @deprecated Jimp typings for TS <3.1 are being depreciated. Please upgrade your TypeScript version
594
- */
595
- interface Font {
596
- chars: {
597
- [char: string]: FontChar;
598
- };
599
- kernings: {
600
- [firstString: string]: {
601
- [secondString: string]: number;
602
- };
603
- };
604
- pages: string[];
605
- common: FontCommon;
606
- info: FontInfo;
607
- }
53
+ export = Jimp;