imagescript 4.0.0-rc.2 → 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,22 +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'` */
70
- mode?: ResizeMode;
71
89
  /**
72
- * Whether to use faster, lower-precision arithmetic. It can cause small color differences, especially around
73
- * transparent edges. Only affects `'bilinear'` and `'area'` resizing. Default: `true`
90
+ * The resizing mode
91
+ * @defaultValue `'bilinear'`
74
92
  */
75
- fast?: boolean;
93
+ mode?: ResizeMode;
76
94
  }
77
95
  /** Options of {@link Image.sharpen} */
78
96
  export interface SharpenOptions {
79
- /** How strongly to sharpen (0 does nothing). Default: `1` */
97
+ /**
98
+ * How strongly to sharpen (0 does nothing)
99
+ * @defaultValue `1`
100
+ */
80
101
  amount?: number;
81
- /** 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
+ */
82
106
  radius?: number;
83
107
  }
84
108
  /**
@@ -87,31 +111,44 @@ export interface SharpenOptions {
87
111
  * errors to nearby pixels; `'ordered'` uses a repeating pattern. Atkinson tends to give a higher-contrast result.
88
112
  */
89
113
  export type DitherMethod = 'none' | 'floyd-steinberg' | 'atkinson' | 'ordered';
90
- /** Options of {@link Image.quantize}: either `colors` or `palette`, and the dithering */
91
- export interface QuantizeOptions {
92
- /**
93
- * The maximum number of colors to keep (2-256). Images with fewer distinct colors keep them exactly; otherwise
94
- * ImageScript chooses a smaller set of representative colors. Give `palette` instead to choose exact colors.
95
- * Default: `256`. Give `colors` or `palette`, not both
96
- */
97
- colors?: number;
98
- /**
99
- * A fixed palette (1-256 colors, e.g. a Game Boy's four greens). Every pixel is changed to the nearest palette
100
- * color by its red, green and blue values; transparency in palette colors is ignored. Give `palette` or `colors`,
101
- * not both
102
- */
103
- palette?: Color[];
114
+ /** How colors are dithered when they are reduced to a palette: options of {@link Image.quantize} and the GIF encoders */
115
+ export interface DitherOptions {
104
116
  /**
105
117
  * How to spread small color changes across nearby pixels to make gradients look smoother with few colors, see
106
- * {@link DitherMethod}. Default: `'floyd-steinberg'`, like {@link GIFEncodeOptions.dither}
118
+ * {@link DitherMethod}
119
+ * @defaultValue `'floyd-steinberg'`
107
120
  */
108
121
  dither?: DitherMethod;
109
122
  /**
110
- * How strongly to apply dithering: `0` disables it; `1` applies it fully. Default: `0.85`, like
111
- * {@link GIFEncodeOptions.ditherStrength}
123
+ * How strongly to apply dithering: `0` disables it (like `'none'`); `1` applies it fully
124
+ * @defaultValue `0.85`
112
125
  */
113
126
  ditherStrength?: number;
114
127
  }
128
+ /**
129
+ * Options of {@link Image.quantize}: either `colors` or `palette` (TypeScript reports a call with both), and the
130
+ * dithering
131
+ */
132
+ export type QuantizeOptions = DitherOptions & ({
133
+ /**
134
+ * The maximum number of colors to keep (2-256). Images with fewer distinct colors keep them exactly; otherwise
135
+ * ImageScript chooses a smaller set of representative colors. Give `palette` instead to choose exact colors.
136
+ * @defaultValue `256`
137
+ */
138
+ colors?: number;
139
+ /** Not with `colors`: give one of them */
140
+ palette?: never;
141
+ } | {
142
+ /**
143
+ * A fixed palette (1-256 colors, e.g. a Game Boy's four greens). Every pixel is changed to the nearest palette
144
+ * color by its red, green and blue values; transparency in palette colors is ignored
145
+ */
146
+ palette: Color[];
147
+ /** Not with `palette`: give one of them */
148
+ colors?: never;
149
+ });
150
+ /** The directions of {@link Image.flip} and {@link Animation.flip}: `'horizontal'` mirrors left and right, `'vertical'` top and bottom */
151
+ export type FlipDirection = 'horizontal' | 'vertical';
115
152
  /** How {@link Image.transform} and {@link Image.rotate} sample the pixels between the source's */
116
153
  export type TransformMode = 'nearest-neighbor' | 'bilinear' | 'bicubic';
117
154
  /** The six values `[a, b, c, d, e, f]` of an affine transform */
@@ -120,54 +157,84 @@ export type AffineTransform = readonly [a: number, b: number, c: number, d: numb
120
157
  export interface TransformOptions {
121
158
  /**
122
159
  * The point the transform is applied around, in pixels: a rotation turns around it, a scale grows from it.
123
- * Default: the middle of the image. It only decides where the result lies on a canvas that stays as large as the
124
- * 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
125
162
  */
126
163
  origin?: {
127
- /** 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
+ */
128
168
  x?: number;
129
- /** 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
+ */
130
173
  y?: number;
131
174
  };
132
175
  /**
133
176
  * Whether to make the image as large as the transformed one, which then fills it (a rotated image grows to fit its
134
177
  * corners, a skewed one gets wider). Without it, the image keeps its size and the parts outside are lost.
135
- * Default: `true`
178
+ * @defaultValue `true`
136
179
  */
137
180
  expand?: boolean;
138
181
  /**
139
182
  * How the pixels between the source's are sampled: `'nearest-neighbor'` (hard pixels, no smoothing, for pixel art),
140
- * `'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'`
141
185
  */
142
186
  mode?: TransformMode;
143
187
  }
144
188
  /** Options of {@link Image.dropShadow} */
145
189
  export interface ShadowOptions {
146
- /** 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
+ */
147
194
  x?: number;
148
- /** 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
+ */
149
199
  y?: number;
150
- /** 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
+ */
151
204
  blur?: number;
152
- /** 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
+ */
153
209
  spread?: number;
154
- /** 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
+ */
155
214
  color?: Color;
156
215
  /**
157
216
  * Whether to make the image larger so the shadow isn't cut off. Without it, the image keeps its size and the part
158
- * of the shadow outside is lost. Default: `true`
217
+ * of the shadow outside is lost
218
+ * @defaultValue `true`
159
219
  */
160
220
  expand?: boolean;
161
221
  }
162
222
  /** Options of {@link Image.outline} */
163
223
  export interface OutlineOptions {
164
- /** The outline's width in pixels. Default: `1` */
224
+ /**
225
+ * The outline's width in pixels
226
+ * @defaultValue `1`
227
+ */
165
228
  width?: number;
166
- /** The outline's color. Default: `0x000000ff` */
229
+ /**
230
+ * The outline's color
231
+ * @defaultValue `0x000000ff`
232
+ */
167
233
  color?: Color;
168
234
  /**
169
235
  * Whether to make the image larger so the outline isn't cut off. Without it, the image keeps its size and the
170
- * outline is cut where the image ends. Default: `true`
236
+ * outline is cut where the image ends
237
+ * @defaultValue `true`
171
238
  */
172
239
  expand?: boolean;
173
240
  }
@@ -184,17 +251,27 @@ export interface LinearGradientOptions extends GradientOptions {
184
251
  /**
185
252
  * The direction of the gradient in degrees, like CSS' `linear-gradient()`: `0` goes up, `90` to the right, `180`
186
253
  * down, `270` to the left. The first stop is at the start of the line through the center that touches the
187
- * corners. Default: `180`
254
+ * corners
255
+ * @defaultValue `180`
188
256
  */
189
257
  angle?: number;
190
258
  }
191
259
  /** Options of {@link Image.radialGradient} */
192
260
  export interface RadialGradientOptions extends GradientOptions {
193
- /** 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
+ */
194
265
  x?: number;
195
- /** 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
+ */
196
270
  y?: number;
197
- /** 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
+ */
198
275
  radius?: number;
199
276
  }
200
277
  /** The options every encoder that writes metadata has */
@@ -208,49 +285,58 @@ export interface EncodeOptions {
208
285
  */
209
286
  export interface GainMapEmbedOptions {
210
287
  /**
211
- * 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`
212
290
  */
213
291
  quality?: number;
214
- /** 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
+ */
215
296
  scale?: number;
216
297
  }
217
298
  /** Options of {@link Image.encodePNG} */
218
299
  export interface PNGEncodeOptions extends EncodeOptions {
219
- /** 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
+ */
220
304
  compression?: number;
221
305
  }
222
- /** Options of {@link Image.encodeTGA} */
223
- export type TGAEncodeOptions = EncodeOptions;
306
+ /** Options of {@link Image.encodeTGA}: the metadata, which TGA keeps in its extension area */
307
+ export interface TGAEncodeOptions extends EncodeOptions {
308
+ }
224
309
  /** Options of {@link Image.encodeGIF}, and of {@link Animation.encodeGIF} with {@link GIFAnimationEncodeOptions} */
225
- export interface GIFEncodeOptions extends EncodeOptions {
310
+ export interface GIFEncodeOptions extends EncodeOptions, DitherOptions {
226
311
  /**
227
312
  * The maximum colors in each frame's palette (2-256, including transparency). Frames with fewer colors keep them
228
- * exactly; otherwise ImageScript chooses representative colors. Default: `256`
313
+ * exactly; otherwise ImageScript chooses representative colors
314
+ * @defaultValue `256`
229
315
  */
230
316
  colors?: number;
231
- /** How the rounding error is spread when the colors don't fit the palette, see {@link DitherMethod}. Default: `'floyd-steinberg'` */
232
- dither?: DitherMethod;
233
- /** How strongly to dither, from `0` (like `'none'`) to `1` (the full error). Default: `0.85` */
234
- ditherStrength?: number;
235
317
  }
236
318
  /** Options of {@link Image.encodeJPEG} */
237
319
  export interface JPEGEncodeOptions extends EncodeOptions {
238
- /** The JPEG quality (1-100). Default: `90` */
320
+ /**
321
+ * The JPEG quality (0-100, 0 is the same as 1)
322
+ * @defaultValue `90`
323
+ */
239
324
  quality?: number;
240
325
  /**
241
326
  * How much color detail to keep: `'4:4:4'` keeps it all; `'4:2:0'` stores less color detail to make a smaller
242
- * file (often hard to notice in photos, but more visible around colored edges). Default: `'4:2:0'` up to quality
243
- * 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
244
329
  */
245
330
  subsampling?: '4:4:4' | '4:2:0';
246
331
  /**
247
332
  * The background color to combine with transparent pixels, since JPEG doesn't support transparency. Opaque images
248
- * are encoded as they are. Default: `0x000000ff` (black)
333
+ * are encoded as they are
334
+ * @defaultValue `0x000000ff` (black)
249
335
  */
250
336
  background?: Color;
251
337
  /**
252
338
  * Whether to write the image's {@link Image.gainMap} (an Ultra HDR JPEG, brighter on HDR displays), or how.
253
- * Default: `true` (written if there is one)
339
+ * @defaultValue `true` (written if there is one)
254
340
  */
255
341
  gainMap?: boolean | GainMapEmbedOptions;
256
342
  }
@@ -263,53 +349,57 @@ export interface WebPEncodeOptions extends EncodeOptions {
263
349
  quality?: number;
264
350
  /**
265
351
  * Compression effort (0-6): higher values usually take longer but may make smaller files. For lossless images,
266
- * `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`
267
354
  */
268
355
  effort?: number;
269
356
  /**
270
357
  * For lossy compression: improve color detail around sharp edges (for example, red text on a blue background).
271
- * This can take longer and make graphics larger. Default: `false`
358
+ * This can take longer and make graphics larger
359
+ * @defaultValue `false`
272
360
  */
273
361
  sharpYuv?: boolean;
274
362
  /**
275
363
  * For lossy compression, the transparency (alpha) channel's quality (0-100). Lower values may make the image
276
- * 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)
277
366
  */
278
367
  alphaQuality?: number;
279
368
  /**
280
369
  * For lossless compression, the maximum worker threads to use. Small images or runtimes that cannot share memory
281
- * 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
282
376
  */
283
377
  threads?: number;
284
378
  }
285
379
  /** Options of {@link Image.roundCorners} */
286
380
  export interface RoundCornersOptions {
287
- /** 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
+ */
288
385
  radius?: number;
289
386
  }
290
387
  /** Options of {@link Image.fisheye} */
291
388
  export interface FisheyeOptions {
292
- /** The distortion strength (exponent of the radial mapping), higher values bulge the center more. Default: `2` */
293
- strength?: number;
294
- }
295
- /** Options of {@link Image.renderSVG} */
296
- export interface RenderSVGOptions {
297
- /**
298
- * The width in pixels, the height follows the SVG's aspect ratio. Give one of `width`, `height` and `scale`.
299
- * Default: the SVG's own width
300
- */
301
- width?: number;
302
- /** The height in pixels, the width follows the SVG's aspect ratio. Give one of `width`, `height` and `scale` */
303
- height?: number;
304
389
  /**
305
- * A factor of the SVG's own size (`2` renders it twice as large). Give one of `width`, `height` and `scale`.
306
- * Default: `1`
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`
307
393
  */
308
- scale?: number;
394
+ strength?: number;
395
+ }
396
+ /** The limits, fonts and images of {@link Image.renderSVG}, part of {@link RenderSVGOptions} */
397
+ export interface SVGResourceOptions {
309
398
  /**
310
399
  * Maximum total pixels in the rendered output. Output over the limit throws a RangeError before anything is
311
- * rendered. It's also the default of {@link RenderSVGOptions.maxLayerPixels} and
312
- * {@link RenderSVGOptions.maxImagePixels}. Default: `268402689` (16383²); `Infinity` disables the limit
400
+ * rendered. It's also the default of {@link SVGResourceOptions.maxLayerPixels} and
401
+ * {@link SVGResourceOptions.maxImagePixels}
402
+ * @defaultValue `268402689` (16383²); `Infinity` disables the limit
313
403
  */
314
404
  maxPixels?: number;
315
405
  /**
@@ -318,13 +408,15 @@ export interface RenderSVGOptions {
318
408
  * output's size, 16 bytes per pixel) while their content is drawn, so deeply nested ones multiply the memory a
319
409
  * small SVG takes. Exceeding it throws a RangeError. With the defaults, rendering can take about 90 bytes per pixel
320
410
  * of `maxPixels` (64 for the layers, up to 20 for the images, 4 for the output): lower `maxPixels` to bound it for
321
- * untrusted SVGs. Default: `4 * maxPixels`; `Infinity` disables the limit
411
+ * untrusted SVGs
412
+ * @defaultValue `4 * maxPixels`; `Infinity` disables the limit
322
413
  */
323
414
  maxLayerPixels?: number;
324
415
  /**
325
- * Maximum total pixels of the raster images the SVG references (data URIs and {@link RenderSVGOptions.images}),
416
+ * Maximum total pixels of the raster images the SVG references (data URIs and {@link SVGResourceOptions.images}),
326
417
  * decoded together; already-decoded {@link Image} values are used as supplied and don't count. Drawing an image
327
- * 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
328
420
  */
329
421
  maxImagePixels?: number;
330
422
  /**
@@ -335,19 +427,53 @@ export interface RenderSVGOptions {
335
427
  * other families and text without one get the first font's family; characters a face doesn't have come from the
336
428
  * other fonts (TrueType, OpenType or WOFF). Fonts the SVG embeds with `@font-face` (in data: URIs) are used too,
337
429
  * before these for their family names. Without any fonts text isn't rendered. One font can be given without an
338
- * array. Default: `[]`
430
+ * array
431
+ * @defaultValue `[]`
339
432
  */
340
- fonts?: BinaryData | BinaryData[];
433
+ font?: BinaryData | BinaryData[];
341
434
  /**
342
435
  * Images for the `<image>` elements (and `feImage`) by their `href`, the same string the SVG uses: with
343
436
  * `images: { 'logo.png': bytes }`, `<image href="logo.png" .../>` draws the image. Values are encoded images (PNG,
344
437
  * JPEG, WebP, GIF's first frame, ...) or {@link Image}s, decoded like data URI images are, and only for the hrefs
345
438
  * the SVG references. Nothing else is read: no files and no URLs, so drawing an image whose href isn't given (and
346
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
347
- * data URI for them. Default: `{}`
440
+ * data URI for them
441
+ * @defaultValue `{}`
348
442
  */
349
443
  images?: Record<string, BinaryData | Image>;
350
444
  }
445
+ /**
446
+ * Options of {@link Image.renderSVG}: the size (one of `width`, `height` and `scale`, TypeScript reports a call with
447
+ * more; by default the SVG's own size), and the limits, fonts and images (see {@link SVGResourceOptions})
448
+ */
449
+ export type RenderSVGOptions = SVGResourceOptions & ({
450
+ /**
451
+ * The width in pixels, the height follows the SVG's aspect ratio
452
+ * @defaultValue The SVG's own width
453
+ */
454
+ width?: number;
455
+ /** Not with `width`: give one of `width`, `height` and `scale` */
456
+ height?: never;
457
+ /** Not with `width`: give one of `width`, `height` and `scale` */
458
+ scale?: never;
459
+ } | {
460
+ /** Not with `height`: give one of `width`, `height` and `scale` */
461
+ width?: never;
462
+ /** The height in pixels, the width follows the SVG's aspect ratio */
463
+ height: number;
464
+ /** Not with `height`: give one of `width`, `height` and `scale` */
465
+ scale?: never;
466
+ } | {
467
+ /** Not with `scale`: give one of `width`, `height` and `scale` */
468
+ width?: never;
469
+ /** Not with `scale`: give one of `width`, `height` and `scale` */
470
+ height?: never;
471
+ /**
472
+ * A factor of the SVG's own size (`2` renders it twice as large)
473
+ * @defaultValue `1`
474
+ */
475
+ scale: number;
476
+ });
351
477
  /**
352
478
  * Options of {@link Image.renderText}: the font and size, the text color, the layout (wrapping, cutting off and alignment,
353
479
  * see {@link TextLayoutOptions}) and the style (see {@link TextStyleOptions})
@@ -364,11 +490,15 @@ export interface RenderTextOptions extends TextStyleOptions, TextLayoutOptions {
364
490
  font: BinaryData | BinaryData[];
365
491
  /** Font size in pixels (per em) */
366
492
  size: number;
367
- /** The text color. Default: `0xffffffff` */
493
+ /**
494
+ * The text color
495
+ * @defaultValue `0xffffffff`
496
+ */
368
497
  color?: Color;
369
498
  /**
370
499
  * Maximum total pixels of the rendered image (the outline included): larger text throws a RangeError before its
371
- * pixels are allocated. Default: `268402689` (16383²); `Infinity` disables the limit
500
+ * pixels are allocated
501
+ * @defaultValue `268402689` (16383²); `Infinity` disables the limit
372
502
  */
373
503
  maxPixels?: number;
374
504
  }
@@ -376,7 +506,8 @@ export interface RenderTextOptions extends TextStyleOptions, TextLayoutOptions {
376
506
  export interface DecodeOptions {
377
507
  /**
378
508
  * Whether to rotate or mirror the image according to its saved orientation information, so photos taken with a
379
- * 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`
380
511
  */
381
512
  applyOrientation?: boolean;
382
513
  /**
@@ -384,7 +515,8 @@ export interface DecodeOptions {
384
515
  * colors to sRGB, the standard used by most screens and browsers. Common RGB and gray profiles described by a
385
516
  * color matrix and tone curves are converted, as are AVIFs using other color ranges (such as Display P3 or BT.2020).
386
517
  * Colors outside sRGB are clipped. Profiles that rely on lookup tables, CMYK profiles and profiles already in
387
- * sRGB are left unchanged. Default: `true`
518
+ * sRGB are left unchanged
519
+ * @defaultValue `true`
388
520
  */
389
521
  applyColorProfile?: boolean;
390
522
  /**
@@ -393,25 +525,31 @@ export interface DecodeOptions {
393
525
  * {@link Animation.decode} counts all frames together because each frame uses a full canvas. The decoded image
394
526
  * takes 4 bytes per pixel (about 1 GiB at the default), and decoding needs more while it runs: for 8-bit images,
395
527
  * about 4-7 bytes per pixel for PNG, JPEG, WebP, GIF and the simpler formats, about 14 for AVIF and about 30 for
396
- * JPEG XL (more with high bit depths). Lower it to bound the memory of servers decoding untrusted files. Default:
397
- * `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
398
530
  */
399
531
  maxPixels?: number;
400
532
  /**
401
533
  * How high-dynamic-range images (which can be brighter than a standard screen's white) become 8-bit sRGB.
402
534
  * `'reinhard'` gently compresses bright highlights so the brightest pixel becomes white; images that are not HDR
403
- * stay unchanged. `'clamp'` clips anything brighter than white. Default: `'reinhard'`
535
+ * stay unchanged. `'clamp'` clips anything brighter than white
536
+ * @defaultValue `'reinhard'`
404
537
  */
405
538
  toneMapping?: ToneMapping;
406
539
  /**
407
540
  * Whether to read extra HDR brightness data (a gain map) from supported JPEG, AVIF and JPEG XL images into
408
- * {@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`
409
543
  */
410
544
  gainMap?: boolean;
411
545
  /**
412
546
  * Maximum worker threads for formats and image sizes that can be decoded in parallel. Small images may use one
413
- * thread because starting workers can take longer than decoding them. Default: the available processors, up to 8
414
- * (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)
415
553
  */
416
554
  threads?: number;
417
555
  }
@@ -424,60 +562,91 @@ export interface JXLEncodeOptions extends EncodeOptions {
424
562
  quality?: number;
425
563
  /**
426
564
  * Compression effort (0-2): higher values usually take longer but may make smaller files. `0` prioritizes speed;
427
- * `2` spends the most time compressing. Default: `1`
565
+ * `2` spends the most time compressing
566
+ * @defaultValue `1`
428
567
  */
429
568
  effort?: number;
430
569
  /**
431
570
  * Maximum worker threads for compression. Small images or runtimes that cannot share memory between workers use
432
- * 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
433
577
  */
434
578
  threads?: number;
435
579
  /**
436
580
  * Whether to write the image's {@link Image.gainMap}, the extra data used to show brighter highlights on HDR
437
- * displays. Default: `true` (written if there is one)
581
+ * displays
582
+ * @defaultValue `true` (written if there is one)
438
583
  */
439
584
  gainMap?: boolean | GainMapEmbedOptions;
440
585
  }
441
586
  /** Options of {@link Image.encodeAVIF} */
442
587
  export interface AVIFEncodeOptions extends EncodeOptions {
443
- /** 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
+ */
444
592
  quality?: number;
445
- /** 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
+ */
446
597
  alphaQuality?: number;
447
598
  /**
448
599
  * How much color detail to keep: `'4:4:4'` keeps it all; `'4:2:0'` stores less color detail to make a smaller
449
- * file. Default: `'4:4:4'`
600
+ * file
601
+ * @defaultValue `'4:4:4'`
450
602
  */
451
603
  subsampling?: '4:4:4' | '4:2:0';
452
- /** 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
+ */
453
608
  effort?: number;
454
609
  /**
455
610
  * Maximum worker threads for compression. Small images or runtimes that cannot share memory between workers use
456
- * 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
457
617
  */
458
618
  threads?: number;
459
619
  /**
460
620
  * Whether to write the image's {@link Image.gainMap}, the extra data used to show brighter highlights on HDR
461
- * displays. Default: `true` (written if there is one)
621
+ * displays
622
+ * @defaultValue `true` (written if there is one)
462
623
  */
463
624
  gainMap?: boolean | GainMapEmbedOptions;
464
625
  }
465
626
  /** Text style options of {@link Image.renderText} */
466
627
  export interface TextStyleOptions {
467
- /** 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
+ */
468
632
  strokeWidth?: number;
469
- /** Color of the outline. Default: `0x000000ff` */
633
+ /**
634
+ * Color of the outline
635
+ * @defaultValue `0x000000ff`
636
+ */
470
637
  strokeColor?: Color;
471
638
  /**
472
639
  * Whether to run the hinting instructions of TrueType fonts, which align stems and edges with the pixel grid for
473
640
  * crisper text at small sizes (like Windows renders text); the glyphs of hinted fonts are then placed on whole
474
- * 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`
475
643
  */
476
644
  hinting?: boolean;
477
645
  /**
478
646
  * OpenType features by their tags, for the whole text: `true` turns one on (like `tnum` for tabular numbers,
479
647
  * `smcp` for small caps, `ss01` for a stylistic set), `false` off (also the ones on by default, like `liga` or
480
- * `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 `{}`
481
650
  */
482
651
  features?: Record<string, boolean | number>;
483
652
  /**
@@ -486,41 +655,57 @@ export interface TextStyleOptions {
486
655
  * right), `italic` (`true`/`false`), `opticalSize` (the size the glyphs are designed for, in pixels; default: the
487
656
  * font size, like browsers' `font-optical-sizing: auto`), and other axes by their 4-character tag (like Roboto
488
657
  * Flex's `GRAD: 50`). Values outside an axis's range are clamped, axes a font doesn't have are ignored, fonts
489
- * without axes aren't affected. Default: `{}` (the fonts' default instances)
658
+ * without axes aren't affected
659
+ * @defaultValue `{}` (the fonts' default instances)
490
660
  */
491
661
  variations?: Record<string, number | boolean>;
492
662
  }
493
663
  /** Options of {@link Image.cropCircle} */
494
664
  export interface CropCircleOptions {
495
665
  /**
496
- * 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),
497
667
  * `'cover'` covers the image (the larger dimension is its diameter, the corners of a rectangular image stay
498
- * 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`
499
675
  */
500
- size?: 'contain' | 'cover';
501
- /** Share of the radius (0..1) over which the edge fades out. Default: `0` */
502
676
  feathering?: number;
503
677
  }
504
678
  /** Options of {@link Image.dominantColor} */
505
679
  export interface DominantColorOptions {
506
- /** Whether to ignore dark colors (all channels below the threshold). Default: `true` */
680
+ /**
681
+ * Whether to ignore dark colors (all channels below `threshold`)
682
+ * @defaultValue `true`
683
+ */
507
684
  ignoreBlack?: boolean;
508
- /** Whether to ignore light colors (all channels above 255 minus the threshold). Default: `true` */
685
+ /**
686
+ * Whether to ignore light colors (all channels above 255 minus `threshold`)
687
+ * @defaultValue `true`
688
+ */
509
689
  ignoreWhite?: boolean;
510
- /** The black/white threshold (0-64, in steps of 4 channel values). Default: `15` */
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
+ */
511
694
  threshold?: number;
512
695
  }
513
696
  /** Options of {@link Image.rotate} */
514
697
  export interface RotateOptions {
515
698
  /**
516
699
  * Whether to make the image larger so the rotated corners aren't cut off. Without it, the image keeps its size and
517
- * the parts outside are lost. Default: `true`
700
+ * the parts outside are lost
701
+ * @defaultValue `true`
518
702
  */
519
703
  expand?: boolean;
520
704
  /**
521
705
  * How the pixels between the source's are sampled for angles that aren't multiples of 90° (those move whole
522
706
  * pixels): `'nearest-neighbor'` (hard pixels, for pixel art), `'bilinear'` (smooth) or `'bicubic'` (sharper, can
523
- * 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'`
524
709
  */
525
710
  mode?: TransformMode;
526
711
  }
@@ -533,7 +718,8 @@ export interface TrimOptions {
533
718
  color?: Color;
534
719
  /**
535
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
536
- * antialiasing. Default: `0`
721
+ * antialiasing
722
+ * @defaultValue `0`
537
723
  */
538
724
  tolerance?: number;
539
725
  }
@@ -541,9 +727,15 @@ export interface TrimOptions {
541
727
  export interface ColorToAlphaOptions {
542
728
  /** The color to remove, by default the color of the top left pixel (e.g. a background) */
543
729
  color?: Color;
544
- /** 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
+ */
545
734
  transparencyThreshold?: number;
546
- /** 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
+ */
547
739
  opacityThreshold?: number;
548
740
  }
549
741
  /**
@@ -555,6 +747,7 @@ export declare class Image {
555
747
  * Creates a new image with the given dimensions, all pixels transparent black
556
748
  * @param width The width in pixels
557
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
558
751
  */
559
752
  constructor(width: number, height: number);
560
753
  /**
@@ -565,7 +758,11 @@ export declare class Image {
565
758
  get gainMap(): GainMap | null;
566
759
  /**
567
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
568
764
  * @param gainMap The new gain map, or `null` to remove it
765
+ * @throws `TypeError` if it isn't a {@link GainMap} or `null`
569
766
  */
570
767
  set gainMap(gainMap: GainMap | null);
571
768
  /**
@@ -590,11 +787,6 @@ export declare class Image {
590
787
  * The image's height
591
788
  */
592
789
  get height(): number;
593
- /**
594
- * Yields an [x, y] array for every pixel in the image (0-based), row by row
595
- * @yields The coordinates of the pixel ([x, y])
596
- */
597
- coordinates(): Generator<[x: number, y: number], void, undefined>;
598
790
  /**
599
791
  * Yields an [x, y, color] array for every pixel in the image (0-based), row by row
600
792
  * @yields The coordinates and color of the pixel ([x, y, color])
@@ -621,6 +813,8 @@ export declare class Image {
621
813
  * @param x The x coordinate
622
814
  * @param y The y coordinate
623
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
624
818
  */
625
819
  getPixelAt(x: number, y: number): Color;
626
820
  /**
@@ -628,6 +822,7 @@ export declare class Image {
628
822
  * @param x The x coordinate
629
823
  * @param y The y coordinate
630
824
  * @param color The new color (`0xRRGGBBAA`)
825
+ * @throws `RangeError` if the position isn't inside the image
631
826
  */
632
827
  setPixelAt(x: number, y: number, color: Color): this;
633
828
  /**
@@ -657,6 +852,11 @@ export declare class Image {
657
852
  resize(width: number, height: number, options?: ResizeOptions): this;
658
853
  /**
659
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
+ * ```
660
860
  * @param options The size and how to resize, see {@link ResizeToOptions}
661
861
  * @returns The resized image
662
862
  */
@@ -689,6 +889,7 @@ export declare class Image {
689
889
  /**
690
890
  * Crops the image into a circle with an antialiased edge
691
891
  * @param options See {@link CropCircleOptions}
892
+ * @see {@link Image.roundCorners} for rounded corners
692
893
  */
693
894
  cropCircle(options?: CropCircleOptions): this;
694
895
  /**
@@ -706,9 +907,9 @@ export declare class Image {
706
907
  recolor(colors: Image): this;
707
908
  /**
708
909
  * Scales the opacity of the image
709
- * @param opacity The factor to multiply the opacity with (0..1 lowers it, >1 raises it, results are clamped)
910
+ * @param factor The factor to multiply the opacity with (0..1 lowers it, >1 raises it, results are clamped)
710
911
  */
711
- opacity(opacity: number): this;
912
+ opacity(factor: number): this;
712
913
  /**
713
914
  * Scales the red channel
714
915
  * @param factor The factor to multiply the channel with (>= 0, results are clamped)
@@ -736,8 +937,13 @@ export declare class Image {
736
937
  saturation(factor: number): this;
737
938
  /**
738
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
+ * ```
739
944
  * @param source The image to place
740
945
  * @param options Position, opacity and blend mode, see {@link CompositeOptions}
946
+ * @throws `TypeError` if the source isn't an {@link Image}
741
947
  */
742
948
  composite(source: Image, options?: CompositeOptions): this;
743
949
  /**
@@ -764,33 +970,46 @@ export declare class Image {
764
970
  */
765
971
  blur(radius: number): this;
766
972
  /**
767
- * Reduces the image to a palette of at most 256 colors (or a fixed one), in place, optionally dithered, e.g.
768
- * `image.quantize({ colors: 16, dither: 'floyd-steinberg' })` or `image.quantize({ palette: [0x0f380fff, 0x306230ff,
769
- * 0x8bac0fff, 0x9bbc0fff] })` for a Game Boy look. Transparent pixels (alpha 0) keep their color and don't count
770
- * towards the palette; the other pixels keep their alpha and only their RGB is reduced. The result is deterministic.
771
- * With a gain map (an HDR image), the HDR highlights are dropped, like {@link Image.invert} does: the map is neutral
772
- * 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
+ * ```
773
983
  * @param options See {@link QuantizeOptions}
774
984
  */
775
985
  quantize(options?: QuantizeOptions): this;
776
986
  /**
777
987
  * Mixes the colors of every pixel with a color matrix, like SVG's `feColorMatrix`: the new red, green, blue and alpha
778
988
  * are each a sum of the old red, green, blue and alpha times a factor, plus an offset. Grayscale, sepia, tints,
779
- * swapped channels, color blindness simulation or a mix of those in one pass.
780
- *
989
+ * swapped channels, color blindness simulation or a mix of those in one pass
990
+ * @remarks
781
991
  * The values are 20 numbers, four rows of `[red, green, blue, alpha, offset]` for the new red, green, blue and alpha,
782
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,
783
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
784
994
  * blue. Nine numbers are the first three rows without the alpha and the offsets (the alpha stays as it is). The
785
995
  * colors are the sRGB values, not premultiplied, and the results are clamped. With a gain map (an HDR image), the
786
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
+ * ```
787
1001
  * @param matrix The 9 or 20 values
788
1002
  */
789
1003
  colorMatrix(matrix: ArrayLike<number>): this;
790
1004
  /**
791
1005
  * Moves every point of the image with an affine transform, in one resampling: rotation, scaling, skew, flips and
792
- * 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
793
- * 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
794
1013
  * ```ts
795
1014
  * image.transform([1, 0, Math.tan(-0.3), 1, 0, 0]); // slanted like italics, around the middle
796
1015
  * image.transform([0.5, 0, 0, 0.5, 0, 0], { origin: { x: 0, y: 0 } }); // half the size
@@ -798,11 +1017,9 @@ export declare class Image {
798
1017
  * const a = Math.PI / 6;
799
1018
  * image.transform([Math.cos(a), Math.sin(a), -Math.sin(a), Math.cos(a), 0, 0]); // turned 30° clockwise
800
1019
  * ```
801
- * The image grows to hold the result (`expand: false` keeps its size), so a shift only shows with `expand: false`.
802
- * The edges fade, like the pixels outside were transparent. A transform that flattens the image (a factor of 0) is
803
- * refused. With a gain map (an HDR image), the map moves with the image
804
1020
  * @param matrix The six values [a, b, c, d, e, f]
805
1021
  * @param options See {@link TransformOptions}
1022
+ * @see {@link Image.rotate} for turning by an angle
806
1023
  */
807
1024
  transform(matrix: AffineTransform, options?: TransformOptions): this;
808
1025
  /**
@@ -810,12 +1027,14 @@ export declare class Image {
810
1027
  * (`image.dropShadow({ blur: 8, color: 0xff2fb9ff })`, with `spread` to make it stronger). The image grows to fit
811
1028
  * the shadow, unless `expand` is `false`
812
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
813
1031
  */
814
1032
  dropShadow(options?: ShadowOptions): this;
815
1033
  /**
816
1034
  * Draws an outline around the image's shape (its alpha): the sticker effect for cut-out images, or an outline for
817
1035
  * text. The image grows to fit it, unless `expand` is `false`
818
1036
  * @param options See {@link OutlineOptions}
1037
+ * @throws {@link LimitError} if the width would make the image larger than an image can be
819
1038
  */
820
1039
  outline(options?: OutlineOptions): this;
821
1040
  /**
@@ -858,37 +1077,48 @@ export declare class Image {
858
1077
  /**
859
1078
  * Gets the average color of the image, weighting each pixel by its opacity
860
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
861
1081
  */
862
1082
  averageColor(): Color;
863
1083
  /**
864
- * Gets the image's dominant color: the colors are grouped into a few clusters (median cut and k-means),
865
- * the average color of the largest one is returned
1084
+ * Gets the image's dominant color: the colors are counted in a histogram of 16 levels per channel, and the average
1085
+ * of the pixels in the fullest bin is returned (so it is a color the image has, not a mix of two hues)
866
1086
  * @param options Which colors to ignore, see {@link DominantColorOptions}
867
1087
  * @return The image's dominant color (fully opaque); mostly transparent pixels are ignored.
868
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
869
1090
  */
870
1091
  dominantColor(options?: DominantColorOptions): Color;
871
1092
  /**
872
1093
  * Rotates the image clockwise by the given angle in degrees (like CSS' `rotate()`; negative angles turn it
873
1094
  * counterclockwise). Multiples of 90° move whole pixels; other angles resample the image (see
874
- * {@link RotateOptions.mode}) and, by default, grow it so the corners fit
1095
+ * {@link RotateOptions.mode}). By default the image grows so the corners fit (a quarter turn swaps width and
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
+ * ```
875
1102
  * @param angle The angle in degrees, clockwise
876
1103
  * @param options See {@link RotateOptions}
1104
+ * @see {@link Image.transform} for skews, flips and shifts
877
1105
  */
878
1106
  rotate(angle: number, options?: RotateOptions): this;
879
1107
  /**
880
1108
  * Flips / mirrors the image horizontally or vertically
881
- * @param direction The direction to flip
1109
+ * @param direction The direction to flip, see {@link FlipDirection}
882
1110
  */
883
- flip(direction: 'horizontal' | 'vertical'): this;
1111
+ flip(direction: FlipDirection): this;
884
1112
  /**
885
1113
  * Rounds the image's corners, with antialiased edges
886
1114
  * @param options See {@link RoundCornersOptions}
1115
+ * @see {@link Image.cropCircle} for a circle
887
1116
  */
888
1117
  roundCorners(options?: RoundCornersOptions): this;
889
1118
  /**
890
1119
  * Applies a fisheye (barrel distortion) effect
891
1120
  * @param options See {@link FisheyeOptions}
1121
+ * @throws `RangeError` if the strength is 0 or less
892
1122
  */
893
1123
  fisheye(options?: FisheyeOptions): this;
894
1124
  /**
@@ -936,13 +1166,14 @@ export declare class Image {
936
1166
  */
937
1167
  encodeAVIF(options?: AVIFEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
938
1168
  /**
939
- * Encodes the image as JPEG XL: losslessly (the default) like libjxl's `cjxl -e 3` (a palette of up to 1024 colors,
940
- * else palettes of channels using few of their values; YCoCg; the weighted predictor in contexts of its error;
941
- * grayscale if the image is), at effort 0 the codestream byte for byte like `cjxl -e 1` on CPUs with AVX2 or NEON
942
- * (its fast lossless mode: the gradient predictor, a palette if the image has at most 511 colors besides black,
943
- * else YCoCg), or lossy with a quality (like `cjxl -q`: XYB, varblocks of libjxl's search, chroma from luma, the
944
- * edge preserving filter). Alpha (if the image has transparency) is lossless either way. The codestream is in the
945
- * 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
946
1177
  * @param options See {@link JXLEncodeOptions}
947
1178
  */
948
1179
  encodeJXL(options?: JXLEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
@@ -953,23 +1184,36 @@ export declare class Image {
953
1184
  encodePNM(): Promise<Uint8Array<ArrayBuffer>>;
954
1185
  /**
955
1186
  * Decodes an image (PNG, JPEG, TIFF, WebP, BMP, ICO, CUR, QOI, PBM, PGM, PPM, PAM, PFM, Radiance HDR, TGA, AVIF or
956
- * JPEG XL). For animations (GIFs, animated WebPs, AVIF image sequences, JPEG XL animations) this is the first frame,
957
- * composed onto the canvas as {@link Animation.decode} has it, and decoding stops after it: use
958
- * {@link Animation.decode} for all frames. For APNGs this is the default image, which is what viewers without APNG
959
- * 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
+ * ```
960
1198
  * @param input The binary data to decode
961
- * @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
962
1200
  * (Exif, for PNGs also XMP) says by default: photos taken with a rotated camera are stored sideways
963
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`)
964
1205
  */
965
1206
  static decode(input: BinaryData, options?: DecodeOptions): Promise<Image>;
966
1207
  /**
967
- * Creates a new image from the given SVG.
1208
+ * Creates a new image from the given SVG
1209
+ * @remarks
968
1210
  * Supports shapes, paths, transforms, use/symbol, CSS styles, gradients, patterns, strokes, markers, clip paths,
969
1211
  * masks, opacity, blend modes, filters (all primitives and the filter functions) and images embedded as data URIs
970
- * (PNG, JPEG, GIF, WebP, SVG) or given with {@link RenderSVGOptions.images}, and text with the given or embedded fonts
971
- * (see {@link RenderSVGOptions.fonts}). Hrefs are resolved from the options and the data URIs only, never from files or URLs:
972
- * drawing an image that isn't given, or can't be decoded, throws.
1212
+ * (PNG, JPEG, GIF, WebP, SVG) or given with {@link SVGResourceOptions.images}, and text with the given or embedded fonts
1213
+ * (see {@link SVGResourceOptions.font}). Hrefs are resolved from the options and the data URIs only, never from files or URLs:
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
973
1217
  * @example
974
1218
  * ```ts
975
1219
  * const logo = await Image.renderSVG(
@@ -980,14 +1224,27 @@ export declare class Image {
980
1224
  * @param svg The SVG content
981
1225
  * @param options See {@link RenderSVGOptions}
982
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
983
1232
  */
984
1233
  static renderSVG(svg: string | BinaryData, options?: RenderSVGOptions): Promise<Image>;
985
1234
  /**
986
- * 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
+ * ```
987
1240
  * @param text Text to render
988
- * @param options The font and size, color, layout and style, see {@link RenderTextOptions}; the image grows by the
989
- * outline width on every side
1241
+ * @param options The font and size, color, layout and style, see {@link RenderTextOptions}. Without a `width` or
1242
+ * `height`, the image grows by the outline width on every side; with one, it has exactly that size
990
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)
991
1248
  */
992
1249
  static renderText(text: string, options: RenderTextOptions): Promise<Image>;
993
1250
  }