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