imagescript 4.0.0-rc.3 → 4.0.0-rc.5
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/README.md +13 -1
- package/dist/animation-encoder.d.ts +13 -6
- package/dist/animation-encoder.js +17 -8
- package/dist/animation.d.ts +55 -9
- package/dist/animation.js +71 -21
- package/dist/codecs/bmp.js +1 -1
- package/dist/codecs/gif.js +16 -5
- package/dist/codecs/jpeg.js +40 -7
- package/dist/codecs/jxl/frame.js +4 -1
- package/dist/codecs/jxl/vardct-enc.js +2 -1
- package/dist/codecs/png.js +52 -22
- package/dist/codecs/quantize.js +3 -5
- package/dist/codecs/tiff.js +8 -1
- package/dist/codecs/vp8.js +1 -1
- package/dist/codecs/webp.js +25 -21
- package/dist/colors.d.ts +3 -0
- package/dist/colors.js +30 -18
- package/dist/frame.d.ts +18 -5
- package/dist/frame.js +2 -0
- package/dist/gainmap.d.ts +41 -15
- package/dist/gainmap.js +19 -10
- package/dist/image.d.ts +379 -123
- package/dist/image.js +100 -58
- package/dist/metadata.d.ts +11 -2
- package/dist/metadata.js +11 -4
- package/dist/package.json +1 -1
- package/dist/render/svg.js +138 -50
- package/dist/render/text.js +12 -7
- package/dist/text-layout.d.ts +12 -5
- package/dist/text-layout.js +6 -5
- package/dist/util/inspect.js +16 -0
- package/dist/util/limits.d.ts +5 -0
- package/dist/util/limits.js +4 -0
- package/dist/util/mem.js +1 -1
- package/dist/util/options.js +71 -9
- package/dist/util/rotate.js +43 -0
- package/package.json +1 -2
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
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* The x position to place the source at
|
|
27
|
+
* @defaultValue `0`
|
|
28
|
+
*/
|
|
26
29
|
x?: number;
|
|
27
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* The y position to place the source at
|
|
32
|
+
* @defaultValue `0`
|
|
33
|
+
*/
|
|
28
34
|
y?: number;
|
|
29
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Opacity of the source (0..1)
|
|
37
|
+
* @defaultValue `1`
|
|
38
|
+
*/
|
|
30
39
|
opacity?: number;
|
|
31
|
-
/**
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* How strongly to sharpen (0 does nothing)
|
|
99
|
+
* @defaultValue `1`
|
|
100
|
+
*/
|
|
75
101
|
amount?: number;
|
|
76
|
-
/**
|
|
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}
|
|
118
|
+
* {@link DitherMethod}
|
|
119
|
+
* @defaultValue `'floyd-steinberg'`
|
|
90
120
|
*/
|
|
91
121
|
dither?: DitherMethod;
|
|
92
|
-
/**
|
|
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
|
-
*
|
|
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
|
-
*
|
|
128
|
-
*
|
|
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
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* The x position of the point in pixels
|
|
166
|
+
* @defaultValue Half the width
|
|
167
|
+
*/
|
|
132
168
|
x?: number;
|
|
133
|
-
/**
|
|
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
|
-
*
|
|
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)
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
195
|
+
/**
|
|
196
|
+
* How far to move the shadow down (negative values: up), in pixels
|
|
197
|
+
* @defaultValue `0`
|
|
198
|
+
*/
|
|
153
199
|
y?: number;
|
|
154
|
-
/**
|
|
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
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* How far to grow the shadow's shape before blurring it, in pixels
|
|
207
|
+
* @defaultValue `0`
|
|
208
|
+
*/
|
|
157
209
|
spread?: number;
|
|
158
|
-
/**
|
|
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
|
|
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
|
-
/**
|
|
224
|
+
/**
|
|
225
|
+
* The outline's width in pixels
|
|
226
|
+
* @defaultValue `1`
|
|
227
|
+
*/
|
|
169
228
|
width?: number;
|
|
170
|
-
/**
|
|
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
|
|
236
|
+
* outline is cut where the image ends
|
|
237
|
+
* @defaultValue `true`
|
|
175
238
|
*/
|
|
176
239
|
expand?: boolean;
|
|
177
240
|
}
|
|
@@ -179,7 +242,8 @@ export interface OutlineOptions {
|
|
|
179
242
|
export interface GradientOptions {
|
|
180
243
|
/**
|
|
181
244
|
* The colors along the gradient: their positions (0..1) and colors (`{ 0: 0xff0000ff, 0.5: 0xffff00ff, 1: 0x00ff00ff }`),
|
|
182
|
-
* or just the colors, evenly spaced (`[0xff0000ff, 0x00ff00ff]`), like {@link Colors.gradient} takes them
|
|
245
|
+
* or just the colors, evenly spaced (`[0xff0000ff, 0x00ff00ff]`), like {@link Colors.gradient} takes them. A
|
|
246
|
+
* position outside 0..1 is allowed, see {@link Colors.gradient}
|
|
183
247
|
*/
|
|
184
248
|
stops: Record<number, Color> | Color[];
|
|
185
249
|
}
|
|
@@ -188,17 +252,27 @@ export interface LinearGradientOptions extends GradientOptions {
|
|
|
188
252
|
/**
|
|
189
253
|
* The direction of the gradient in degrees, like CSS' `linear-gradient()`: `0` goes up, `90` to the right, `180`
|
|
190
254
|
* down, `270` to the left. The first stop is at the start of the line through the center that touches the
|
|
191
|
-
* corners
|
|
255
|
+
* corners
|
|
256
|
+
* @defaultValue `180`
|
|
192
257
|
*/
|
|
193
258
|
angle?: number;
|
|
194
259
|
}
|
|
195
260
|
/** Options of {@link Image.radialGradient} */
|
|
196
261
|
export interface RadialGradientOptions extends GradientOptions {
|
|
197
|
-
/**
|
|
262
|
+
/**
|
|
263
|
+
* The x position of the center in pixels
|
|
264
|
+
* @defaultValue The middle of the image
|
|
265
|
+
*/
|
|
198
266
|
x?: number;
|
|
199
|
-
/**
|
|
267
|
+
/**
|
|
268
|
+
* The y position of the center in pixels
|
|
269
|
+
* @defaultValue The middle of the image
|
|
270
|
+
*/
|
|
200
271
|
y?: number;
|
|
201
|
-
/**
|
|
272
|
+
/**
|
|
273
|
+
* The radius of the last stop in pixels
|
|
274
|
+
* @defaultValue The distance to the farthest corner
|
|
275
|
+
*/
|
|
202
276
|
radius?: number;
|
|
203
277
|
}
|
|
204
278
|
/** The options every encoder that writes metadata has */
|
|
@@ -212,15 +286,22 @@ export interface EncodeOptions {
|
|
|
212
286
|
*/
|
|
213
287
|
export interface GainMapEmbedOptions {
|
|
214
288
|
/**
|
|
215
|
-
* The map's quality (1-100, like the format's `quality`; for JPEG XL 100 is lossless)
|
|
289
|
+
* The map's quality (1-100, like the format's `quality`; for JPEG XL 100 is lossless)
|
|
290
|
+
* @defaultValue `90`
|
|
216
291
|
*/
|
|
217
292
|
quality?: number;
|
|
218
|
-
/**
|
|
293
|
+
/**
|
|
294
|
+
* The map's size as a factor of the image's (0-1)
|
|
295
|
+
* @defaultValue The map's own size
|
|
296
|
+
*/
|
|
219
297
|
scale?: number;
|
|
220
298
|
}
|
|
221
299
|
/** Options of {@link Image.encodePNG} */
|
|
222
300
|
export interface PNGEncodeOptions extends EncodeOptions {
|
|
223
|
-
/**
|
|
301
|
+
/**
|
|
302
|
+
* The compression level (0-9), higher is smaller but slower
|
|
303
|
+
* @defaultValue `4`
|
|
304
|
+
*/
|
|
224
305
|
compression?: number;
|
|
225
306
|
}
|
|
226
307
|
/** Options of {@link Image.encodeTGA}: the metadata, which TGA keeps in its extension area */
|
|
@@ -230,28 +311,33 @@ export interface TGAEncodeOptions extends EncodeOptions {
|
|
|
230
311
|
export interface GIFEncodeOptions extends EncodeOptions, DitherOptions {
|
|
231
312
|
/**
|
|
232
313
|
* 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
|
|
314
|
+
* exactly; otherwise ImageScript chooses representative colors
|
|
315
|
+
* @defaultValue `256`
|
|
234
316
|
*/
|
|
235
317
|
colors?: number;
|
|
236
318
|
}
|
|
237
319
|
/** Options of {@link Image.encodeJPEG} */
|
|
238
320
|
export interface JPEGEncodeOptions extends EncodeOptions {
|
|
239
|
-
/**
|
|
321
|
+
/**
|
|
322
|
+
* The JPEG quality (0-100, 0 is the same as 1)
|
|
323
|
+
* @defaultValue `90`
|
|
324
|
+
*/
|
|
240
325
|
quality?: number;
|
|
241
326
|
/**
|
|
242
327
|
* 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)
|
|
244
|
-
* 90, `'4:4:4'` above
|
|
328
|
+
* file (often hard to notice in photos, but more visible around colored edges)
|
|
329
|
+
* @defaultValue `'4:2:0'` up to quality 90, `'4:4:4'` above
|
|
245
330
|
*/
|
|
246
331
|
subsampling?: '4:4:4' | '4:2:0';
|
|
247
332
|
/**
|
|
248
333
|
* The background color to combine with transparent pixels, since JPEG doesn't support transparency. Opaque images
|
|
249
|
-
* are encoded as they are
|
|
334
|
+
* are encoded as they are
|
|
335
|
+
* @defaultValue `0x000000ff` (black)
|
|
250
336
|
*/
|
|
251
337
|
background?: Color;
|
|
252
338
|
/**
|
|
253
339
|
* Whether to write the image's {@link Image.gainMap} (an Ultra HDR JPEG, brighter on HDR displays), or how.
|
|
254
|
-
*
|
|
340
|
+
* @defaultValue `true` (written if there is one)
|
|
255
341
|
*/
|
|
256
342
|
gainMap?: boolean | GainMapEmbedOptions;
|
|
257
343
|
}
|
|
@@ -264,33 +350,49 @@ export interface WebPEncodeOptions extends EncodeOptions {
|
|
|
264
350
|
quality?: number;
|
|
265
351
|
/**
|
|
266
352
|
* 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
|
|
353
|
+
* `0` prioritizes speed; `2` and above spend more time reducing file size (lossless images are encoded the same at
|
|
354
|
+
* `2` and above)
|
|
355
|
+
* @defaultValue `2`
|
|
268
356
|
*/
|
|
269
357
|
effort?: number;
|
|
270
358
|
/**
|
|
271
359
|
* 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
|
|
360
|
+
* This can take longer and make graphics larger
|
|
361
|
+
* @defaultValue `false`
|
|
273
362
|
*/
|
|
274
363
|
sharpYuv?: boolean;
|
|
275
364
|
/**
|
|
276
365
|
* 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
|
|
366
|
+
* smaller but can make transparency look less smooth
|
|
367
|
+
* @defaultValue `100` (full quality)
|
|
278
368
|
*/
|
|
279
369
|
alphaQuality?: number;
|
|
280
370
|
/**
|
|
281
371
|
* For lossless compression, the maximum worker threads to use. Small images or runtimes that cannot share memory
|
|
282
|
-
* between workers use one thread
|
|
372
|
+
* between workers use one thread
|
|
373
|
+
* @remarks
|
|
374
|
+
* Where workers can't start, the work runs on the calling thread with the same output. That includes browser pages
|
|
375
|
+
* that aren't cross-origin isolated and ones that load the package from another origin (a CDN such as jsDelivr),
|
|
376
|
+
* which browsers don't allow to start workers
|
|
377
|
+
* @defaultValue The available processors, up to 8
|
|
283
378
|
*/
|
|
284
379
|
threads?: number;
|
|
285
380
|
}
|
|
286
381
|
/** Options of {@link Image.roundCorners} */
|
|
287
382
|
export interface RoundCornersOptions {
|
|
288
|
-
/**
|
|
383
|
+
/**
|
|
384
|
+
* The radius of the corners, 0 or more; one above half the smaller side is cut to that
|
|
385
|
+
* @defaultValue A quarter of the smaller side
|
|
386
|
+
*/
|
|
289
387
|
radius?: number;
|
|
290
388
|
}
|
|
291
389
|
/** Options of {@link Image.fisheye} */
|
|
292
390
|
export interface FisheyeOptions {
|
|
293
|
-
/**
|
|
391
|
+
/**
|
|
392
|
+
* The distortion strength (exponent of the radial mapping), above 0: higher values bulge the center more. At 1 and
|
|
393
|
+
* below, the picture shrinks into the middle of the image, and 0 or less would leave nothing of it (it throws)
|
|
394
|
+
* @defaultValue `2`
|
|
395
|
+
*/
|
|
294
396
|
strength?: number;
|
|
295
397
|
}
|
|
296
398
|
/** The limits, fonts and images of {@link Image.renderSVG}, part of {@link RenderSVGOptions} */
|
|
@@ -298,7 +400,8 @@ export interface SVGResourceOptions {
|
|
|
298
400
|
/**
|
|
299
401
|
* Maximum total pixels in the rendered output. Output over the limit throws a RangeError before anything is
|
|
300
402
|
* rendered. It's also the default of {@link SVGResourceOptions.maxLayerPixels} and
|
|
301
|
-
* {@link SVGResourceOptions.maxImagePixels}
|
|
403
|
+
* {@link SVGResourceOptions.maxImagePixels}
|
|
404
|
+
* @defaultValue `268402689` (16383²); `Infinity` disables the limit
|
|
302
405
|
*/
|
|
303
406
|
maxPixels?: number;
|
|
304
407
|
/**
|
|
@@ -307,13 +410,15 @@ export interface SVGResourceOptions {
|
|
|
307
410
|
* output's size, 16 bytes per pixel) while their content is drawn, so deeply nested ones multiply the memory a
|
|
308
411
|
* small SVG takes. Exceeding it throws a RangeError. With the defaults, rendering can take about 90 bytes per pixel
|
|
309
412
|
* 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
|
|
413
|
+
* untrusted SVGs
|
|
414
|
+
* @defaultValue `4 * maxPixels`; `Infinity` disables the limit
|
|
311
415
|
*/
|
|
312
416
|
maxLayerPixels?: number;
|
|
313
417
|
/**
|
|
314
418
|
* Maximum total pixels of the raster images the SVG references (data URIs and {@link SVGResourceOptions.images}),
|
|
315
419
|
* 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
|
|
420
|
+
* beyond the limit throws a RangeError
|
|
421
|
+
* @defaultValue `maxPixels`; `Infinity` disables the limit
|
|
317
422
|
*/
|
|
318
423
|
maxImagePixels?: number;
|
|
319
424
|
/**
|
|
@@ -324,7 +429,8 @@ export interface SVGResourceOptions {
|
|
|
324
429
|
* other families and text without one get the first font's family; characters a face doesn't have come from the
|
|
325
430
|
* other fonts (TrueType, OpenType or WOFF). Fonts the SVG embeds with `@font-face` (in data: URIs) are used too,
|
|
326
431
|
* before these for their family names. Without any fonts text isn't rendered. One font can be given without an
|
|
327
|
-
* array
|
|
432
|
+
* array
|
|
433
|
+
* @defaultValue `[]`
|
|
328
434
|
*/
|
|
329
435
|
font?: BinaryData | BinaryData[];
|
|
330
436
|
/**
|
|
@@ -333,7 +439,8 @@ export interface SVGResourceOptions {
|
|
|
333
439
|
* JPEG, WebP, GIF's first frame, ...) or {@link Image}s, decoded like data URI images are, and only for the hrefs
|
|
334
440
|
* the SVG references. Nothing else is read: no files and no URLs, so drawing an image whose href isn't given (and
|
|
335
441
|
* 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
|
|
442
|
+
* data URI for them
|
|
443
|
+
* @defaultValue `{}`
|
|
337
444
|
*/
|
|
338
445
|
images?: Record<string, BinaryData | Image>;
|
|
339
446
|
}
|
|
@@ -342,7 +449,10 @@ export interface SVGResourceOptions {
|
|
|
342
449
|
* more; by default the SVG's own size), and the limits, fonts and images (see {@link SVGResourceOptions})
|
|
343
450
|
*/
|
|
344
451
|
export type RenderSVGOptions = SVGResourceOptions & ({
|
|
345
|
-
/**
|
|
452
|
+
/**
|
|
453
|
+
* The width in pixels, the height follows the SVG's aspect ratio
|
|
454
|
+
* @defaultValue The SVG's own width
|
|
455
|
+
*/
|
|
346
456
|
width?: number;
|
|
347
457
|
/** Not with `width`: give one of `width`, `height` and `scale` */
|
|
348
458
|
height?: never;
|
|
@@ -360,7 +470,10 @@ export type RenderSVGOptions = SVGResourceOptions & ({
|
|
|
360
470
|
width?: never;
|
|
361
471
|
/** Not with `scale`: give one of `width`, `height` and `scale` */
|
|
362
472
|
height?: never;
|
|
363
|
-
/**
|
|
473
|
+
/**
|
|
474
|
+
* A factor of the SVG's own size (`2` renders it twice as large)
|
|
475
|
+
* @defaultValue `1`
|
|
476
|
+
*/
|
|
364
477
|
scale: number;
|
|
365
478
|
});
|
|
366
479
|
/**
|
|
@@ -379,11 +492,15 @@ export interface RenderTextOptions extends TextStyleOptions, TextLayoutOptions {
|
|
|
379
492
|
font: BinaryData | BinaryData[];
|
|
380
493
|
/** Font size in pixels (per em) */
|
|
381
494
|
size: number;
|
|
382
|
-
/**
|
|
495
|
+
/**
|
|
496
|
+
* The text color
|
|
497
|
+
* @defaultValue `0xffffffff`
|
|
498
|
+
*/
|
|
383
499
|
color?: Color;
|
|
384
500
|
/**
|
|
385
501
|
* Maximum total pixels of the rendered image (the outline included): larger text throws a RangeError before its
|
|
386
|
-
* pixels are allocated
|
|
502
|
+
* pixels are allocated
|
|
503
|
+
* @defaultValue `268402689` (16383²); `Infinity` disables the limit
|
|
387
504
|
*/
|
|
388
505
|
maxPixels?: number;
|
|
389
506
|
}
|
|
@@ -391,7 +508,8 @@ export interface RenderTextOptions extends TextStyleOptions, TextLayoutOptions {
|
|
|
391
508
|
export interface DecodeOptions {
|
|
392
509
|
/**
|
|
393
510
|
* 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
|
|
511
|
+
* rotated camera display upright. This applies to every animation frame too
|
|
512
|
+
* @defaultValue `true`
|
|
395
513
|
*/
|
|
396
514
|
applyOrientation?: boolean;
|
|
397
515
|
/**
|
|
@@ -399,7 +517,8 @@ export interface DecodeOptions {
|
|
|
399
517
|
* colors to sRGB, the standard used by most screens and browsers. Common RGB and gray profiles described by a
|
|
400
518
|
* color matrix and tone curves are converted, as are AVIFs using other color ranges (such as Display P3 or BT.2020).
|
|
401
519
|
* Colors outside sRGB are clipped. Profiles that rely on lookup tables, CMYK profiles and profiles already in
|
|
402
|
-
* sRGB are left unchanged
|
|
520
|
+
* sRGB are left unchanged
|
|
521
|
+
* @defaultValue `true`
|
|
403
522
|
*/
|
|
404
523
|
applyColorProfile?: boolean;
|
|
405
524
|
/**
|
|
@@ -407,26 +526,33 @@ export interface DecodeOptions {
|
|
|
407
526
|
* is allocated, helping prevent a small or untrusted file from requesting an enormous amount of memory.
|
|
408
527
|
* {@link Animation.decode} counts all frames together because each frame uses a full canvas. The decoded image
|
|
409
528
|
* takes 4 bytes per pixel (about 1 GiB at the default), and decoding needs more while it runs: for 8-bit images,
|
|
410
|
-
* about 4-7 bytes per pixel for PNG, JPEG, WebP, GIF and the simpler formats, about 14 for AVIF and about
|
|
411
|
-
* JPEG XL (more with high bit depths). Lower it to bound the
|
|
412
|
-
*
|
|
529
|
+
* about 4-7 bytes per pixel for PNG, JPEG, WebP, GIF and the simpler formats, about 14 for AVIF and about 60 for
|
|
530
|
+
* lossy JPEG XL on one thread, about 110 with worker threads (more with high bit depths). Lower it to bound the
|
|
531
|
+
* memory of servers decoding untrusted files
|
|
532
|
+
* @defaultValue `268402689` (16383²); `Infinity` disables the limit
|
|
413
533
|
*/
|
|
414
534
|
maxPixels?: number;
|
|
415
535
|
/**
|
|
416
536
|
* How high-dynamic-range images (which can be brighter than a standard screen's white) become 8-bit sRGB.
|
|
417
537
|
* `'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
|
|
538
|
+
* stay unchanged. `'clamp'` clips anything brighter than white
|
|
539
|
+
* @defaultValue `'reinhard'`
|
|
419
540
|
*/
|
|
420
541
|
toneMapping?: ToneMapping;
|
|
421
542
|
/**
|
|
422
543
|
* 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
|
|
544
|
+
* {@link Image.gainMap}. For animations, this also reads maps from supported JPEG XL frames
|
|
545
|
+
* @defaultValue `true`
|
|
424
546
|
*/
|
|
425
547
|
gainMap?: boolean;
|
|
426
548
|
/**
|
|
427
549
|
* 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
|
|
429
|
-
*
|
|
550
|
+
* thread because starting workers can take longer than decoding them
|
|
551
|
+
* @remarks
|
|
552
|
+
* Where workers can't start, the work runs on the calling thread with the same output. That includes browser pages
|
|
553
|
+
* that aren't cross-origin isolated and ones that load the package from another origin (a CDN such as jsDelivr),
|
|
554
|
+
* which browsers don't allow to start workers
|
|
555
|
+
* @defaultValue The available processors, up to 8 (one in runtimes that cannot share memory between workers)
|
|
430
556
|
*/
|
|
431
557
|
threads?: number;
|
|
432
558
|
}
|
|
@@ -439,60 +565,91 @@ export interface JXLEncodeOptions extends EncodeOptions {
|
|
|
439
565
|
quality?: number;
|
|
440
566
|
/**
|
|
441
567
|
* Compression effort (0-2): higher values usually take longer but may make smaller files. `0` prioritizes speed;
|
|
442
|
-
* `2` spends the most time compressing
|
|
568
|
+
* `2` spends the most time compressing (lossy images only: lossless images are encoded the same at `1` and `2`)
|
|
569
|
+
* @defaultValue `1`
|
|
443
570
|
*/
|
|
444
571
|
effort?: number;
|
|
445
572
|
/**
|
|
446
573
|
* Maximum worker threads for compression. Small images or runtimes that cannot share memory between workers use
|
|
447
|
-
* one thread
|
|
574
|
+
* one thread
|
|
575
|
+
* @remarks
|
|
576
|
+
* Where workers can't start, the work runs on the calling thread with the same output. That includes browser pages
|
|
577
|
+
* that aren't cross-origin isolated and ones that load the package from another origin (a CDN such as jsDelivr),
|
|
578
|
+
* which browsers don't allow to start workers
|
|
579
|
+
* @defaultValue The available processors, up to 8
|
|
448
580
|
*/
|
|
449
581
|
threads?: number;
|
|
450
582
|
/**
|
|
451
583
|
* Whether to write the image's {@link Image.gainMap}, the extra data used to show brighter highlights on HDR
|
|
452
|
-
* displays
|
|
584
|
+
* displays
|
|
585
|
+
* @defaultValue `true` (written if there is one)
|
|
453
586
|
*/
|
|
454
587
|
gainMap?: boolean | GainMapEmbedOptions;
|
|
455
588
|
}
|
|
456
589
|
/** Options of {@link Image.encodeAVIF} */
|
|
457
590
|
export interface AVIFEncodeOptions extends EncodeOptions {
|
|
458
|
-
/**
|
|
591
|
+
/**
|
|
592
|
+
* 0-100, like avifenc's: higher is better and larger, 100 is lossless
|
|
593
|
+
* @defaultValue `60`
|
|
594
|
+
*/
|
|
459
595
|
quality?: number;
|
|
460
|
-
/**
|
|
596
|
+
/**
|
|
597
|
+
* The quality of the transparency channel, if the image has transparency
|
|
598
|
+
* @defaultValue `100` (lossless)
|
|
599
|
+
*/
|
|
461
600
|
alphaQuality?: number;
|
|
462
601
|
/**
|
|
463
602
|
* 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
|
|
603
|
+
* file
|
|
604
|
+
* @defaultValue `'4:4:4'`
|
|
465
605
|
*/
|
|
466
606
|
subsampling?: '4:4:4' | '4:2:0';
|
|
467
|
-
/**
|
|
607
|
+
/**
|
|
608
|
+
* How hard the encoder searches for the best modes: 0-2, faster to smaller
|
|
609
|
+
* @defaultValue `1`
|
|
610
|
+
*/
|
|
468
611
|
effort?: number;
|
|
469
612
|
/**
|
|
470
613
|
* Maximum worker threads for compression. Small images or runtimes that cannot share memory between workers use
|
|
471
|
-
* one thread
|
|
614
|
+
* one thread
|
|
615
|
+
* @remarks
|
|
616
|
+
* Where workers can't start, the work runs on the calling thread with the same output. That includes browser pages
|
|
617
|
+
* that aren't cross-origin isolated and ones that load the package from another origin (a CDN such as jsDelivr),
|
|
618
|
+
* which browsers don't allow to start workers
|
|
619
|
+
* @defaultValue The available processors, up to 8
|
|
472
620
|
*/
|
|
473
621
|
threads?: number;
|
|
474
622
|
/**
|
|
475
623
|
* Whether to write the image's {@link Image.gainMap}, the extra data used to show brighter highlights on HDR
|
|
476
|
-
* displays
|
|
624
|
+
* displays
|
|
625
|
+
* @defaultValue `true` (written if there is one)
|
|
477
626
|
*/
|
|
478
627
|
gainMap?: boolean | GainMapEmbedOptions;
|
|
479
628
|
}
|
|
480
629
|
/** Text style options of {@link Image.renderText} */
|
|
481
630
|
export interface TextStyleOptions {
|
|
482
|
-
/**
|
|
631
|
+
/**
|
|
632
|
+
* Width of an outline around the glyphs in pixels
|
|
633
|
+
* @defaultValue `0`
|
|
634
|
+
*/
|
|
483
635
|
strokeWidth?: number;
|
|
484
|
-
/**
|
|
636
|
+
/**
|
|
637
|
+
* Color of the outline
|
|
638
|
+
* @defaultValue `0x000000ff`
|
|
639
|
+
*/
|
|
485
640
|
strokeColor?: Color;
|
|
486
641
|
/**
|
|
487
642
|
* Whether to run the hinting instructions of TrueType fonts, which align stems and edges with the pixel grid for
|
|
488
643
|
* 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
|
|
644
|
+
* pixels. Fonts without instructions (and CFF/OpenType outlines) aren't affected
|
|
645
|
+
* @defaultValue `true`
|
|
490
646
|
*/
|
|
491
647
|
hinting?: boolean;
|
|
492
648
|
/**
|
|
493
649
|
* OpenType features by their tags, for the whole text: `true` turns one on (like `tnum` for tabular numbers,
|
|
494
650
|
* `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
|
|
651
|
+
* `kern`), a number picks an alternate (`salt: 2`). Fonts without a feature ignore it
|
|
652
|
+
* @defaultValue `{}`
|
|
496
653
|
*/
|
|
497
654
|
features?: Record<string, boolean | number>;
|
|
498
655
|
/**
|
|
@@ -501,41 +658,57 @@ export interface TextStyleOptions {
|
|
|
501
658
|
* right), `italic` (`true`/`false`), `opticalSize` (the size the glyphs are designed for, in pixels; default: the
|
|
502
659
|
* font size, like browsers' `font-optical-sizing: auto`), and other axes by their 4-character tag (like Roboto
|
|
503
660
|
* 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
|
|
661
|
+
* without axes aren't affected
|
|
662
|
+
* @defaultValue `{}` (the fonts' default instances)
|
|
505
663
|
*/
|
|
506
664
|
variations?: Record<string, number | boolean>;
|
|
507
665
|
}
|
|
508
666
|
/** Options of {@link Image.cropCircle} */
|
|
509
667
|
export interface CropCircleOptions {
|
|
510
668
|
/**
|
|
511
|
-
*
|
|
669
|
+
* How the circle fits the image: `'contain'` fits it inside the image (the smaller dimension is its diameter, no hard edges),
|
|
512
670
|
* `'cover'` covers the image (the larger dimension is its diameter, the corners of a rectangular image stay
|
|
513
|
-
* transparent on the shorter side)
|
|
671
|
+
* transparent on the shorter side)
|
|
672
|
+
* @defaultValue `'contain'`
|
|
673
|
+
*/
|
|
674
|
+
fit?: 'contain' | 'cover';
|
|
675
|
+
/**
|
|
676
|
+
* Share of the radius (0 to 1, a value outside of it throws) over which the edge fades out
|
|
677
|
+
* @defaultValue `0`
|
|
514
678
|
*/
|
|
515
|
-
size?: 'contain' | 'cover';
|
|
516
|
-
/** Share of the radius (0..1) over which the edge fades out. Default: `0` */
|
|
517
679
|
feathering?: number;
|
|
518
680
|
}
|
|
519
681
|
/** Options of {@link Image.dominantColor} */
|
|
520
682
|
export interface DominantColorOptions {
|
|
521
|
-
/**
|
|
683
|
+
/**
|
|
684
|
+
* Whether to ignore dark colors (all channels below `threshold`)
|
|
685
|
+
* @defaultValue `true`
|
|
686
|
+
*/
|
|
522
687
|
ignoreBlack?: boolean;
|
|
523
|
-
/**
|
|
688
|
+
/**
|
|
689
|
+
* Whether to ignore light colors (all channels above 255 minus `threshold`)
|
|
690
|
+
* @defaultValue `true`
|
|
691
|
+
*/
|
|
524
692
|
ignoreWhite?: boolean;
|
|
525
|
-
/**
|
|
693
|
+
/**
|
|
694
|
+
* How close (in channel values, 0-256) to black or white a color has to be to be ignored
|
|
695
|
+
* @defaultValue `60`
|
|
696
|
+
*/
|
|
526
697
|
threshold?: number;
|
|
527
698
|
}
|
|
528
699
|
/** Options of {@link Image.rotate} */
|
|
529
700
|
export interface RotateOptions {
|
|
530
701
|
/**
|
|
531
702
|
* 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
|
|
703
|
+
* the parts outside are lost
|
|
704
|
+
* @defaultValue `true`
|
|
533
705
|
*/
|
|
534
706
|
expand?: boolean;
|
|
535
707
|
/**
|
|
536
708
|
* How the pixels between the source's are sampled for angles that aren't multiples of 90° (those move whole
|
|
537
709
|
* 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}
|
|
710
|
+
* overshoot a little at hard edges), like {@link TransformOptions.mode}
|
|
711
|
+
* @defaultValue `'bilinear'`
|
|
539
712
|
*/
|
|
540
713
|
mode?: TransformMode;
|
|
541
714
|
}
|
|
@@ -548,7 +721,8 @@ export interface TrimOptions {
|
|
|
548
721
|
color?: Color;
|
|
549
722
|
/**
|
|
550
723
|
* 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
|
|
724
|
+
* antialiasing
|
|
725
|
+
* @defaultValue `0`
|
|
552
726
|
*/
|
|
553
727
|
tolerance?: number;
|
|
554
728
|
}
|
|
@@ -556,20 +730,31 @@ export interface TrimOptions {
|
|
|
556
730
|
export interface ColorToAlphaOptions {
|
|
557
731
|
/** The color to remove, by default the color of the top left pixel (e.g. a background) */
|
|
558
732
|
color?: Color;
|
|
559
|
-
/**
|
|
733
|
+
/**
|
|
734
|
+
* Pixels at most this far from the color (0-1) become fully transparent
|
|
735
|
+
* @defaultValue 0
|
|
736
|
+
*/
|
|
560
737
|
transparencyThreshold?: number;
|
|
561
|
-
/**
|
|
738
|
+
/**
|
|
739
|
+
* Pixels at least this far from the color (0-1) stay fully opaque
|
|
740
|
+
* @defaultValue 1
|
|
741
|
+
*/
|
|
562
742
|
opacityThreshold?: number;
|
|
563
743
|
}
|
|
564
744
|
/**
|
|
565
745
|
* An RGBA image; provides the codecs and the manipulation functions. Methods that change the image modify it in place
|
|
566
746
|
* and return it, so calls can be chained
|
|
747
|
+
*
|
|
748
|
+
* @remarks Subclassing is not supported: the methods that make an image ({@link Image.clone}, {@link Image.extract},
|
|
749
|
+
* {@link Image.decode}, ...) return plain `Image`s, without calling a subclass' constructor
|
|
567
750
|
*/
|
|
568
751
|
export declare class Image {
|
|
569
752
|
/**
|
|
570
753
|
* Creates a new image with the given dimensions, all pixels transparent black
|
|
571
754
|
* @param width The width in pixels
|
|
572
755
|
* @param height The height in pixels
|
|
756
|
+
* @throws `TypeError` if the width or height is not a number
|
|
757
|
+
* @throws `RangeError` if the width or height is less than 1, or the image is too large to allocate
|
|
573
758
|
*/
|
|
574
759
|
constructor(width: number, height: number);
|
|
575
760
|
/**
|
|
@@ -580,7 +765,11 @@ export declare class Image {
|
|
|
580
765
|
get gainMap(): GainMap | null;
|
|
581
766
|
/**
|
|
582
767
|
* Replaces the gain map
|
|
768
|
+
* @remarks
|
|
769
|
+
* The image uses a copy of the map: changing the image (resizing it, say) changes its own map only, also when the
|
|
770
|
+
* same map was given to other images, and later changes to the map you gave don't reach the image
|
|
583
771
|
* @param gainMap The new gain map, or `null` to remove it
|
|
772
|
+
* @throws `TypeError` if it isn't a {@link GainMap} or `null`
|
|
584
773
|
*/
|
|
585
774
|
set gainMap(gainMap: GainMap | null);
|
|
586
775
|
/**
|
|
@@ -606,7 +795,9 @@ export declare class Image {
|
|
|
606
795
|
*/
|
|
607
796
|
get height(): number;
|
|
608
797
|
/**
|
|
609
|
-
* Yields an [x, y, color] array for every pixel in the image (0-based), row by row
|
|
798
|
+
* Yields an [x, y, color] array for every pixel in the image (0-based), row by row. Resizing the image meanwhile
|
|
799
|
+
* doesn't affect the iteration (it goes on over the pixels it started with), but other changes to the pixels, like
|
|
800
|
+
* `setPixelAt()`, are seen by the pixels not yet yielded
|
|
610
801
|
* @yields The coordinates and color of the pixel ([x, y, color])
|
|
611
802
|
*/
|
|
612
803
|
pixels(): Generator<[x: number, y: number, color: Color], void, undefined>;
|
|
@@ -631,6 +822,8 @@ export declare class Image {
|
|
|
631
822
|
* @param x The x coordinate
|
|
632
823
|
* @param y The y coordinate
|
|
633
824
|
* @returns The color value (`0xRRGGBBAA`)
|
|
825
|
+
* @throws `RangeError` if the position isn't inside the image
|
|
826
|
+
* @see {@link Image.pixels} to go over every pixel
|
|
634
827
|
*/
|
|
635
828
|
getPixelAt(x: number, y: number): Color;
|
|
636
829
|
/**
|
|
@@ -638,12 +831,13 @@ export declare class Image {
|
|
|
638
831
|
* @param x The x coordinate
|
|
639
832
|
* @param y The y coordinate
|
|
640
833
|
* @param color The new color (`0xRRGGBBAA`)
|
|
834
|
+
* @throws `RangeError` if the position isn't inside the image
|
|
641
835
|
*/
|
|
642
836
|
setPixelAt(x: number, y: number, color: Color): this;
|
|
643
837
|
/**
|
|
644
838
|
* Fills the image data with the supplied color
|
|
645
839
|
* @param color The color, or a function returning the color of each pixel (checked like any color: a result that
|
|
646
|
-
* isn't
|
|
840
|
+
* isn't a number throws a TypeError, a number that isn't a color a RangeError)
|
|
647
841
|
*/
|
|
648
842
|
fill(color: Color | ColorFunction): this;
|
|
649
843
|
/**
|
|
@@ -667,6 +861,11 @@ export declare class Image {
|
|
|
667
861
|
resize(width: number, height: number, options?: ResizeOptions): this;
|
|
668
862
|
/**
|
|
669
863
|
* Resizes the image: to the given width or height (the other side keeps the aspect ratio), or to both
|
|
864
|
+
* @example
|
|
865
|
+
* ```ts
|
|
866
|
+
* image.resize({ width: 300, height: 200, fit: 'cover' }); // fills 300x200, cropping what doesn't fit
|
|
867
|
+
* image.resize({ width: 150 }); // 150 wide, the height keeps the aspect ratio
|
|
868
|
+
* ```
|
|
670
869
|
* @param options The size and how to resize, see {@link ResizeToOptions}
|
|
671
870
|
* @returns The resized image
|
|
672
871
|
*/
|
|
@@ -699,6 +898,7 @@ export declare class Image {
|
|
|
699
898
|
/**
|
|
700
899
|
* Crops the image into a circle with an antialiased edge
|
|
701
900
|
* @param options See {@link CropCircleOptions}
|
|
901
|
+
* @see {@link Image.roundCorners} for rounded corners
|
|
702
902
|
*/
|
|
703
903
|
cropCircle(options?: CropCircleOptions): this;
|
|
704
904
|
/**
|
|
@@ -746,8 +946,13 @@ export declare class Image {
|
|
|
746
946
|
saturation(factor: number): this;
|
|
747
947
|
/**
|
|
748
948
|
* Composites (overlays) the source onto this image
|
|
949
|
+
* @example
|
|
950
|
+
* ```ts
|
|
951
|
+
* image.composite(overlay, { x: 10, y: 10, opacity: 0.5, mode: 'multiply' });
|
|
952
|
+
* ```
|
|
749
953
|
* @param source The image to place
|
|
750
954
|
* @param options Position, opacity and blend mode, see {@link CompositeOptions}
|
|
955
|
+
* @throws `TypeError` if the source isn't an {@link Image}
|
|
751
956
|
*/
|
|
752
957
|
composite(source: Image, options?: CompositeOptions): this;
|
|
753
958
|
/**
|
|
@@ -774,33 +979,46 @@ export declare class Image {
|
|
|
774
979
|
*/
|
|
775
980
|
blur(radius: number): this;
|
|
776
981
|
/**
|
|
777
|
-
* Reduces the image to a palette of at most 256 colors (or a fixed one), in place, optionally dithered
|
|
778
|
-
*
|
|
779
|
-
*
|
|
780
|
-
*
|
|
781
|
-
*
|
|
782
|
-
*
|
|
982
|
+
* Reduces the image to a palette of at most 256 colors (or a fixed one), in place, optionally dithered
|
|
983
|
+
* @remarks
|
|
984
|
+
* Transparent pixels (alpha 0) keep their color and don't count towards the palette; the other pixels keep their alpha
|
|
985
|
+
* and only their RGB is reduced. The result is deterministic. With a gain map (an HDR image), the HDR highlights are
|
|
986
|
+
* dropped, like {@link Image.invert} does: the map is neutral afterwards
|
|
987
|
+
* @example
|
|
988
|
+
* ```ts
|
|
989
|
+
* image.quantize({ colors: 16, dither: 'floyd-steinberg' });
|
|
990
|
+
* image.quantize({ palette: [0x0f380fff, 0x306230ff, 0x8bac0fff, 0x9bbc0fff] }); // a Game Boy look
|
|
991
|
+
* ```
|
|
783
992
|
* @param options See {@link QuantizeOptions}
|
|
784
993
|
*/
|
|
785
994
|
quantize(options?: QuantizeOptions): this;
|
|
786
995
|
/**
|
|
787
996
|
* Mixes the colors of every pixel with a color matrix, like SVG's `feColorMatrix`: the new red, green, blue and alpha
|
|
788
997
|
* 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
|
-
*
|
|
998
|
+
* swapped channels, color blindness simulation or a mix of those in one pass
|
|
999
|
+
* @remarks
|
|
791
1000
|
* The values are 20 numbers, four rows of `[red, green, blue, alpha, offset]` for the new red, green, blue and alpha,
|
|
792
1001
|
* 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
1002
|
* 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
1003
|
* blue. Nine numbers are the first three rows without the alpha and the offsets (the alpha stays as it is). The
|
|
795
1004
|
* colors are the sRGB values, not premultiplied, and the results are clamped. With a gain map (an HDR image), the
|
|
796
1005
|
* HDR highlights follow the change as they do for other color changes
|
|
1006
|
+
* @example
|
|
1007
|
+
* ```ts
|
|
1008
|
+
* image.colorMatrix([0.393, 0.769, 0.189, 0.349, 0.686, 0.168, 0.272, 0.534, 0.131]); // sepia
|
|
1009
|
+
* ```
|
|
797
1010
|
* @param matrix The 9 or 20 values
|
|
798
1011
|
*/
|
|
799
1012
|
colorMatrix(matrix: ArrayLike<number>): this;
|
|
800
1013
|
/**
|
|
801
1014
|
* 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
|
|
803
|
-
*
|
|
1015
|
+
* shifts in any mix and around any point
|
|
1016
|
+
* @remarks
|
|
1017
|
+
* 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,
|
|
1018
|
+
* b x + d y + f), with y pointing down. The image grows to hold the result (`expand: false` keeps its size), so a shift
|
|
1019
|
+
* only shows with `expand: false`. The edges fade, like the pixels outside were transparent. A transform that flattens
|
|
1020
|
+
* the image (a factor of 0) is refused. With a gain map (an HDR image), the map moves with the image
|
|
1021
|
+
* @example
|
|
804
1022
|
* ```ts
|
|
805
1023
|
* image.transform([1, 0, Math.tan(-0.3), 1, 0, 0]); // slanted like italics, around the middle
|
|
806
1024
|
* image.transform([0.5, 0, 0, 0.5, 0, 0], { origin: { x: 0, y: 0 } }); // half the size
|
|
@@ -808,11 +1026,9 @@ export declare class Image {
|
|
|
808
1026
|
* const a = Math.PI / 6;
|
|
809
1027
|
* image.transform([Math.cos(a), Math.sin(a), -Math.sin(a), Math.cos(a), 0, 0]); // turned 30° clockwise
|
|
810
1028
|
* ```
|
|
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
1029
|
* @param matrix The six values [a, b, c, d, e, f]
|
|
815
1030
|
* @param options See {@link TransformOptions}
|
|
1031
|
+
* @see {@link Image.rotate} for turning by an angle
|
|
816
1032
|
*/
|
|
817
1033
|
transform(matrix: AffineTransform, options?: TransformOptions): this;
|
|
818
1034
|
/**
|
|
@@ -820,12 +1036,14 @@ export declare class Image {
|
|
|
820
1036
|
* (`image.dropShadow({ blur: 8, color: 0xff2fb9ff })`, with `spread` to make it stronger). The image grows to fit
|
|
821
1037
|
* the shadow, unless `expand` is `false`
|
|
822
1038
|
* @param options See {@link ShadowOptions}
|
|
1039
|
+
* @throws {@link LimitError} if the size or offset of the shadow would make the image larger than an image can be
|
|
823
1040
|
*/
|
|
824
1041
|
dropShadow(options?: ShadowOptions): this;
|
|
825
1042
|
/**
|
|
826
1043
|
* Draws an outline around the image's shape (its alpha): the sticker effect for cut-out images, or an outline for
|
|
827
1044
|
* text. The image grows to fit it, unless `expand` is `false`
|
|
828
1045
|
* @param options See {@link OutlineOptions}
|
|
1046
|
+
* @throws {@link LimitError} if the width would make the image larger than an image can be
|
|
829
1047
|
*/
|
|
830
1048
|
outline(options?: OutlineOptions): this;
|
|
831
1049
|
/**
|
|
@@ -868,6 +1086,7 @@ export declare class Image {
|
|
|
868
1086
|
/**
|
|
869
1087
|
* Gets the average color of the image, weighting each pixel by its opacity
|
|
870
1088
|
* @returns The average color (fully opaque), black for fully transparent images
|
|
1089
|
+
* @see {@link Image.dominantColor} for the color that most of the image has
|
|
871
1090
|
*/
|
|
872
1091
|
averageColor(): Color;
|
|
873
1092
|
/**
|
|
@@ -876,6 +1095,7 @@ export declare class Image {
|
|
|
876
1095
|
* @param options Which colors to ignore, see {@link DominantColorOptions}
|
|
877
1096
|
* @return The image's dominant color (fully opaque); mostly transparent pixels are ignored.
|
|
878
1097
|
* If every pixel is ignored as black or white, the filter is dropped
|
|
1098
|
+
* @see {@link Image.averageColor} for the mix of all colors
|
|
879
1099
|
*/
|
|
880
1100
|
dominantColor(options?: DominantColorOptions): Color;
|
|
881
1101
|
/**
|
|
@@ -883,8 +1103,14 @@ export declare class Image {
|
|
|
883
1103
|
* counterclockwise). Multiples of 90° move whole pixels; other angles resample the image (see
|
|
884
1104
|
* {@link RotateOptions.mode}). By default the image grows so the corners fit (a quarter turn swaps width and
|
|
885
1105
|
* height); with `expand: false` it keeps its size, also for quarter turns, and what doesn't fit is cut off
|
|
1106
|
+
* @example
|
|
1107
|
+
* ```ts
|
|
1108
|
+
* image.rotate(90); // a quarter turn clockwise: width and height swap
|
|
1109
|
+
* image.rotate(-15, { expand: false }); // 15° counterclockwise, the size stays and the corners are cut off
|
|
1110
|
+
* ```
|
|
886
1111
|
* @param angle The angle in degrees, clockwise
|
|
887
1112
|
* @param options See {@link RotateOptions}
|
|
1113
|
+
* @see {@link Image.transform} for skews, flips and shifts
|
|
888
1114
|
*/
|
|
889
1115
|
rotate(angle: number, options?: RotateOptions): this;
|
|
890
1116
|
/**
|
|
@@ -895,23 +1121,26 @@ export declare class Image {
|
|
|
895
1121
|
/**
|
|
896
1122
|
* Rounds the image's corners, with antialiased edges
|
|
897
1123
|
* @param options See {@link RoundCornersOptions}
|
|
1124
|
+
* @see {@link Image.cropCircle} for a circle
|
|
898
1125
|
*/
|
|
899
1126
|
roundCorners(options?: RoundCornersOptions): this;
|
|
900
1127
|
/**
|
|
901
1128
|
* Applies a fisheye (barrel distortion) effect
|
|
902
1129
|
* @param options See {@link FisheyeOptions}
|
|
1130
|
+
* @throws `RangeError` if the strength is 0 or less
|
|
903
1131
|
*/
|
|
904
1132
|
fisheye(options?: FisheyeOptions): this;
|
|
905
1133
|
/**
|
|
906
1134
|
* Encodes the image into a PNG, with the smallest lossless color type (a palette for up to 256 colors,
|
|
907
|
-
* grayscale or RGB, alpha only if needed). Uses the runtime's native zlib when available
|
|
1135
|
+
* grayscale or RGB, alpha only if needed). Uses the runtime's native zlib when available (the files differ between runtimes, whose zlibs compress differently: about a quarter larger on Deno than on Node and Bun)
|
|
908
1136
|
* @param options See {@link PNGEncodeOptions}
|
|
909
1137
|
* @return The encoded data
|
|
910
1138
|
*/
|
|
911
1139
|
encodePNG(options?: PNGEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
912
1140
|
/**
|
|
913
1141
|
* Encodes the image into a JPEG. JPEG has no transparency: an image with transparent or translucent pixels is
|
|
914
|
-
* composited onto the `background` color (black by default) first, the image itself stays unchanged
|
|
1142
|
+
* composited onto the `background` color (black by default) first, the image itself stays unchanged. An image whose
|
|
1143
|
+
* pixels are all gray is written as a grayscale JPEG (one component)
|
|
915
1144
|
* @param options See {@link JPEGEncodeOptions}
|
|
916
1145
|
*/
|
|
917
1146
|
encodeJPEG(options?: JPEGEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
@@ -947,13 +1176,14 @@ export declare class Image {
|
|
|
947
1176
|
*/
|
|
948
1177
|
encodeAVIF(options?: AVIFEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
949
1178
|
/**
|
|
950
|
-
* Encodes the image as JPEG XL: losslessly (the default)
|
|
951
|
-
*
|
|
952
|
-
*
|
|
953
|
-
*
|
|
954
|
-
*
|
|
955
|
-
*
|
|
956
|
-
*
|
|
1179
|
+
* Encodes the image as JPEG XL: losslessly (the default), or lossy with a quality. Alpha (if the image has
|
|
1180
|
+
* transparency) is lossless either way. The codestream is in the container, with the metadata as Exif
|
|
1181
|
+
* @remarks
|
|
1182
|
+
* Lossless works like libjxl's `cjxl -e 3` (a palette of up to 1024 colors, else palettes of channels using few of
|
|
1183
|
+
* their values; YCoCg; the weighted predictor in contexts of its error; grayscale if the image is), at effort 0 the
|
|
1184
|
+
* codestream byte for byte like `cjxl -e 1` on CPUs with AVX2 or NEON (its fast lossless mode: the gradient predictor,
|
|
1185
|
+
* a palette if the image has at most 511 colors besides black, else YCoCg). Lossy works like `cjxl -q`: XYB, varblocks
|
|
1186
|
+
* of libjxl's search, chroma from luma, the edge preserving filter
|
|
957
1187
|
* @param options See {@link JXLEncodeOptions}
|
|
958
1188
|
*/
|
|
959
1189
|
encodeJXL(options?: JXLEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
@@ -964,23 +1194,36 @@ export declare class Image {
|
|
|
964
1194
|
encodePNM(): Promise<Uint8Array<ArrayBuffer>>;
|
|
965
1195
|
/**
|
|
966
1196
|
* Decodes an image (PNG, JPEG, TIFF, WebP, BMP, ICO, CUR, QOI, PBM, PGM, PPM, PAM, PFM, Radiance HDR, TGA, AVIF or
|
|
967
|
-
* JPEG XL)
|
|
968
|
-
*
|
|
969
|
-
*
|
|
970
|
-
*
|
|
1197
|
+
* JPEG XL)
|
|
1198
|
+
* @remarks
|
|
1199
|
+
* For animations (GIFs, animated WebPs, AVIF image sequences, JPEG XL animations) this is the first frame, composed
|
|
1200
|
+
* onto the canvas as {@link Animation.decode} has it, and decoding stops after it: use {@link Animation.decode} for all
|
|
1201
|
+
* frames. For APNGs this is the default image, which is what viewers without APNG support show; for icons and cursors
|
|
1202
|
+
* it's their largest image
|
|
1203
|
+
* @example
|
|
1204
|
+
* ```ts
|
|
1205
|
+
* const image = await Image.decode(bytes); // the file's bytes, e.g. from fs.readFile() or fetch()
|
|
1206
|
+
* const webp = await image.resize({ width: 800 }).encodeWebP({ quality: 80 });
|
|
1207
|
+
* ```
|
|
971
1208
|
* @param input The binary data to decode
|
|
972
|
-
* @param options See {@link DecodeOptions}. JPEGs, TIFFs and
|
|
1209
|
+
* @param options See {@link DecodeOptions}. JPEGs, TIFFs, PNGs, WebPs and JPEG XLs are rotated/mirrored as their orientation
|
|
973
1210
|
* (Exif, for PNGs also XMP) says by default: photos taken with a rotated camera are stored sideways
|
|
974
1211
|
* @return The decoded image
|
|
1212
|
+
* @throws {@link LimitError} if the image has more than `options.maxPixels` pixels (checked before its pixels are
|
|
1213
|
+
* allocated)
|
|
1214
|
+
* @throws `Error` if the data isn't a supported image, or is damaged or truncated (the underlying error is its `cause`)
|
|
975
1215
|
*/
|
|
976
1216
|
static decode(input: BinaryData, options?: DecodeOptions): Promise<Image>;
|
|
977
1217
|
/**
|
|
978
|
-
* Creates a new image from the given SVG
|
|
1218
|
+
* Creates a new image from the given SVG
|
|
1219
|
+
* @remarks
|
|
979
1220
|
* Supports shapes, paths, transforms, use/symbol, CSS styles, gradients, patterns, strokes, markers, clip paths,
|
|
980
1221
|
* masks, opacity, blend modes, filters (all primitives and the filter functions) and images embedded as data URIs
|
|
981
1222
|
* (PNG, JPEG, GIF, WebP, SVG) or given with {@link SVGResourceOptions.images}, and text with the given or embedded fonts
|
|
982
1223
|
* (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.
|
|
1224
|
+
* drawing an image that isn't given, or can't be decoded, throws. SVGs from untrusted sources are fine to render: the
|
|
1225
|
+
* size of the output, the layers and the images are limited by the options, and so is the work nested masks, clip
|
|
1226
|
+
* paths, patterns, markers and filter images can multiply
|
|
984
1227
|
* @example
|
|
985
1228
|
* ```ts
|
|
986
1229
|
* const logo = await Image.renderSVG(
|
|
@@ -991,14 +1234,27 @@ export declare class Image {
|
|
|
991
1234
|
* @param svg The SVG content
|
|
992
1235
|
* @param options See {@link RenderSVGOptions}
|
|
993
1236
|
* @return The rendered SVG graphic
|
|
1237
|
+
* @throws {@link LimitError} if the output, the layers or the images exceed the limits of the options
|
|
1238
|
+
* @throws `RangeError` if the requested size is below 1 pixel (or a scale isn't above 0)
|
|
1239
|
+
* @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
|
|
1240
|
+
* or can't be decoded), or masks, clip paths, patterns, markers and filter images are nested so deeply that they
|
|
1241
|
+
* would multiply
|
|
994
1242
|
*/
|
|
995
1243
|
static renderSVG(svg: string | BinaryData, options?: RenderSVGOptions): Promise<Image>;
|
|
996
1244
|
/**
|
|
997
|
-
* Creates a new image containing the rendered text
|
|
1245
|
+
* Creates a new image containing the rendered text
|
|
1246
|
+
* @example
|
|
1247
|
+
* ```ts
|
|
1248
|
+
* const label = await Image.renderText('Hello, world', { font: fontBytes, size: 48, color: 0xffffffff });
|
|
1249
|
+
* ```
|
|
998
1250
|
* @param text Text to render
|
|
999
1251
|
* @param options The font and size, color, layout and style, see {@link RenderTextOptions}. Without a `width` or
|
|
1000
1252
|
* `height`, the image grows by the outline width on every side; with one, it has exactly that size
|
|
1001
1253
|
* @return The rendered text
|
|
1254
|
+
* @throws `TypeError` if the text isn't a string, or the options aren't an object with a `font`
|
|
1255
|
+
* @throws `Error` if the font can't be read
|
|
1256
|
+
* @throws {@link LimitError} if the image would have more than `options.maxPixels` pixels (checked before anything is
|
|
1257
|
+
* allocated)
|
|
1002
1258
|
*/
|
|
1003
1259
|
static renderText(text: string, options: RenderTextOptions): Promise<Image>;
|
|
1004
1260
|
}
|