imagescript 4.0.0-rc.3 → 4.0.0-rc.4

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/dist/image.d.ts CHANGED
@@ -22,13 +22,25 @@ export type ResizeMode = 'nearest-neighbor' | 'bilinear' | 'bicubic' | 'area';
22
22
  export type BlendMode = 'normal' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'add';
23
23
  /** Options of {@link Image.composite} */
24
24
  export interface CompositeOptions {
25
- /** The x position to place the source at. Default: `0` */
25
+ /**
26
+ * The x position to place the source at
27
+ * @defaultValue `0`
28
+ */
26
29
  x?: number;
27
- /** The y position to place the source at. Default: `0` */
30
+ /**
31
+ * The y position to place the source at
32
+ * @defaultValue `0`
33
+ */
28
34
  y?: number;
29
- /** Opacity of the source (0..1). Default: `1` */
35
+ /**
36
+ * Opacity of the source (0..1)
37
+ * @defaultValue `1`
38
+ */
30
39
  opacity?: number;
31
- /** How the colors are mixed. Default: `'normal'` */
40
+ /**
41
+ * How the colors are mixed
42
+ * @defaultValue `'normal'`
43
+ */
32
44
  mode?: BlendMode;
33
45
  }
34
46
  /** How {@link Image.resize}, {@link Frame.resize} and {@link Animation.resize} fit an image into a box */
