imagescript 1.3.1 → 3.0.0

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.
Files changed (117) hide show
  1. package/LICENSE +4 -1
  2. package/README.md +64 -26
  3. package/THIRD_PARTY_NOTICES.md +74 -0
  4. package/dist/codecs/crc.d.ts +9 -0
  5. package/dist/codecs/crc.js +29 -0
  6. package/dist/codecs/exif.d.ts +11 -0
  7. package/dist/codecs/exif.js +27 -0
  8. package/dist/codecs/gif.d.ts +44 -0
  9. package/dist/codecs/gif.js +401 -0
  10. package/dist/codecs/jpeg.d.ts +35 -0
  11. package/dist/codecs/jpeg.js +980 -0
  12. package/dist/codecs/png.d.ts +44 -0
  13. package/dist/codecs/png.js +442 -0
  14. package/dist/codecs/quantize.d.ts +25 -0
  15. package/dist/codecs/quantize.js +302 -0
  16. package/dist/codecs/tiff.d.ts +6 -0
  17. package/dist/codecs/tiff.js +546 -0
  18. package/dist/codecs/zlib.d.ts +22 -0
  19. package/dist/codecs/zlib.js +607 -0
  20. package/dist/frame.d.ts +57 -0
  21. package/dist/frame.js +65 -0
  22. package/dist/gif.d.ts +44 -0
  23. package/dist/gif.js +93 -0
  24. package/dist/image-type.d.ts +20 -0
  25. package/dist/image-type.js +49 -0
  26. package/dist/image.d.ts +521 -0
  27. package/dist/image.js +1118 -0
  28. package/dist/index.d.ts +19 -0
  29. package/dist/index.js +13 -0
  30. package/dist/package.json +1 -0
  31. package/dist/render/font.d.ts +63 -0
  32. package/dist/render/font.js +857 -0
  33. package/dist/render/svg.d.ts +11 -0
  34. package/dist/render/svg.js +1717 -0
  35. package/dist/render/text.d.ts +61 -0
  36. package/dist/render/text.js +317 -0
  37. package/dist/text-layout.d.ts +46 -0
  38. package/dist/text-layout.js +35 -0
  39. package/dist/util/blur.d.ts +13 -0
  40. package/dist/util/blur.js +146 -0
  41. package/dist/util/mem.d.ts +10 -0
  42. package/dist/util/mem.js +23 -0
  43. package/dist/util/resample.d.ts +12 -0
  44. package/dist/util/resample.js +99 -0
  45. package/dist/util/utf8.d.ts +5 -0
  46. package/dist/util/utf8.js +55 -0
  47. package/dist/version.d.ts +1 -0
  48. package/dist/version.js +1 -0
  49. package/licenses/Apache-2.0.txt +202 -0
  50. package/licenses/README.ijg +260 -0
  51. package/package.json +31 -7
  52. package/ImageScript.d.ts +0 -954
  53. package/ImageScript.js +0 -1669
  54. package/bench/_.mjs +0 -166
  55. package/bench/all.mjs +0 -4
  56. package/bench/blur.mjs +0 -59
  57. package/bench/flip.mjs +0 -63
  58. package/bench/overlay.mjs +0 -35
  59. package/bench/package.json +0 -7
  60. package/bench/readme.md +0 -64
  61. package/bench/resize.mjs +0 -52
  62. package/codecs/LICENSE +0 -21
  63. package/codecs/lib.d.ts +0 -50
  64. package/codecs/lib.js +0 -6
  65. package/codecs/lib.mjs +0 -1
  66. package/codecs/node/bin/arm64-darwin.node +0 -0
  67. package/codecs/node/bin/arm64-linux.node +0 -0
  68. package/codecs/node/bin/x64-darwin.node +0 -0
  69. package/codecs/node/bin/x64-linux.node +0 -0
  70. package/codecs/node/bin/x64-win32.node +0 -0
  71. package/codecs/node/index.js +0 -3
  72. package/codecs/node/index.mjs +0 -6
  73. package/codecs/package.json +0 -14
  74. package/codecs/readme.md +0 -38
  75. package/codecs/wasm/bin/codecs.wasm +0 -0
  76. package/codecs/wasm/bin/simd.wasm +0 -0
  77. package/codecs/wasm/bundle/browser.js +0 -1
  78. package/codecs/wasm/index.js +0 -1
  79. package/codecs/wasm/index.mjs +0 -1
  80. package/png/README.md +0 -1
  81. package/png/node.js +0 -1137
  82. package/png/src/crc.mjs +0 -49
  83. package/png/src/mem.mjs +0 -24
  84. package/png/src/png.mjs +0 -254
  85. package/png/src/zlib.mjs +0 -618
  86. package/tsconfig.json +0 -21
  87. package/utils/mem.js +0 -26
  88. package/v2/codecs/magic.js +0 -25
  89. package/v2/framebuffer.d.ts +0 -67
  90. package/v2/framebuffer.js +0 -2352
  91. package/v2/framebuffer.mjs +0 -126
  92. package/v2/framebuffer.rs +0 -1264
  93. package/v2/index.d.ts +0 -84
  94. package/v2/index.js +0 -261
  95. package/v2/ops/blur.mjs +0 -303
  96. package/v2/ops/color.mjs +0 -277
  97. package/v2/ops/crop.mjs +0 -64
  98. package/v2/ops/fill.mjs +0 -33
  99. package/v2/ops/flip.mjs +0 -33
  100. package/v2/ops/index.mjs +0 -9
  101. package/v2/ops/iterator.mjs +0 -34
  102. package/v2/ops/overlay.mjs +0 -63
  103. package/v2/ops/resize.mjs +0 -166
  104. package/v2/ops/rotate.mjs +0 -117
  105. package/v2/util/mem.mjs +0 -24
  106. package/wasm/any/font.wasm +0 -0
  107. package/wasm/any/gif.wasm +0 -0
  108. package/wasm/any/jpeg.wasm +0 -0
  109. package/wasm/any/png.wasm +0 -0
  110. package/wasm/any/svg.wasm +0 -0
  111. package/wasm/any/tiff.wasm +0 -0
  112. package/wasm/node/font.js +0 -142
  113. package/wasm/node/gif.js +0 -76
  114. package/wasm/node/jpeg.js +0 -92
  115. package/wasm/node/png.js +0 -49
  116. package/wasm/node/svg.js +0 -56
  117. package/wasm/node/tiff.js +0 -47