@@ -44,9 +56,12 @@ export type ResizeToOptions = ResizeOptions & ({
44
56
  height?: number;
45
57
  /**
46
58
  * `'fill'` stretches to the exact size; `'inside'` keeps the aspect ratio and makes the image as large as fits
47
- * inside it, so one side can be smaller. Default: `'fill'`
59
+ * inside it, so one side can be smaller
60
+ * @defaultValue `'fill'`
48
61
  */
49
62
  fit?: 'fill' | 'inside';
63
+ /** Only with `fit: 'contain'` */
64
+ background?: never;
50
65
  } | {
51
66
  /** The exact width of the box */
52
67
  width: number;
@@ -54,7 +69,10 @@ export type ResizeToOptions = ResizeOptions & ({
54
69
  height: number;
55
70
  /** Keeps the aspect ratio and pads to the exact box */
56
71
  fit: 'contain';
57
- /** For `'contain'`, the color of the bars. Default: `0x00000000` (transparent) */
72
+ /**
73
+ * For `'contain'`, the color of the bars
74
+ * @defaultValue `0x00000000` (transparent)
75
+ */
58
76
  background?: Color;
59
77
  } | {
60
78
  /** The exact width of the box */
@@ -63,17 +81,28 @@ export type ResizeToOptions = ResizeOptions & ({
63
81
  height: number;
64
82
  /** Keeps the aspect ratio and crops to the exact box */
65
83
  fit: 'cover';
84
+ /** Only with `fit: 'contain'` */
85
+ background?: never;
66
86
  });
67
87
  /** Options of {@link Image.scale} and {@link Image.resize} */
68
88
  export interface ResizeOptions {
69
- /** The resizing mode. Default: `'bilinear'` */
89
+ /**
90
+ * The resizing mode
91
+ * @defaultValue `'bilinear'`
92
+ */
70
93
  mode?: ResizeMode;
71
94
  }
72
95
  /** Options of {@link Image.sharpen} */
73
96
  export interface SharpenOptions {
74
- /** How strongly to sharpen (0 does nothing). Default: `1` */
97
+ /**
98
+ * How strongly to sharpen (0 does nothing)
99
+ * @defaultValue `1`
100
+ */
75
101
  amount?: number;
76
- /** The radius of the blur the image is compared with (larger values sharpen coarser details). Default: `1` */
102
+ /**
103
+ * The radius of the blur the image is compared with (larger values sharpen coarser details)
104
+ * @defaultValue `1`
105
+ */
77
106
  radius?: number;
78
107
  }
79
108
  /**
@@ -86,10 +115,14 @@ export type DitherMethod = 'none' | 'floyd-steinberg' | 'atkinson' | 'ordered';
86
115
  export interface DitherOptions {
87
116
  /**
88
117
  * How to spread small color changes across nearby pixels to make gradients look smoother with few colors, see
89
- * {@link DitherMethod}. Default: `'floyd-steinberg'`
118
+ * {@link DitherMethod}
119
+ * @defaultValue `'floyd-steinberg'`
90
120
  */
91
121
  dither?: DitherMethod;
92
- /** How strongly to apply dithering: `0` disables it (like `'none'`); `1` applies it fully. Default: `0.85` */
122
+ /**
123
+ * How strongly to apply dithering: `0` disables it (like `'none'`); `1` applies it fully
124
+ * @defaultValue `0.85`
125
+ */
93
126
  ditherStrength?: number;
94
127
  }
95
128
  /**
@@ -100,7 +133,7 @@ export type QuantizeOptions = DitherOptions & ({
100
133
  /**
101
134
  * The maximum number of colors to keep (2-256). Images with fewer distinct colors keep them exactly; otherwise
102
135
  * ImageScript chooses a smaller set of representative colors. Give `palette` instead to choose exact colors.
103
- * Default: `256`
136
+ * @defaultValue `256`
104
137
  */
105
138
  colors?: number;
106
139
  /** Not with `colors`: give one of them */
@@ -124,54 +157,84 @@ export type AffineTransform = readonly [a: number, b: number, c: number, d: numb
124
157
  export interface TransformOptions {
125
158
  /**
126
159
  * The point the transform is applied around, in pixels: a rotation turns around it, a scale grows from it.
127
- * Default: the middle of the image. It only decides where the result lies on a canvas that stays as large as the
128
- * image (`expand: false`)
160
+ * It only decides where the result lies on a canvas that stays as large as the image (`expand: false`)
161
+ * @defaultValue The middle of the image
129
162
  */
130
163
  origin?: {
131
- /** The x position of the point in pixels. Default: half the width */
164
+ /**
165
+ * The x position of the point in pixels
166
+ * @defaultValue Half the width
167
+ */
132
168
  x?: number;
133
- /** The y position of the point in pixels. Default: half the height */
169
+ /**
170
+ * The y position of the point in pixels
171
+ * @defaultValue Half the height
172
+ */
134
173
  y?: number;
135
174
  };
136
175
  /**
137
176
  * Whether to make the image as large as the transformed one, which then fills it (a rotated image grows to fit its
138
177
  * corners, a skewed one gets wider). Without it, the image keeps its size and the parts outside are lost.
139
- * Default: `true`
178
+ * @defaultValue `true`
140
179
  */
141
180
  expand?: boolean;
142
181
  /**
143
182
  * How the pixels between the source's are sampled: `'nearest-neighbor'` (hard pixels, no smoothing, for pixel art),
144
- * `'bilinear'` (smooth), `'bicubic'` (sharper, slower, can overshoot a little at hard edges). Default: `'bilinear'`
183
+ * `'bilinear'` (smooth), `'bicubic'` (sharper, slower, can overshoot a little at hard edges)
184
+ * @defaultValue `'bilinear'`
145
185
  */
146
186
  mode?: TransformMode;
147
187
  }
148
188
  /** Options of {@link Image.dropShadow} */
149
189
  export interface ShadowOptions {
150
- /** How far to move the shadow to the right (negative values: to the left), in pixels. Default: `0` */
190
+ /**
191
+ * How far to move the shadow to the right (negative values: to the left), in pixels
192
+ * @defaultValue `0`
193
+ */
151
194
  x?: number;
152
- /** How far to move the shadow down (negative values: up), in pixels. Default: `0` */
195
+ /**
196
+ * How far to move the shadow down (negative values: up), in pixels
197
+ * @defaultValue `0`
198
+ */
153
199
  y?: number;
154
- /** How soft the shadow's edge is: the standard deviation of a gaussian blur in pixels, like {@link Image.blur}. Default: `0` */
200
+ /**
201
+ * How soft the shadow's edge is: the standard deviation of a gaussian blur in pixels, like {@link Image.blur}
202
+ * @defaultValue `0`
203
+ */
155
204
  blur?: number;
156
- /** How far to grow the shadow's shape before blurring it, in pixels. Default: `0` */
205
+ /**
206
+ * How far to grow the shadow's shape before blurring it, in pixels
207
+ * @defaultValue `0`
208
+ */
157
209
  spread?: number;
158
- /** The shadow's color, its alpha is the shadow's opacity. Default: `0x00000080` (50% black) */
210
+ /**
211
+ * The shadow's color, its alpha is the shadow's opacity
212
+ * @defaultValue `0x00000080` (50% black)
213
+ */
159
214
  color?: Color;
160
215
  /**
161
216
  * Whether to make the image larger so the shadow isn't cut off. Without it, the image keeps its size and the part
162
- * of the shadow outside is lost. Default: `true`
217
+ * of the shadow outside is lost
218
+ * @defaultValue `true`
163
219
  */
164
220
  expand?: boolean;
165
221
  }
166
222
  /** Options of {@link Image.outline} */
167
223
  export interface OutlineOptions {
168
- /** The outline's width in pixels. Default: `1` */
224
+ /**
225
+ * The outline's width in pixels
226
+ * @defaultValue `1`
227
+ */
169
228
  width?: number;
170
- /** The outline's color. Default: `0x000000ff` */
229
+ /**
230
+ * The outline's color
231
+ * @defaultValue `0x000000ff`
232
+ */
171
233
  color?: Color;
172
234
  /**
173
235
  * Whether to make the image larger so the outline isn't cut off. Without it, the image keeps its size and the
174
- * outline is cut where the image ends. Default: `true`
236
+ * outline is cut where the image ends
237
+ * @defaultValue `true`
175
238
  */
176
239
  expand?: boolean;
177
240
  }
@@ -188,17 +251,27 @@ export interface LinearGradientOptions extends GradientOptions {
188
251
  /**
189
252
  * The direction of the gradient in degrees, like CSS' `linear-gradient()`: `0` goes up, `90` to the right, `180`
190
253
  * down, `270` to the left. The first stop is at the start of the line through the center that touches the
191
- * corners. Default: `180`
254
+ * corners
255
+ * @defaultValue `180`
192
256
  */
193
257
  angle?: number;
194
258
  }
195
259
  /** Options of {@link Image.radialGradient} */
196
260
  export interface RadialGradientOptions extends GradientOptions {
197
- /** The x position of the center in pixels. Default: the middle of the image */
261
+ /**
262
+ * The x position of the center in pixels
263
+ * @defaultValue The middle of the image
264
+ */
198
265
  x?: number;
199
- /** The y position of the center in pixels. Default: the middle of the image */
266
+ /**
267
+ * The y position of the center in pixels
268
+ * @defaultValue The middle of the image
269
+ */
200
270
  y?: number;
201
- /** The radius of the last stop in pixels. Default: the distance to the farthest corner */
271
+ /**
272
+ * The radius of the last stop in pixels
273
+ * @defaultValue The distance to the farthest corner
274
+ */
202
275
  radius?: number;
203
276
  }
204
277
  /** The options every encoder that writes metadata has */
@@ -212,15 +285,22 @@ export interface EncodeOptions {
212
285
  */
213
286
  export interface GainMapEmbedOptions {
214
287
  /**
215
- * The map's quality (1-100, like the format's `quality`; for JPEG XL 100 is lossless). Default: `90`
288
+ * The map's quality (1-100, like the format's `quality`; for JPEG XL 100 is lossless)
289
+ * @defaultValue `90`
216
290
  */
217
291
  quality?: number;
218
- /** The map's size as a factor of the image's (0-1). Default: the map's own size */
292
+ /**
293
+ * The map's size as a factor of the image's (0-1)
294
+ * @defaultValue The map's own size
295
+ */
219
296
  scale?: number;
220
297
  }
221
298
  /** Options of {@link Image.encodePNG} */
222
299
  export interface PNGEncodeOptions extends EncodeOptions {
223
- /** The compression level (0-9), higher is smaller but slower. Default: `4` */
300
+ /**
301
+ * The compression level (0-9), higher is smaller but slower
302
+ * @defaultValue `4`
303
+ */
224
304
  compression?: number;
225
305
  }
226
306
  /** Options of {@link Image.encodeTGA}: the metadata, which TGA keeps in its extension area */
@@ -230,28 +310,33 @@ export interface TGAEncodeOptions extends EncodeOptions {
230
310
  export interface GIFEncodeOptions extends EncodeOptions, DitherOptions {
231
311
  /**
232
312
  * The maximum colors in each frame's palette (2-256, including transparency). Frames with fewer colors keep them
233
- * exactly; otherwise ImageScript chooses representative colors. Default: `256`
313
+ * exactly; otherwise ImageScript chooses representative colors
314
+ * @defaultValue `256`
234
315
  */
235
316
  colors?: number;
236
317
  }
237
318
  /** Options of {@link Image.encodeJPEG} */
238
319
  export interface JPEGEncodeOptions extends EncodeOptions {
239
- /** The JPEG quality (0-100, 0 is the same as 1). Default: `90` */
320
+ /**
321
+ * The JPEG quality (0-100, 0 is the same as 1)
322
+ * @defaultValue `90`
323
+ */
240
324
  quality?: number;
241
325
  /**
242
326
  * How much color detail to keep: `'4:4:4'` keeps it all; `'4:2:0'` stores less color detail to make a smaller
243
- * file (often hard to notice in photos, but more visible around colored edges). Default: `'4:2:0'` up to quality
244
- * 90, `'4:4:4'` above
327
+ * file (often hard to notice in photos, but more visible around colored edges)
328
+ * @defaultValue `'4:2:0'` up to quality 90, `'4:4:4'` above
245
329
  */
246
330
  subsampling?: '4:4:4' | '4:2:0';
247
331
  /**
248
332
  * The background color to combine with transparent pixels, since JPEG doesn't support transparency. Opaque images
249
- * are encoded as they are. Default: `0x000000ff` (black)
333
+ * are encoded as they are
334
+ * @defaultValue `0x000000ff` (black)
250
335
  */
251
336
  background?: Color;
252
337
  /**
253
338
  * Whether to write the image's {@link Image.gainMap} (an Ultra HDR JPEG, brighter on HDR displays), or how.
254
- * Default: `true` (written if there is one)
339
+ * @defaultValue `true` (written if there is one)
255
340
  */
256
341
  gainMap?: boolean | GainMapEmbedOptions;
257
342
  }
@@ -264,33 +349,48 @@ export interface WebPEncodeOptions extends EncodeOptions {
264
349
  quality?: number;
265
350
  /**
266
351
  * Compression effort (0-6): higher values usually take longer but may make smaller files. For lossless images,
267
- * `0` prioritizes speed; `2` and above spend more time reducing file size. Default: `2`
352
+ * `0` prioritizes speed; `2` and above spend more time reducing file size
353
+ * @defaultValue `2`
268
354
  */
269
355
  effort?: number;
270
356
  /**
271
357
  * For lossy compression: improve color detail around sharp edges (for example, red text on a blue background).
272
- * This can take longer and make graphics larger. Default: `false`
358
+ * This can take longer and make graphics larger
359
+ * @defaultValue `false`
273
360
  */
274
361
  sharpYuv?: boolean;
275
362
  /**
276
363
  * For lossy compression, the transparency (alpha) channel's quality (0-100). Lower values may make the image
277
- * smaller but can make transparency look less smooth. Default: `100` (full quality)
364
+ * smaller but can make transparency look less smooth
365
+ * @defaultValue `100` (full quality)
278
366
  */
279
367
  alphaQuality?: number;
280
368
  /**
281
369
  * For lossless compression, the maximum worker threads to use. Small images or runtimes that cannot share memory
282
- * between workers use one thread. Default: the available processors, up to 8
370
+ * between workers use one thread
371
+ * @remarks
372
+ * Where workers can't start, the work runs on the calling thread with the same output. That includes browser pages
373
+ * that aren't cross-origin isolated and ones that load the package from another origin (a CDN such as jsDelivr),
374
+ * which browsers don't allow to start workers
375
+ * @defaultValue The available processors, up to 8
283
376
  */
284
377
  threads?: number;
285
378
  }
286
379
  /** Options of {@link Image.roundCorners} */
287
380
  export interface RoundCornersOptions {
288
- /** The radius of the corners. Default: a quarter of the smaller side */
381
+ /**
382
+ * The radius of the corners, 0 or more; one above half the smaller side is cut to that
383
+ * @defaultValue A quarter of the smaller side
384
+ */
289
385
  radius?: number;
290
386
  }
291
387
  /** Options of {@link Image.fisheye} */
292
388
  export interface FisheyeOptions {
293
- /** The distortion strength (exponent of the radial mapping), higher values bulge the center more. Default: `2` */
389
+ /**
390
+ * The distortion strength (exponent of the radial mapping), above 0: higher values bulge the center more. At 1 and
391
+ * below, the picture shrinks into the middle of the image, and 0 or less would leave nothing of it (it throws)
392
+ * @defaultValue `2`
393
+ */
294
394
  strength?: number;
295
395
  }
296
396
  /** The limits, fonts and images of {@link Image.renderSVG}, part of {@link RenderSVGOptions} */
@@ -298,7 +398,8 @@ export interface SVGResourceOptions {
298
398
  /**
299
399
  * Maximum total pixels in the rendered output. Output over the limit throws a RangeError before anything is
300
400
  * rendered. It's also the default of {@link SVGResourceOptions.maxLayerPixels} and
301
- * {@link SVGResourceOptions.maxImagePixels}. Default: `268402689` (16383²); `Infinity` disables the limit
401
+ * {@link SVGResourceOptions.maxImagePixels}
402
+ * @defaultValue `268402689` (16383²); `Infinity` disables the limit
302
403
  */
303
404
  maxPixels?: number;
304
405
  /**
@@ -307,13 +408,15 @@ export interface SVGResourceOptions {
307
408
  * output's size, 16 bytes per pixel) while their content is drawn, so deeply nested ones multiply the memory a
308
409
  * small SVG takes. Exceeding it throws a RangeError. With the defaults, rendering can take about 90 bytes per pixel
309
410
  * of `maxPixels` (64 for the layers, up to 20 for the images, 4 for the output): lower `maxPixels` to bound it for
310
- * untrusted SVGs. Default: `4 * maxPixels`; `Infinity` disables the limit
411
+ * untrusted SVGs
412
+ * @defaultValue `4 * maxPixels`; `Infinity` disables the limit
311
413
  */
312
414
  maxLayerPixels?: number;
313
415
  /**
314
416
  * Maximum total pixels of the raster images the SVG references (data URIs and {@link SVGResourceOptions.images}),
315
417
  * decoded together; already-decoded {@link Image} values are used as supplied and don't count. Drawing an image
316
- * beyond the limit throws a RangeError. Default: `maxPixels`; `Infinity` disables the limit
418
+ * beyond the limit throws a RangeError
419
+ * @defaultValue `maxPixels`; `Infinity` disables the limit
317
420
  */
318
421
  maxImagePixels?: number;
319
422
  /**
@@ -324,7 +427,8 @@ export interface SVGResourceOptions {
324
427
  * other families and text without one get the first font's family; characters a face doesn't have come from the
325
428
  * other fonts (TrueType, OpenType or WOFF). Fonts the SVG embeds with `@font-face` (in data: URIs) are used too,
326
429
  * before these for their family names. Without any fonts text isn't rendered. One font can be given without an
327
- * array. Default: `[]`
430
+ * array
431
+ * @defaultValue `[]`
328
432
  */
329
433
  font?: BinaryData | BinaryData[];
330
434
  /**
@@ -333,7 +437,8 @@ export interface SVGResourceOptions {
333
437
  * JPEG, WebP, GIF's first frame, ...) or {@link Image}s, decoded like data URI images are, and only for the hrefs
334
438
  * the SVG references. Nothing else is read: no files and no URLs, so drawing an image whose href isn't given (and
335
439
  * isn't a data URI) throws, as does drawing one that can't be decoded. SVG documents can't be given this way, use a
336
- * data URI for them. Default: `{}`
440
+ * data URI for them
441
+ * @defaultValue `{}`
337
442
  */
338
443
  images?: Record<string, BinaryData | Image>;
339
444
  }
@@ -342,7 +447,10 @@ export interface SVGResourceOptions {
342
447
  * more; by default the SVG's own size), and the limits, fonts and images (see {@link SVGResourceOptions})
343
448
  */
344
449
  export type RenderSVGOptions = SVGResourceOptions & ({
345
- /** The width in pixels, the height follows the SVG's aspect ratio. Default: the SVG's own width */
450
+ /**
451
+ * The width in pixels, the height follows the SVG's aspect ratio
452
+ * @defaultValue The SVG's own width
453
+ */
346
454
  width?: number;
347
455
  /** Not with `width`: give one of `width`, `height` and `scale` */
348
456
  height?: never;
@@ -360,7 +468,10 @@ export type RenderSVGOptions = SVGResourceOptions & ({
360
468
  width?: never;
361
469
  /** Not with `scale`: give one of `width`, `height` and `scale` */
362
470
  height?: never;
363
- /** A factor of the SVG's own size (`2` renders it twice as large). Default: `1` */
471
+ /**
472
+ * A factor of the SVG's own size (`2` renders it twice as large)
473
+ * @defaultValue `1`
474
+ */
364
475
  scale: number;
365
476
  });
366
477
  /**
@@ -379,11 +490,15 @@ export interface RenderTextOptions extends TextStyleOptions, TextLayoutOptions {
379
490
  font: BinaryData | BinaryData[];
380
491
  /** Font size in pixels (per em) */
381
492
  size: number;
382
- /** The text color. Default: `0xffffffff` */
493
+ /**
494
+ * The text color
495
+ * @defaultValue `0xffffffff`
496
+ */
383
497
  color?: Color;
384
498
  /**
385
499
  * Maximum total pixels of the rendered image (the outline included): larger text throws a RangeError before its
386
- * pixels are allocated. Default: `268402689` (16383²); `Infinity` disables the limit
500
+ * pixels are allocated
501
+ * @defaultValue `268402689` (16383²); `Infinity` disables the limit
387
502
  */
388
503
  maxPixels?: number;
389
504
  }
@@ -391,7 +506,8 @@ export interface RenderTextOptions extends TextStyleOptions, TextLayoutOptions {
391
506
  export interface DecodeOptions {
392
507
  /**
393
508
  * Whether to rotate or mirror the image according to its saved orientation information, so photos taken with a
394
- * rotated camera display upright. This applies to every animation frame too. Default: `true`
509
+ * rotated camera display upright. This applies to every animation frame too
510
+ * @defaultValue `true`
395
511
  */
396
512
  applyOrientation?: boolean;
397
513
  /**
@@ -399,7 +515,8 @@ export interface DecodeOptions {
399
515
  * colors to sRGB, the standard used by most screens and browsers. Common RGB and gray profiles described by a
400
516
  * color matrix and tone curves are converted, as are AVIFs using other color ranges (such as Display P3 or BT.2020).
401
517
  * Colors outside sRGB are clipped. Profiles that rely on lookup tables, CMYK profiles and profiles already in
402
- * sRGB are left unchanged. Default: `true`
518
+ * sRGB are left unchanged
519
+ * @defaultValue `true`
403
520
  */
404
521
  applyColorProfile?: boolean;
405
522
  /**
@@ -408,25 +525,31 @@ export interface DecodeOptions {
408
525
  * {@link Animation.decode} counts all frames together because each frame uses a full canvas. The decoded image
409
526
  * takes 4 bytes per pixel (about 1 GiB at the default), and decoding needs more while it runs: for 8-bit images,
410
527
  * about 4-7 bytes per pixel for PNG, JPEG, WebP, GIF and the simpler formats, about 14 for AVIF and about 30 for
411
- * JPEG XL (more with high bit depths). Lower it to bound the memory of servers decoding untrusted files. Default:
412
- * `268402689` (16383²); `Infinity` disables the limit
528
+ * JPEG XL (more with high bit depths). Lower it to bound the memory of servers decoding untrusted files
529
+ * @defaultValue `268402689` (16383²); `Infinity` disables the limit
413
530
  */
414
531
  maxPixels?: number;
415
532
  /**
416
533
  * How high-dynamic-range images (which can be brighter than a standard screen's white) become 8-bit sRGB.
417
534
  * `'reinhard'` gently compresses bright highlights so the brightest pixel becomes white; images that are not HDR
418
- * stay unchanged. `'clamp'` clips anything brighter than white. Default: `'reinhard'`
535
+ * stay unchanged. `'clamp'` clips anything brighter than white
536
+ * @defaultValue `'reinhard'`
419
537
  */
420
538
  toneMapping?: ToneMapping;
421
539
  /**
422
540
  * Whether to read extra HDR brightness data (a gain map) from supported JPEG, AVIF and JPEG XL images into
423
- * {@link Image.gainMap}. For animations, this also reads maps from supported JPEG XL frames. Default: `true`
541
+ * {@link Image.gainMap}. For animations, this also reads maps from supported JPEG XL frames
542
+ * @defaultValue `true`
424
543
  */
425
544
  gainMap?: boolean;
426
545
  /**
427
546
  * Maximum worker threads for formats and image sizes that can be decoded in parallel. Small images may use one
428
- * thread because starting workers can take longer than decoding them. Default: the available processors, up to 8
429
- * (one in runtimes that cannot share memory between workers)
547
+ * thread because starting workers can take longer than decoding them
548
+ * @remarks
549
+ * Where workers can't start, the work runs on the calling thread with the same output. That includes browser pages
550
+ * that aren't cross-origin isolated and ones that load the package from another origin (a CDN such as jsDelivr),
551
+ * which browsers don't allow to start workers
552
+ * @defaultValue The available processors, up to 8 (one in runtimes that cannot share memory between workers)
430
553
  */
431
554
  threads?: number;
432
555
  }
@@ -439,60 +562,91 @@ export interface JXLEncodeOptions extends EncodeOptions {
439
562
  quality?: number;
440
563
  /**
441
564
  * Compression effort (0-2): higher values usually take longer but may make smaller files. `0` prioritizes speed;
442
- * `2` spends the most time compressing. Default: `1`
565
+ * `2` spends the most time compressing
566
+ * @defaultValue `1`
443
567
  */
444
568
  effort?: number;
445
569
  /**
446
570
  * Maximum worker threads for compression. Small images or runtimes that cannot share memory between workers use
447
- * one thread. Default: the available processors, up to 8
571
+ * one thread
572
+ * @remarks
573
+ * Where workers can't start, the work runs on the calling thread with the same output. That includes browser pages
574
+ * that aren't cross-origin isolated and ones that load the package from another origin (a CDN such as jsDelivr),
575
+ * which browsers don't allow to start workers
576
+ * @defaultValue The available processors, up to 8
448
577
  */
449
578
  threads?: number;
450
579
  /**
451
580
  * Whether to write the image's {@link Image.gainMap}, the extra data used to show brighter highlights on HDR
452
- * displays. Default: `true` (written if there is one)
581
+ * displays
582
+ * @defaultValue `true` (written if there is one)
453
583
  */
454
584
  gainMap?: boolean | GainMapEmbedOptions;
455
585
  }
456
586
  /** Options of {@link Image.encodeAVIF} */
457
587
  export interface AVIFEncodeOptions extends EncodeOptions {
458
- /** 0-100, like avifenc's: higher is better and larger, 100 is lossless. Default: `60` */
588
+ /**
589
+ * 0-100, like avifenc's: higher is better and larger, 100 is lossless
590
+ * @defaultValue `60`
591
+ */
459
592
  quality?: number;
460
- /** The quality of the transparency channel, if the image has transparency. Default: `100` (lossless) */
593
+ /**
594
+ * The quality of the transparency channel, if the image has transparency
595
+ * @defaultValue `100` (lossless)
596
+ */
461
597
  alphaQuality?: number;
462
598
  /**
463
599
  * How much color detail to keep: `'4:4:4'` keeps it all; `'4:2:0'` stores less color detail to make a smaller
464
- * file. Default: `'4:4:4'`
600
+ * file
601
+ * @defaultValue `'4:4:4'`
465
602
  */
466
603
  subsampling?: '4:4:4' | '4:2:0';
467
- /** How hard the encoder searches for the best modes: 0-2, faster to smaller. Default: `1` */
604
+ /**
605
+ * How hard the encoder searches for the best modes: 0-2, faster to smaller
606
+ * @defaultValue `1`
607
+ */
468
608
  effort?: number;
469
609
  /**
470
610
  * Maximum worker threads for compression. Small images or runtimes that cannot share memory between workers use
471
- * one thread. Default: the available processors, up to 8
611
+ * one thread
612
+ * @remarks
613
+ * Where workers can't start, the work runs on the calling thread with the same output. That includes browser pages
614
+ * that aren't cross-origin isolated and ones that load the package from another origin (a CDN such as jsDelivr),
615
+ * which browsers don't allow to start workers
616
+ * @defaultValue The available processors, up to 8
472
617
  */
473
618
  threads?: number;
474
619
  /**
475
620
  * Whether to write the image's {@link Image.gainMap}, the extra data used to show brighter highlights on HDR
476
- * displays. Default: `true` (written if there is one)
621
+ * displays
622
+ * @defaultValue `true` (written if there is one)
477
623
  */
478
624
  gainMap?: boolean | GainMapEmbedOptions;
479
625
  }
480
626
  /** Text style options of {@link Image.renderText} */
481
627
  export interface TextStyleOptions {
482
- /** Width of an outline around the glyphs in pixels. Default: `0` */
628
+ /**
629
+ * Width of an outline around the glyphs in pixels
630
+ * @defaultValue `0`
631
+ */
483
632
  strokeWidth?: number;
484
- /** Color of the outline. Default: `0x000000ff` */
633
+ /**
634
+ * Color of the outline
635
+ * @defaultValue `0x000000ff`
636
+ */
485
637
  strokeColor?: Color;
486
638
  /**
487
639
  * Whether to run the hinting instructions of TrueType fonts, which align stems and edges with the pixel grid for
488
640
  * crisper text at small sizes (like Windows renders text); the glyphs of hinted fonts are then placed on whole
489
- * pixels. Fonts without instructions (and CFF/OpenType outlines) aren't affected. Default: `true`
641
+ * pixels. Fonts without instructions (and CFF/OpenType outlines) aren't affected
642
+ * @defaultValue `true`
490
643
  */
491
644
  hinting?: boolean;
492
645
  /**
493
646
  * OpenType features by their tags, for the whole text: `true` turns one on (like `tnum` for tabular numbers,
494
647
  * `smcp` for small caps, `ss01` for a stylistic set), `false` off (also the ones on by default, like `liga` or
495
- * `kern`), a number picks an alternate (`salt: 2`). Fonts without a feature ignore it. Default: `{}`
648
+ * `kern`), a number picks an alternate (`salt: 2`). Fonts without a feature ignore it
649
+ * @defaultValue `{}`
496
650
  */
497
651
  features?: Record<string, boolean | number>;
498
652
  /**
@@ -501,41 +655,57 @@ export interface TextStyleOptions {
501
655
  * right), `italic` (`true`/`false`), `opticalSize` (the size the glyphs are designed for, in pixels; default: the
502
656
  * font size, like browsers' `font-optical-sizing: auto`), and other axes by their 4-character tag (like Roboto
503
657
  * Flex's `GRAD: 50`). Values outside an axis's range are clamped, axes a font doesn't have are ignored, fonts
504
- * without axes aren't affected. Default: `{}` (the fonts' default instances)
658
+ * without axes aren't affected
659
+ * @defaultValue `{}` (the fonts' default instances)
505
660
  */
506
661
  variations?: Record<string, number | boolean>;
507
662
  }
508
663
  /** Options of {@link Image.cropCircle} */
509
664
  export interface CropCircleOptions {
510
665
  /**
511
- * The circle's size: `'contain'` fits it inside the image (the smaller dimension is its diameter, no hard edges),
666
+ * How the circle fits the image: `'contain'` fits it inside the image (the smaller dimension is its diameter, no hard edges),
512
667
  * `'cover'` covers the image (the larger dimension is its diameter, the corners of a rectangular image stay
513
- * transparent on the shorter side). Default: `'contain'`
668
+ * transparent on the shorter side)
669
+ * @defaultValue `'contain'`
670
+ */
671
+ fit?: 'contain' | 'cover';
672
+ /**
673
+ * Share of the radius (0 to 1, a value outside of it throws) over which the edge fades out
674
+ * @defaultValue `0`
514
675
  */
515
- size?: 'contain' | 'cover';
516
- /** Share of the radius (0..1) over which the edge fades out. Default: `0` */
517
676
  feathering?: number;
518
677
  }
519
678
  /** Options of {@link Image.dominantColor} */
520
679
  export interface DominantColorOptions {
521
- /** Whether to ignore dark colors (all channels below `threshold`). Default: `true` */
680
+ /**
681
+ * Whether to ignore dark colors (all channels below `threshold`)
682
+ * @defaultValue `true`
683
+ */
522
684
  ignoreBlack?: boolean;
523
- /** Whether to ignore light colors (all channels above 255 minus `threshold`). Default: `true` */
685
+ /**
686
+ * Whether to ignore light colors (all channels above 255 minus `threshold`)
687
+ * @defaultValue `true`
688
+ */
524
689
  ignoreWhite?: boolean;
525
- /** How close (in channel values, 0-256) to black or white a color has to be to be ignored. Default: `60` */
690
+ /**
691
+ * How close (in channel values, 0-256) to black or white a color has to be to be ignored
692
+ * @defaultValue `60`
693
+ */
526
694
  threshold?: number;
527
695
  }
528
696
  /** Options of {@link Image.rotate} */
529
697
  export interface RotateOptions {
530
698
  /**
531
699
  * Whether to make the image larger so the rotated corners aren't cut off. Without it, the image keeps its size and
532
- * the parts outside are lost. Default: `true`
700
+ * the parts outside are lost
701
+ * @defaultValue `true`
533
702
  */
534
703
  expand?: boolean;
535
704
  /**
536
705
  * How the pixels between the source's are sampled for angles that aren't multiples of 90° (those move whole
537
706
  * pixels): `'nearest-neighbor'` (hard pixels, for pixel art), `'bilinear'` (smooth) or `'bicubic'` (sharper, can
538
- * overshoot a little at hard edges), like {@link TransformOptions.mode}. Default: `'bilinear'`
707
+ * overshoot a little at hard edges), like {@link TransformOptions.mode}
708
+ * @defaultValue `'bilinear'`
539
709
  */
540
710
  mode?: TransformMode;
541
711
  }
@@ -548,7 +718,8 @@ export interface TrimOptions {
548
718
  color?: Color;
549
719
  /**
550
720
  * How far (0-1) a pixel's channels may be from the color for it to be trimmed, e.g. for JPEG artifacts or
551
- * antialiasing. Default: `0`
721
+ * antialiasing
722
+ * @defaultValue `0`
552
723
  */
553
724
  tolerance?: number;
554
725
  }
@@ -556,9 +727,15 @@ export interface TrimOptions {
556
727
  export interface ColorToAlphaOptions {
557
728
  /** The color to remove, by default the color of the top left pixel (e.g. a background) */
558
729
  color?: Color;
559
- /** Pixels at most this far from the color (0-1) become fully transparent. Default: 0 */
730
+ /**
731
+ * Pixels at most this far from the color (0-1) become fully transparent
732
+ * @defaultValue 0
733
+ */
560
734
  transparencyThreshold?: number;
561
- /** Pixels at least this far from the color (0-1) stay fully opaque. Default: 1 */
735
+ /**
736
+ * Pixels at least this far from the color (0-1) stay fully opaque
737
+ * @defaultValue 1
738
+ */
562
739
  opacityThreshold?: number;
563
740
  }
564
741
  /**
@@ -570,6 +747,7 @@ export declare class Image {
570
747
  * Creates a new image with the given dimensions, all pixels transparent black
571
748
  * @param width The width in pixels
572
749
  * @param height The height in pixels
750
+ * @throws `RangeError` if the width or height is not a number of at least 1, or the image is too large to allocate
573
751
  */
574
752
  constructor(width: number, height: number);
575
753
  /**
@@ -580,7 +758,11 @@ export declare class Image {
580
758
  get gainMap(): GainMap | null;
581
759
  /**
582
760
  * Replaces the gain map
761
+ * @remarks
762
+ * The image uses a copy of the map: changing the image (resizing it, say) changes its own map only, also when the
763
+ * same map was given to other images, and later changes to the map you gave don't reach the image
583
764
  * @param gainMap The new gain map, or `null` to remove it
765
+ * @throws `TypeError` if it isn't a {@link GainMap} or `null`
584
766
  */
585
767
  set gainMap(gainMap: GainMap | null);
586
768
  /**
@@ -631,6 +813,8 @@ export declare class Image {
631
813
  * @param x The x coordinate
632
814
  * @param y The y coordinate
633
815
  * @returns The color value (`0xRRGGBBAA`)
816
+ * @throws `RangeError` if the position isn't inside the image
817
+ * @see {@link Image.pixels} to go over every pixel
634
818
  */
635
819
  getPixelAt(x: number, y: number): Color;
636
820
  /**
@@ -638,6 +822,7 @@ export declare class Image {
638
822
  * @param x The x coordinate
639
823
  * @param y The y coordinate
640
824
  * @param color The new color (`0xRRGGBBAA`)
825
+ * @throws `RangeError` if the position isn't inside the image
641
826
  */
642
827
  setPixelAt(x: number, y: number, color: Color): this;
643
828
  /**
@@ -667,6 +852,11 @@ export declare class Image {
667
852
  resize(width: number, height: number, options?: ResizeOptions): this;
668
853
  /**
669
854
  * Resizes the image: to the given width or height (the other side keeps the aspect ratio), or to both
855
+ * @example
856
+ * ```ts
857
+ * image.resize({ width: 300, height: 200, fit: 'cover' }); // fills 300x200, cropping what doesn't fit
858
+ * image.resize({ width: 150 }); // 150 wide, the height keeps the aspect ratio
859
+ * ```
670
860
  * @param options The size and how to resize, see {@link ResizeToOptions}
671
861
  * @returns The resized image
672
862
  */
@@ -699,6 +889,7 @@ export declare class Image {
699
889
  /**
700
890
  * Crops the image into a circle with an antialiased edge
701
891
  * @param options See {@link CropCircleOptions}
892
+ * @see {@link Image.roundCorners} for rounded corners
702
893
  */
703
894
  cropCircle(options?: CropCircleOptions): this;
704
895
  /**
@@ -746,8 +937,13 @@ export declare class Image {
746
937
  saturation(factor: number): this;
747
938
  /**
748
939
  * Composites (overlays) the source onto this image
940
+ * @example
941
+ * ```ts
942
+ * image.composite(overlay, { x: 10, y: 10, opacity: 0.5, mode: 'multiply' });
943
+ * ```
749
944
  * @param source The image to place
750
945
  * @param options Position, opacity and blend mode, see {@link CompositeOptions}
946
+ * @throws `TypeError` if the source isn't an {@link Image}
751
947
  */
752
948
  composite(source: Image, options?: CompositeOptions): this;
753
949
  /**
@@ -774,33 +970,46 @@ export declare class Image {
774
970
  */
775
971
  blur(radius: number): this;
776
972
  /**
777
- * Reduces the image to a palette of at most 256 colors (or a fixed one), in place, optionally dithered, e.g.
778
- * `image.quantize({ colors: 16, dither: 'floyd-steinberg' })` or `image.quantize({ palette: [0x0f380fff, 0x306230ff,
779
- * 0x8bac0fff, 0x9bbc0fff] })` for a Game Boy look. Transparent pixels (alpha 0) keep their color and don't count
780
- * towards the palette; the other pixels keep their alpha and only their RGB is reduced. The result is deterministic.
781
- * With a gain map (an HDR image), the HDR highlights are dropped, like {@link Image.invert} does: the map is neutral
782
- * afterwards
973
+ * Reduces the image to a palette of at most 256 colors (or a fixed one), in place, optionally dithered
974
+ * @remarks
975
+ * Transparent pixels (alpha 0) keep their color and don't count towards the palette; the other pixels keep their alpha
976
+ * and only their RGB is reduced. The result is deterministic. With a gain map (an HDR image), the HDR highlights are
977
+ * dropped, like {@link Image.invert} does: the map is neutral afterwards
978
+ * @example
979
+ * ```ts
980
+ * image.quantize({ colors: 16, dither: 'floyd-steinberg' });
981
+ * image.quantize({ palette: [0x0f380fff, 0x306230ff, 0x8bac0fff, 0x9bbc0fff] }); // a Game Boy look
982
+ * ```
783
983
  * @param options See {@link QuantizeOptions}
784
984
  */
785
985
  quantize(options?: QuantizeOptions): this;
786
986
  /**
787
987
  * Mixes the colors of every pixel with a color matrix, like SVG's `feColorMatrix`: the new red, green, blue and alpha
788
988
  * are each a sum of the old red, green, blue and alpha times a factor, plus an offset. Grayscale, sepia, tints,
789
- * swapped channels, color blindness simulation or a mix of those in one pass.
790
- *
989
+ * swapped channels, color blindness simulation or a mix of those in one pass
990
+ * @remarks
791
991
  * The values are 20 numbers, four rows of `[red, green, blue, alpha, offset]` for the new red, green, blue and alpha,
792
992
  * with the colors and the offsets as 0 to 1 (like CSS and SVG): `[1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
793
993
  * 0, 0, 0, 1, 0]` changes nothing, `[0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0]` swaps red and
794
994
  * blue. Nine numbers are the first three rows without the alpha and the offsets (the alpha stays as it is). The
795
995
  * colors are the sRGB values, not premultiplied, and the results are clamped. With a gain map (an HDR image), the
796
996
  * HDR highlights follow the change as they do for other color changes
997
+ * @example
998
+ * ```ts
999
+ * image.colorMatrix([0.393, 0.769, 0.189, 0.349, 0.686, 0.168, 0.272, 0.534, 0.131]); // sepia
1000
+ * ```
797
1001
  * @param matrix The 9 or 20 values
798
1002
  */
799
1003
  colorMatrix(matrix: ArrayLike<number>): this;
800
1004
  /**
801
1005
  * Moves every point of the image with an affine transform, in one resampling: rotation, scaling, skew, flips and
802
- * shifts in any mix and around any point. The six numbers are SVG's `matrix(a b c d e f)`: a point (x, y) of the
803
- * image ends up at (a x + c y + e, b x + d y + f), with y pointing down.
1006
+ * shifts in any mix and around any point
1007
+ * @remarks
1008
+ * The six numbers are SVG's `matrix(a b c d e f)`: a point (x, y) of the image ends up at (a x + c y + e,
1009
+ * b x + d y + f), with y pointing down. The image grows to hold the result (`expand: false` keeps its size), so a shift
1010
+ * only shows with `expand: false`. The edges fade, like the pixels outside were transparent. A transform that flattens
1011
+ * the image (a factor of 0) is refused. With a gain map (an HDR image), the map moves with the image
1012
+ * @example
804
1013
  * ```ts
805
1014
  * image.transform([1, 0, Math.tan(-0.3), 1, 0, 0]); // slanted like italics, around the middle
806
1015
  * image.transform([0.5, 0, 0, 0.5, 0, 0], { origin: { x: 0, y: 0 } }); // half the size
@@ -808,11 +1017,9 @@ export declare class Image {
808
1017
  * const a = Math.PI / 6;
809
1018
  * image.transform([Math.cos(a), Math.sin(a), -Math.sin(a), Math.cos(a), 0, 0]); // turned 30° clockwise
810
1019
  * ```
811
- * The image grows to hold the result (`expand: false` keeps its size), so a shift only shows with `expand: false`.
812
- * The edges fade, like the pixels outside were transparent. A transform that flattens the image (a factor of 0) is
813
- * refused. With a gain map (an HDR image), the map moves with the image
814
1020
  * @param matrix The six values [a, b, c, d, e, f]
815
1021
  * @param options See {@link TransformOptions}
1022
+ * @see {@link Image.rotate} for turning by an angle
816
1023
  */
817
1024
  transform(matrix: AffineTransform, options?: TransformOptions): this;
818
1025
  /**
@@ -820,12 +1027,14 @@ export declare class Image {
820
1027
  * (`image.dropShadow({ blur: 8, color: 0xff2fb9ff })`, with `spread` to make it stronger). The image grows to fit
821
1028
  * the shadow, unless `expand` is `false`
822
1029
  * @param options See {@link ShadowOptions}
1030
+ * @throws {@link LimitError} if the size or offset of the shadow would make the image larger than an image can be
823
1031
  */
824
1032
  dropShadow(options?: ShadowOptions): this;
825
1033
  /**
826
1034
  * Draws an outline around the image's shape (its alpha): the sticker effect for cut-out images, or an outline for
827
1035
  * text. The image grows to fit it, unless `expand` is `false`
828
1036
  * @param options See {@link OutlineOptions}
1037
+ * @throws {@link LimitError} if the width would make the image larger than an image can be
829
1038
  */
830
1039
  outline(options?: OutlineOptions): this;
831
1040
  /**
@@ -868,6 +1077,7 @@ export declare class Image {
868
1077
  /**
869
1078
  * Gets the average color of the image, weighting each pixel by its opacity
870
1079
  * @returns The average color (fully opaque), black for fully transparent images
1080
+ * @see {@link Image.dominantColor} for the color that most of the image has
871
1081
  */
872
1082
  averageColor(): Color;
873
1083
  /**
@@ -876,6 +1086,7 @@ export declare class Image {
876
1086
  * @param options Which colors to ignore, see {@link DominantColorOptions}
877
1087
  * @return The image's dominant color (fully opaque); mostly transparent pixels are ignored.
878
1088
  * If every pixel is ignored as black or white, the filter is dropped
1089
+ * @see {@link Image.averageColor} for the mix of all colors
879
1090
  */
880
1091
  dominantColor(options?: DominantColorOptions): Color;
881
1092
  /**
@@ -883,8 +1094,14 @@ export declare class Image {
883
1094
  * counterclockwise). Multiples of 90° move whole pixels; other angles resample the image (see
884
1095
  * {@link RotateOptions.mode}). By default the image grows so the corners fit (a quarter turn swaps width and
885
1096
  * height); with `expand: false` it keeps its size, also for quarter turns, and what doesn't fit is cut off
1097
+ * @example
1098
+ * ```ts
1099
+ * image.rotate(90); // a quarter turn clockwise: width and height swap
1100
+ * image.rotate(-15, { expand: false }); // 15° counterclockwise, the size stays and the corners are cut off
1101
+ * ```
886
1102
  * @param angle The angle in degrees, clockwise
887
1103
  * @param options See {@link RotateOptions}
1104
+ * @see {@link Image.transform} for skews, flips and shifts
888
1105
  */
889
1106
  rotate(angle: number, options?: RotateOptions): this;
890
1107
  /**
@@ -895,11 +1112,13 @@ export declare class Image {
895
1112
  /**
896
1113
  * Rounds the image's corners, with antialiased edges
897
1114
  * @param options See {@link RoundCornersOptions}
1115
+ * @see {@link Image.cropCircle} for a circle
898
1116
  */
899
1117
  roundCorners(options?: RoundCornersOptions): this;
900
1118
  /**
901
1119
  * Applies a fisheye (barrel distortion) effect
902
1120
  * @param options See {@link FisheyeOptions}
1121
+ * @throws `RangeError` if the strength is 0 or less
903
1122
  */
904
1123
  fisheye(options?: FisheyeOptions): this;
905
1124
  /**
@@ -947,13 +1166,14 @@ export declare class Image {
947
1166
  */
948
1167
  encodeAVIF(options?: AVIFEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
949
1168
  /**
950
- * Encodes the image as JPEG XL: losslessly (the default) like libjxl's `cjxl -e 3` (a palette of up to 1024 colors,
951
- * else palettes of channels using few of their values; YCoCg; the weighted predictor in contexts of its error;
952
- * grayscale if the image is), at effort 0 the codestream byte for byte like `cjxl -e 1` on CPUs with AVX2 or NEON
953
- * (its fast lossless mode: the gradient predictor, a palette if the image has at most 511 colors besides black,
954
- * else YCoCg), or lossy with a quality (like `cjxl -q`: XYB, varblocks of libjxl's search, chroma from luma, the
955
- * edge preserving filter). Alpha (if the image has transparency) is lossless either way. The codestream is in the
956
- * container, with the metadata as Exif
1169
+ * Encodes the image as JPEG XL: losslessly (the default), or lossy with a quality. Alpha (if the image has
1170
+ * transparency) is lossless either way. The codestream is in the container, with the metadata as Exif
1171
+ * @remarks
1172
+ * Lossless works like libjxl's `cjxl -e 3` (a palette of up to 1024 colors, else palettes of channels using few of
1173
+ * their values; YCoCg; the weighted predictor in contexts of its error; grayscale if the image is), at effort 0 the
1174
+ * codestream byte for byte like `cjxl -e 1` on CPUs with AVX2 or NEON (its fast lossless mode: the gradient predictor,
1175
+ * a palette if the image has at most 511 colors besides black, else YCoCg). Lossy works like `cjxl -q`: XYB, varblocks
1176
+ * of libjxl's search, chroma from luma, the edge preserving filter
957
1177
  * @param options See {@link JXLEncodeOptions}
958
1178
  */
959
1179
  encodeJXL(options?: JXLEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
@@ -964,23 +1184,36 @@ export declare class Image {
964
1184
  encodePNM(): Promise<Uint8Array<ArrayBuffer>>;
965
1185
  /**
966
1186
  * Decodes an image (PNG, JPEG, TIFF, WebP, BMP, ICO, CUR, QOI, PBM, PGM, PPM, PAM, PFM, Radiance HDR, TGA, AVIF or
967
- * JPEG XL). For animations (GIFs, animated WebPs, AVIF image sequences, JPEG XL animations) this is the first frame,
968
- * composed onto the canvas as {@link Animation.decode} has it, and decoding stops after it: use
969
- * {@link Animation.decode} for all frames. For APNGs this is the default image, which is what viewers without APNG
970
- * support show; for icons and cursors it's their largest image
1187
+ * JPEG XL)
1188
+ * @remarks
1189
+ * For animations (GIFs, animated WebPs, AVIF image sequences, JPEG XL animations) this is the first frame, composed
1190
+ * onto the canvas as {@link Animation.decode} has it, and decoding stops after it: use {@link Animation.decode} for all
1191
+ * frames. For APNGs this is the default image, which is what viewers without APNG support show; for icons and cursors
1192
+ * it's their largest image
1193
+ * @example
1194
+ * ```ts
1195
+ * const image = await Image.decode(bytes); // the file's bytes, e.g. from fs.readFile() or fetch()
1196
+ * const webp = await image.resize({ width: 800 }).encodeWebP({ quality: 80 });
1197
+ * ```
971
1198
  * @param input The binary data to decode
972
- * @param options See {@link DecodeOptions}. JPEGs, TIFFs and PNGs are rotated/mirrored as their orientation tag
1199
+ * @param options See {@link DecodeOptions}. JPEGs, TIFFs, PNGs, WebPs and JPEG XLs are rotated/mirrored as their orientation
973
1200
  * (Exif, for PNGs also XMP) says by default: photos taken with a rotated camera are stored sideways
974
1201
  * @return The decoded image
1202
+ * @throws {@link LimitError} if the image has more than `options.maxPixels` pixels (checked before its pixels are
1203
+ * allocated)
1204
+ * @throws `Error` if the data isn't a supported image, or is damaged or truncated (the underlying error is its `cause`)
975
1205
  */
976
1206
  static decode(input: BinaryData, options?: DecodeOptions): Promise<Image>;
977
1207
  /**
978
- * Creates a new image from the given SVG.
1208
+ * Creates a new image from the given SVG
1209
+ * @remarks
979
1210
  * Supports shapes, paths, transforms, use/symbol, CSS styles, gradients, patterns, strokes, markers, clip paths,
980
1211
  * masks, opacity, blend modes, filters (all primitives and the filter functions) and images embedded as data URIs
981
1212
  * (PNG, JPEG, GIF, WebP, SVG) or given with {@link SVGResourceOptions.images}, and text with the given or embedded fonts
982
1213
  * (see {@link SVGResourceOptions.font}). Hrefs are resolved from the options and the data URIs only, never from files or URLs:
983
- * drawing an image that isn't given, or can't be decoded, throws.
1214
+ * drawing an image that isn't given, or can't be decoded, throws. SVGs from untrusted sources are fine to render: the
1215
+ * size of the output, the layers and the images are limited by the options, and so is the work nested masks, clip
1216
+ * paths, patterns, markers and filter images can multiply
984
1217
  * @example
985
1218
  * ```ts
986
1219
  * const logo = await Image.renderSVG(
@@ -991,14 +1224,27 @@ export declare class Image {
991
1224
  * @param svg The SVG content
992
1225
  * @param options See {@link RenderSVGOptions}
993
1226
  * @return The rendered SVG graphic
1227
+ * @throws {@link LimitError} if the output, the layers or the images exceed the limits of the options
1228
+ * @throws `RangeError` if the requested size is below 1 pixel (or a scale isn't above 0)
1229
+ * @throws `Error` if the SVG can't be parsed (it has no `<svg>` element), an image in it can't be drawn (it isn't given
1230
+ * or can't be decoded), or masks, clip paths, patterns, markers and filter images are nested so deeply that they
1231
+ * would multiply
994
1232
  */
995
1233
  static renderSVG(svg: string | BinaryData, options?: RenderSVGOptions): Promise<Image>;
996
1234
  /**
997
- * Creates a new image containing the rendered text.
1235
+ * Creates a new image containing the rendered text
1236
+ * @example
1237
+ * ```ts
1238
+ * const label = await Image.renderText('Hello, world', { font: fontBytes, size: 48, color: 0xffffffff });
1239
+ * ```
998
1240
  * @param text Text to render
999
1241
  * @param options The font and size, color, layout and style, see {@link RenderTextOptions}. Without a `width` or
1000
1242
  * `height`, the image grows by the outline width on every side; with one, it has exactly that size
1001
1243
  * @return The rendered text
1244
+ * @throws `TypeError` if the text isn't a string, or the options aren't an object with a `font`
1245
+ * @throws `Error` if the font can't be read
1246
+ * @throws {@link LimitError} if the image would have more than `options.maxPixels` pixels (checked before anything is
1247
+ * allocated)
1002
1248
  */
1003
1249
  static renderText(text: string, options: RenderTextOptions): Promise<Image>;
1004
1250
  }