@@ -0,0 +1,521 @@
1
+ import { BinaryData } from './util/mem.js';
2
+ import { TextLayout } from './text-layout.js';
3
+ /** A color as a 32-bit RGBA integer (`0xRRGGBBAA`) */
4
+ export type Color = number;
5
+ /** Called with a pixel's (0-based) coordinates, returns its color */
6
+ export type ColorFunction = (x: number, y: number) => Color;
7
+ /** Resampling filters for {@link Image.resize} and the other scaling functions, see {@link Image.RESIZE_BILINEAR} etc. */
8
+ export type ResizeMode = 'RESIZE_NEAREST_NEIGHBOR' | 'RESIZE_BILINEAR' | 'RESIZE_BICUBIC' | 'RESIZE_AREA';
9
+ /** How {@link Image.renderSVG} scales: {@link Image.SVG_MODE_SCALE}, {@link Image.SVG_MODE_WIDTH} or {@link Image.SVG_MODE_HEIGHT} */
10
+ export type SVGScaleMode = 1 | 2 | 3;
11
+ /** Blend modes of {@link Image.composite}, named like CSS' mix-blend-mode values */
12
+ export type BlendMode = 'normal' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'add';
13
+ /** Options of {@link Image.composite} */
14
+ export interface CompositeOptions {
15
+ /** Opacity of the source (0..1). Default: `1` */
16
+ opacity?: number;
17
+ /** How the colors are mixed. Default: `'normal'` */
18
+ mode?: BlendMode;
19
+ }
20
+ /** Options of {@link Image.decode} */
21
+ export interface DecodeOptions {
22
+ /** Whether to rotate/mirror JPEGs, TIFFs and PNGs as their orientation tag (Exif or XMP) says. Default: `true` */
23
+ applyOrientation?: boolean;
24
+ }
25
+ /** Text style options of {@link Image.renderText} */
26
+ export interface TextStyle {
27
+ /** Width of an outline around the glyphs in pixels. Default: `0` */
28
+ strokeWidth?: number;
29
+ /** Color of the outline. Default: `0x000000ff` */
30
+ strokeColor?: Color;
31
+ }
32
+ /** Options of {@link Image.cropCircle} */
33
+ export interface CropCircleOptions {
34
+ /** Whether to use the larger dimension for the size. Default: `false` */
35
+ max?: boolean;
36
+ /** Share of the radius (0..1) over which the edge fades out. Default: `0` */
37
+ feathering?: number;
38
+ }
39
+ /** Options of {@link Image.dominantColor} */
40
+ export interface DominantColorOptions {
41
+ /** Whether to ignore dark colors (all channels below the threshold). Default: `true` */
42
+ ignoreBlack?: boolean;
43
+ /** Whether to ignore light colors (all channels above 255 minus the threshold). Default: `true` */
44
+ ignoreWhite?: boolean;
45
+ /** The black/white threshold (0-64, in steps of 4 channel values). Default: `15` */
46
+ threshold?: number;
47
+ }
48
+ /** Options of {@link Image.rotate} */
49
+ export interface RotateOptions {
50
+ /** Whether to resize the image so it fits all pixels or just ignore outlying pixels. Default: `true` */
51
+ resize?: boolean;
52
+ }
53
+ /** Text metadata written into PNGs by {@link Image.encode} */
54
+ export interface PNGMetadata {
55
+ /** The image's title */
56
+ title?: string;
57
+ /** The image's author */
58
+ author?: string;
59
+ /** The image's description */
60
+ description?: string;
61
+ /** The image's copyright info */
62
+ copyright?: string;
63
+ /** The image's creation time. Default: now */
64
+ creationTime?: string | number | Date;
65
+ /** The software used to create the image. Default: `'github.com/matmen/ImageScript vX.X.X'`, `''` leaves it out */
66
+ software?: string;
67
+ /** A disclaimer for the image */
68
+ disclaimer?: string;
69
+ /** A warning for the image */
70
+ warning?: string;
71
+ /** The image's source */
72
+ source?: string;
73
+ /** A comment for the image */
74
+ comment?: string;
75
+ }
76
+ /**
77
+ * An RGBA image; provides the codecs and the manipulation functions. Methods that change the image modify it in place
78
+ * and return it, so calls can be chained
79
+ */
80
+ export declare class Image {
81
+ /**
82
+ * Creates a new image with the given dimensions
83
+ * @param width
84
+ * @param height
85
+ */
86
+ constructor(width: number, height: number);
87
+ /**
88
+ * The image's RGBA pixel data. It can be replaced by any 8-bit array with width * height * 4 bytes
89
+ * (it is used as is, without copying)
90
+ */
91
+ get bitmap(): Uint8ClampedArray;
92
+ /** Replaces the pixel data, the array has to hold width * height * 4 bytes */
93
+ set bitmap(bitmap: Uint8ClampedArray | Uint8Array);
94
+ /**
95
+ * @private
96
+ */
97
+ toString(): string;
98
+ /**
99
+ * The images width
100
+ */
101
+ get width(): number;
102
+ /**
103
+ * The images height
104
+ */
105
+ get height(): number;
106
+ /**
107
+ * Yields an [x, y] array for every pixel in the image (0-based)
108
+ * @yields The coordinates of the pixel ([x, y])
109
+ */
110
+ [Symbol.iterator](): Generator<[x: number, y: number], void, undefined>;
111
+ /**
112
+ * Yields an [x, y, color] array for every pixel in the image (0-based)
113
+ * @yields The coordinates and color of the pixel ([x, y, color])
114
+ */
115
+ iterateWithColors(): Generator<[x: number, y: number, color: Color], void, undefined>;
116
+ /**
117
+ * Converts RGBA components to an RGBA value, values are rounded and clamped to 0..255
118
+ * @param r red (0..255)
119
+ * @param g green (0..255)
120
+ * @param b blue (0..255)
121
+ * @param a alpha (0..255)
122
+ * @returns RGBA value
123
+ */
124
+ static rgbaToColor(r: number, g: number, b: number, a: number): Color;
125
+ /**
126
+ * Converts RGB components to an RGBA value (assuming alpha = 255)
127
+ * @param r red (0..255)
128
+ * @param g green (0..255)
129
+ * @param b blue (0..255)
130
+ * @returns RGBA value
131
+ */
132
+ static rgbToColor(r: number, g: number, b: number): Color;
133
+ /**
134
+ * Converts HSLA colors to RGBA colors
135
+ * @param h hue (0..1)
136
+ * @param s saturation (0..1)
137
+ * @param l lightness (0..1)
138
+ * @param a opacity (0..1)
139
+ * @returns color
140
+ */
141
+ static hslaToColor(h: number, s: number, l: number, a: number): Color;
142
+ /**
143
+ * Converts HSL colors to RGBA colors (assuming an opacity of 255)
144
+ * @param h hue (0..1)
145
+ * @param s saturation (0..1)
146
+ * @param l lightness (0..1)
147
+ * @returns color
148
+ */
149
+ static hslToColor(h: number, s: number, l: number): Color;
150
+ /**
151
+ * Converts an RGBA value to an array of HSLA values
152
+ * @param r {number} (0..255)
153
+ * @param g {number} (0..255)
154
+ * @param b {number} (0..255)
155
+ * @param a {number} (0..255)
156
+ * @returns The HSLA values ([H, S, L, A])
157
+ */
158
+ static rgbaToHSLA(r: number, g: number, b: number, a: number): [h: number, s: number, l: number, a: number];
159
+ /**
160
+ * Converts a color value to an array of RGBA values
161
+ * @param color The color value to convert
162
+ * @returns The RGBA values ([R, G, B, A])
163
+ */
164
+ static colorToRGBA(color: Color): [r: number, g: number, b: number, a: number];
165
+ /**
166
+ * Converts a color value to an array of RGB values (ignoring the colors alpha)
167
+ * @param color The color value to convert
168
+ * @returns The RGB values ([R, G, B])
169
+ */
170
+ static colorToRGB(color: Color): [r: number, g: number, b: number];
171
+ /**
172
+ * Gets the pixel color at the specified position (0-based)
173
+ * @param x
174
+ * @param y
175
+ * @returns The color value
176
+ */
177
+ getPixelAt(x: number, y: number): Color;
178
+ /**
179
+ * Gets a view of the RGBA components of the pixel at the specified position (0-based)
180
+ * @param x
181
+ * @param y
182
+ * @returns The RGBA value
183
+ */
184
+ getRGBAAt(x: number, y: number): Uint8ClampedArray;
185
+ /**
186
+ * Sets the pixel color for the specified position (0-based)
187
+ * @param x
188
+ * @param y
189
+ * @param pixelColor
190
+ */
191
+ setPixelAt(x: number, y: number, pixelColor: Color): this;
192
+ /**
193
+ * @callback colorFunction
194
+ * @param x 0-based x coordinate
195
+ * @param y 0-based y coordinate
196
+ * @returns pixel color
197
+ */
198
+ /**
199
+ * Fills the image data with the supplied color
200
+ * @param color
201
+ */
202
+ fill(color: Color | ColorFunction): this;
203
+ /**
204
+ * Clones the current image
205
+ */
206
+ clone(): Image;
207
+ /**
208
+ * Use {@link https://en.wikipedia.org/wiki/Image_scaling#Nearest-neighbor_interpolation Nearest-neighbor} resizing.
209
+ */
210
+ static get RESIZE_NEAREST_NEIGHBOR(): 'RESIZE_NEAREST_NEIGHBOR';
211
+ /**
212
+ * Bilinear resizing (the default). When shrinking, the filter widens with the scale factor, so every source pixel contributes
213
+ */
214
+ static get RESIZE_BILINEAR(): 'RESIZE_BILINEAR';
215
+ /**
216
+ * Bicubic (Catmull-Rom) resizing, sharper than bilinear, especially when enlarging
217
+ */
218
+ static get RESIZE_BICUBIC(): 'RESIZE_BICUBIC';
219
+ /**
220
+ * Area averaging (box filter): every output pixel is the average of the source pixels it covers. Meant for shrinking
221
+ */
222
+ static get RESIZE_AREA(): 'RESIZE_AREA';
223
+ /**
224
+ * Used for automatically preserving an images aspect ratio when resizing.
225
+ */
226
+ static get RESIZE_AUTO(): -1;
227
+ /**
228
+ * Resizes the image by the given factor
229
+ * @param factor The factor to resize the image with
230
+ * @param [mode=Image.RESIZE_BILINEAR] The resizing mode to use
231
+ */
232
+ scale(factor: number, mode?: ResizeMode): this;
233
+ /**
234
+ * Resizes the image to the given dimensions.
235
+ * Use {@link Image.RESIZE_AUTO} as either width or height to automatically preserve the aspect ratio.
236
+ * @param width The new width
237
+ * @param height The new height
238
+ * @param [mode=Image.RESIZE_BILINEAR] The resizing mode to use
239
+ * @returns The resized image
240
+ */
241
+ resize(width: number, height: number, mode?: ResizeMode): this;
242
+ /**
243
+ * Resizes the image so it is contained in the given bounding box.
244
+ * Can return an image with one axis smaller than the given bounding box.
245
+ * @param width The width of the bounding box
246
+ * @param height The height of the bounding box
247
+ * @param [mode=Image.RESIZE_BILINEAR] The resizing mode to use
248
+ * @returns The resized image
249
+ */
250
+ contain(width: number, height: number, mode?: ResizeMode): this;
251
+ /**
252
+ * Resizes the image so it is contained in the given bounding box, placing it in the center of the given bounding box.
253
+ * Always returns the exact dimensions of the bounding box.
254
+ * @param width The width of the bounding box
255
+ * @param height The height of the bounding box
256
+ * @param [mode=Image.RESIZE_BILINEAR] The resizing mode to use
257
+ * @returns The resized image
258
+ */
259
+ fit(width: number, height: number, mode?: ResizeMode): this;
260
+ /**
261
+ * Resizes the image so it covers the given bounding box, cropping the overflowing edges.
262
+ * Always returns the exact dimensions of the bounding box.
263
+ * @param width The width of the bounding box
264
+ * @param height The height of the bounding box
265
+ * @param [mode=Image.RESIZE_BILINEAR] The resizing mode to use
266
+ * @returns The resized image
267
+ */
268
+ cover(width: number, height: number, mode?: ResizeMode): this;
269
+ /**
270
+ * Crops an image to the specified dimensions.
271
+ * The region is clipped to the image, so the result can be smaller than the requested size
272
+ * @param x The x offset (0-based)
273
+ * @param y The y offset (0-based)
274
+ * @param width The new images width
275
+ * @param height The new images height
276
+ */
277
+ crop(x: number, y: number, width: number, height: number): this;
278
+ /**
279
+ * Draws a box at the specified coordinates (0-based), clipped to the image
280
+ * @param x The x offset
281
+ * @param y The y offset
282
+ * @param width The box width
283
+ * @param height The box height
284
+ * @param color The color to fill the box in with, a function gets coordinates relative to the box
285
+ */
286
+ drawBox(x: number, y: number, width: number, height: number, color: Color | ColorFunction): this;
287
+ /**
288
+ * Draws an antialiased circle around the center of the specified pixel (0-based)
289
+ * @param x The center x position
290
+ * @param y The center y position
291
+ * @param radius The circles radius in pixels
292
+ * @param color The color, a function gets coordinates relative to the circle's bounding box
293
+ */
294
+ drawCircle(x: number, y: number, radius: number, color: Color | ColorFunction): this;
295
+ /**
296
+ * Crops the image into a circle with an antialiased edge
297
+ * @param options See {@link CropCircleOptions}
298
+ */
299
+ cropCircle(options?: CropCircleOptions): this;
300
+ /**
301
+ * Crops the image into a circle with an antialiased edge
302
+ * @param max Whether to use the larger dimension for the size. Default: `false`
303
+ * @param feathering Share of the radius (0..1) over which the edge fades out. Default: `0`
304
+ */
305
+ cropCircle(max?: boolean, feathering?: number): this;
306
+ /**
307
+ * Sets the images opacity
308
+ * @param opacity The opacity to apply (0..1)
309
+ * @param absolute Whether to scale the current opacity (false) or just set the new opacity (true)
310
+ */
311
+ opacity(opacity: number, absolute?: boolean): this;
312
+ /**
313
+ * Scales or sets the red channel
314
+ * @param factor The factor to multiply the channel with (>= 0, results are clamped), or the value (0..1) to set it to
315
+ * @param absolute Whether to scale the current value (false) or set every pixel's red channel to `factor` * 255 (true)
316
+ */
317
+ red(factor: number, absolute?: boolean): this;
318
+ /**
319
+ * Scales or sets the green channel
320
+ * @param factor The factor to multiply the channel with (>= 0, results are clamped), or the value (0..1) to set it to
321
+ * @param absolute Whether to scale the current value (false) or set every pixel's green channel to `factor` * 255 (true)
322
+ */
323
+ green(factor: number, absolute?: boolean): this;
324
+ /**
325
+ * Scales or sets the blue channel
326
+ * @param factor The factor to multiply the channel with (>= 0, results are clamped), or the value (0..1) to set it to
327
+ * @param absolute Whether to scale the current value (false) or set every pixel's blue channel to `factor` * 255 (true)
328
+ */
329
+ blue(factor: number, absolute?: boolean): this;
330
+ /**
331
+ * Sets the brightness of the image
332
+ * @param value The lightness to apply (0..1)
333
+ * @param absolute Whether to scale the current lightness (false) or just set the new lightness (true)
334
+ */
335
+ lightness(value: number, absolute?: boolean): this;
336
+ /**
337
+ * Sets the saturation of the image
338
+ * @param value The saturation to apply (0..1)
339
+ * @param absolute Whether to scale the current saturation (false) or just set the new saturation (true)
340
+ */
341
+ saturation(value: number, absolute?: boolean): this;
342
+ /**
343
+ * Composites (overlays) the source onto this image at the specified coordinates
344
+ * @param source The image to place
345
+ * @param [x=0] The x position to place the image at
346
+ * @param [y=0] The y position to place the image at
347
+ * @param options Opacity and blend mode, see {@link CompositeOptions}
348
+ */
349
+ composite(source: Image, x?: number, y?: number, options?: CompositeOptions): this;
350
+ /**
351
+ * Inverts the images colors
352
+ */
353
+ invert(): this;
354
+ /**
355
+ * Inverts the images lightness (HSL), keeping hue and saturation: dark colors become light and vice versa
356
+ */
357
+ invertLightness(): this;
358
+ /**
359
+ * Inverts the images value (HSV), keeping hue and saturation: the brightest channel `v` becomes `255 - v`
360
+ * and the others scale along, black becomes white
361
+ */
362
+ invertValue(): this;
363
+ /**
364
+ * Shifts the images hue
365
+ * @param degrees How many degrees to shift the hue by
366
+ */
367
+ hueShift(degrees: number): this;
368
+ /**
369
+ * Blurs the image with a gaussian blur (transparent pixels don't bleed their color)
370
+ * @param radius The blur radius: the gaussian's standard deviation in pixels, like CSS' blur()
371
+ */
372
+ blur(radius: number): this;
373
+ /**
374
+ * Sharpens the image with an unsharp mask: the difference to a blurred copy is amplified
375
+ * @param [amount=1] How strongly to sharpen (0 does nothing)
376
+ * @param [radius=1] The radius of the blur the image is compared with (larger values sharpen coarser details)
377
+ */
378
+ sharpen(amount?: number, radius?: number): this;
379
+ /**
380
+ * Multiplies the color channels, e.g. 1.2 makes the image 20% brighter
381
+ * @param factor The factor (>= 0, 1 keeps the image)
382
+ */
383
+ brightness(factor: number): this;
384
+ /**
385
+ * Scales the color channels' distance from mid grey, e.g. 1.5 increases the contrast, 0.5 reduces it
386
+ * @param factor The factor (>= 0, 1 keeps the image, 0 makes it grey)
387
+ */
388
+ contrast(factor: number): this;
389
+ /**
390
+ * Applies a gamma correction, values above 1 brighten the dark tones, values below 1 darken them
391
+ * @param gamma The gamma (> 0, 1 keeps the image)
392
+ */
393
+ gamma(gamma: number): this;
394
+ /**
395
+ * Converts the image to greyscale by its luma (ITU-R 601, like Pillow), keeping the alpha
396
+ */
397
+ greyscale(): this;
398
+ /**
399
+ * Applies a sepia tone
400
+ */
401
+ sepia(): this;
402
+ /**
403
+ * Gets the average color of the image, weighting each pixel by its opacity
404
+ * @returns The average color (fully opaque), black for fully transparent images
405
+ */
406
+ averageColor(): Color;
407
+ /**
408
+ * Gets the image's dominant color: the colors are grouped into a few clusters (median cut and k-means),
409
+ * the average color of the largest one is returned
410
+ * @param options Which colors to ignore, see {@link DominantColorOptions}
411
+ * @return The image's dominant color (fully opaque); mostly transparent pixels are ignored.
412
+ * If every pixel is ignored as black or white, the filter is dropped
413
+ */
414
+ dominantColor(options?: DominantColorOptions): Color;
415
+ /**
416
+ * Gets the image's dominant color, see {@link Image.dominantColor | the variant with options}
417
+ * @param ignoreBlack Whether to ignore dark colors (all channels below the threshold). Default: `true`
418
+ * @param ignoreWhite Whether to ignore light colors (all channels above 255 minus the threshold). Default: `true`
419
+ * @param bwThreshold The black/white threshold (0-64, in steps of 4 channel values). Default: `15`
420
+ * @return The image's dominant color (fully opaque)
421
+ */
422
+ dominantColor(ignoreBlack?: boolean, ignoreWhite?: boolean, bwThreshold?: number): Color;
423
+ /**
424
+ * Rotates the image counterclockwise by the given amount of degrees
425
+ * @param angle The angle to rotate the image for (in degrees)
426
+ * @param options See {@link RotateOptions}
427
+ */
428
+ rotate(angle: number, options?: RotateOptions): this;
429
+ /**
430
+ * Rotates the image counterclockwise by the given amount of degrees
431
+ * @param angle The angle to rotate the image for (in degrees)
432
+ * @param resize Whether to resize the image so it fits all pixels or just ignore outlying pixels. Default: `true`
433
+ */
434
+ rotate(angle: number, resize?: boolean): this;
435
+ /**
436
+ * Flips / mirrors the image horizontally or vertically
437
+ * @param direction The direction to flip
438
+ */
439
+ flip(direction: 'horizontal' | 'vertical'): this;
440
+ /**
441
+ * Creates a multi-point gradient generator
442
+ * @param colors The gradient points to use (e.g. `{0: 0xff0000ff, 1: 0x00ff00ff}`)
443
+ * @return The gradient generator. The function argument is the position in the gradient (0..1).
444
+ */
445
+ static gradient(colors: Record<number, Color>): (position: number) => Color;
446
+ /**
447
+ * Rounds the images corners, with antialiased edges
448
+ * @param [radius=min(width,height)/4] The radius of the corners
449
+ */
450
+ roundCorners(radius?: number): this;
451
+ /**
452
+ * Applies a fisheye (barrel distortion) effect
453
+ * @param [strength=2] The distortion strength (exponent of the radial mapping), higher values bulge the center more
454
+ */
455
+ fisheye(strength?: number): this;
456
+ /**
457
+ * Encodes the image into a PNG, with the smallest lossless color type (a palette for up to 256 colors,
458
+ * greyscale or RGB, alpha only if needed). Uses the runtime's native zlib when available
459
+ * @param compression The compression level (0-9). Default: `1`
460
+ * @param metadata Text metadata to include
461
+ * @return The encoded data
462
+ */
463
+ encode(compression?: number, metadata?: PNGMetadata): Promise<Uint8Array>;
464
+ /**
465
+ * Encodes the image into a PNG with compression level 1
466
+ * @param metadata Text metadata to include
467
+ * @return The encoded data
468
+ */
469
+ encode(metadata?: PNGMetadata): Promise<Uint8Array>;
470
+ /**
471
+ * Encodes the image into a PNG, an alias of {@link Image.encode}
472
+ */
473
+ encodePNG(compression?: number, metadata?: PNGMetadata): Promise<Uint8Array>;
474
+ encodePNG(metadata?: PNGMetadata): Promise<Uint8Array>;
475
+ /**
476
+ * Encodes the image into a JPEG
477
+ * @param [quality=90] The JPEG quality to use (1-100), chroma subsampling is disabled above 90
478
+ */
479
+ encodeJPEG(quality?: number): Promise<Uint8Array>;
480
+ /**
481
+ * Decodes an image (PNG, JPEG or TIFF)
482
+ * @param input The binary data to decode
483
+ * @param options See {@link DecodeOptions}. JPEGs, TIFFs and PNGs are rotated/mirrored as their orientation tag
484
+ * (Exif, for PNGs also XMP) says by default: photos taken with a rotated camera are stored sideways
485
+ * @return The decoded image
486
+ */
487
+ static decode(input: BinaryData, options?: DecodeOptions): Promise<Image>;
488
+ /**
489
+ * Scale the SVG by the given amount. For use with {@link Image.renderSVG}
490
+ */
491
+ static get SVG_MODE_SCALE(): 1;
492
+ /**
493
+ * Scale the SVG to fit the given width. For use with {@link Image.renderSVG}
494
+ */
495
+ static get SVG_MODE_WIDTH(): 2;
496
+ /**
497
+ * Scale the SVG to fit the given height. For use with {@link Image.renderSVG}
498
+ */
499
+ static get SVG_MODE_HEIGHT(): 3;
500
+ /**
501
+ * Creates a new image from the given SVG
502
+ * Supports shapes, paths, transforms, use/symbol, CSS styles, gradients, strokes, clip paths, masks and opacity;
503
+ * text, images, filters and patterns are not rendered
504
+ * @param svg The SVG content
505
+ * @param size The size to use
506
+ * @param mode The SVG resizing mode to use (one of {@link SVG_MODE_SCALE}, {@link SVG_MODE_WIDTH}, {@link SVG_MODE_HEIGHT})
507
+ * @return The rendered SVG graphic
508
+ */
509
+ static renderSVG(svg: string | BinaryData, size?: number, mode?: SVGScaleMode): Promise<Image>;
510
+ /**
511
+ * Creates a new image containing the rendered text.
512
+ * @param font TrueType (ttf/ttc) or OpenType (otf) font buffer to use
513
+ * @param size Font size in pixels (per em)
514
+ * @param text Text to render
515
+ * @param [color=0xffffffff] Text color to use
516
+ * @param [layout] The text layout to use
517
+ * @param style Outline, see {@link TextStyle}; the image grows by the outline width on every side
518
+ * @return The rendered text
519
+ */
520
+ static renderText(font: BinaryData, size: number, text: string, color?: Color, layout?: TextLayout, style?: TextStyle): Promise<Image>;
521
+ }