@napi-rs/image 1.7.0 → 1.9.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/browser.js +1 -0
- package/index.d.ts +224 -202
- package/index.js +123 -31
- package/package.json +33 -30
package/browser.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@napi-rs/image-wasm32-wasi'
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,118 @@
|
|
|
1
|
-
/*
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export class Transformer {
|
|
5
|
+
constructor(input: Buffer)
|
|
6
|
+
/** Support CSS3 color, e.g. rgba(255, 255, 255, .8) */
|
|
7
|
+
static fromSvg(input: string | Buffer, background?: string | undefined | null): Transformer
|
|
8
|
+
static fromRgbaPixels(input: Uint8Array | Uint8ClampedArray, width: number, height: number): Transformer
|
|
9
|
+
metadata(withExif?: boolean | undefined | null, signal?: AbortSignal | undefined | null): Promise<Metadata>
|
|
10
|
+
/**
|
|
11
|
+
* Rotate with exif orientation
|
|
12
|
+
* If the orientation param is not null,
|
|
13
|
+
* the new orientation value will override the exif orientation value
|
|
14
|
+
*/
|
|
15
|
+
rotate(orientation?: Orientation | undefined | null): this
|
|
16
|
+
/**
|
|
17
|
+
* Return a grayscale version of this image.
|
|
18
|
+
* Returns `Luma` images in most cases. However, for `f32` images,
|
|
19
|
+
* this will return a greyscale `Rgb/Rgba` image instead.
|
|
20
|
+
*/
|
|
21
|
+
grayscale(): this
|
|
22
|
+
/** Invert the colors of this image. */
|
|
23
|
+
invert(): this
|
|
24
|
+
/**
|
|
25
|
+
* Resize this image using the specified filter algorithm.
|
|
26
|
+
* The image is scaled to the maximum possible size that fits
|
|
27
|
+
* within the bounds specified by `width` and `height`.
|
|
28
|
+
*/
|
|
29
|
+
resize(widthOrOptions: number | ResizeOptions, height?: number | undefined | null, filter?: ResizeFilterType | undefined | null, fit?: ResizeFit | undefined | null): this
|
|
30
|
+
/**
|
|
31
|
+
* Resize this image using the specified filter algorithm.
|
|
32
|
+
* The image is scaled to the maximum possible size that fits
|
|
33
|
+
* within the bounds specified by `width` and `height`.
|
|
34
|
+
*
|
|
35
|
+
* This is using faster SIMD based resize implementation
|
|
36
|
+
* the resize filter is different from `resize` method
|
|
37
|
+
*/
|
|
38
|
+
fastResize(options: FastResizeOptions): this
|
|
39
|
+
/**
|
|
40
|
+
* Performs a Gaussian blur on this image.
|
|
41
|
+
* `sigma` is a measure of how much to blur by.
|
|
42
|
+
*/
|
|
43
|
+
blur(sigma: number): this
|
|
44
|
+
/**
|
|
45
|
+
* Performs an unsharpen mask on this image.
|
|
46
|
+
* `sigma` is the amount to blur the image by.
|
|
47
|
+
* `threshold` is a control of how much to sharpen.
|
|
48
|
+
*
|
|
49
|
+
* See <https://en.wikipedia.org/wiki/Unsharp_masking#Digital_unsharp_masking>
|
|
50
|
+
*/
|
|
51
|
+
unsharpen(sigma: number, threshold: number): this
|
|
52
|
+
/** Filters this image with the specified 3x3 kernel. */
|
|
53
|
+
filter3x3(kernel: Array<number>): this
|
|
54
|
+
/**
|
|
55
|
+
* Adjust the contrast of this image.
|
|
56
|
+
* `contrast` is the amount to adjust the contrast by.
|
|
57
|
+
* Negative values decrease the contrast and positive values increase the contrast.
|
|
58
|
+
*/
|
|
59
|
+
adjustContrast(contrast: number): this
|
|
60
|
+
/**
|
|
61
|
+
* Brighten the pixels of this image.
|
|
62
|
+
* `value` is the amount to brighten each pixel by.
|
|
63
|
+
* Negative values decrease the brightness and positive values increase it.
|
|
64
|
+
*/
|
|
65
|
+
brighten(brightness: number): this
|
|
66
|
+
/**
|
|
67
|
+
* Hue rotate the supplied image.
|
|
68
|
+
* `value` is the degrees to rotate each pixel by.
|
|
69
|
+
* 0 and 360 do nothing, the rest rotates by the given degree value.
|
|
70
|
+
* just like the css webkit filter hue-rotate(180)
|
|
71
|
+
*/
|
|
72
|
+
huerotate(hue: number): this
|
|
73
|
+
/** Crop a cut-out of this image delimited by the bounding rectangle. */
|
|
74
|
+
crop(x: number, y: number, width: number, height: number): this
|
|
75
|
+
/** Overlay an image at a given coordinate (x, y) */
|
|
76
|
+
overlay(onTop: Buffer, x: number, y: number): this
|
|
77
|
+
/** Return this image's pixels as a native endian byte slice. */
|
|
78
|
+
rawPixels(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
79
|
+
/** Return this image's pixels as a native endian byte slice. */
|
|
80
|
+
rawPixelsSync(): Buffer
|
|
81
|
+
/**
|
|
82
|
+
* The quality factor `quality_factor` ranges from 0 to 100 and controls the loss and quality during compression.
|
|
83
|
+
* The value 0 corresponds to low quality and small output sizes, whereas 100 is the highest quality and largest output size.
|
|
84
|
+
* https://developers.google.com/speed/webp/docs/api#simple_encoding_api
|
|
85
|
+
*/
|
|
86
|
+
webp(qualityFactor?: number | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
87
|
+
/**
|
|
88
|
+
* The quality factor `quality_factor` ranges from 0 to 100 and controls the loss and quality during compression.
|
|
89
|
+
* The value 0 corresponds to low quality and small output sizes, whereas 100 is the highest quality and largest output size.
|
|
90
|
+
* https://developers.google.com/speed/webp/docs/api#simple_encoding_api
|
|
91
|
+
*/
|
|
92
|
+
webpSync(qualityFactor?: number | undefined | null): Buffer
|
|
93
|
+
webpLossless(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
94
|
+
webpLosslessSync(): Buffer
|
|
95
|
+
avif(options?: AvifConfig | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
96
|
+
avifSync(options?: AvifConfig | undefined | null): Buffer
|
|
97
|
+
png(options?: PngEncodeOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
98
|
+
pngSync(options?: PngEncodeOptions | undefined | null): Buffer
|
|
99
|
+
/** default `quality` is 90 */
|
|
100
|
+
jpeg(quality?: number | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
101
|
+
/** default `quality` is 90 */
|
|
102
|
+
jpegSync(quality?: number | undefined | null): Buffer
|
|
103
|
+
bmp(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
104
|
+
bmpSync(): Buffer
|
|
105
|
+
ico(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
106
|
+
icoSync(): Buffer
|
|
107
|
+
tiff(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
108
|
+
tiffSync(): Buffer
|
|
109
|
+
pnm(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
110
|
+
pnmSync(): Buffer
|
|
111
|
+
tga(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
112
|
+
tgaSync(): Buffer
|
|
113
|
+
farbfeld(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
114
|
+
farbfeldSync(): Buffer
|
|
115
|
+
}
|
|
5
116
|
|
|
6
117
|
export interface AvifConfig {
|
|
7
118
|
/** 0-100 scale, 100 is lossless */
|
|
@@ -15,6 +126,7 @@ export interface AvifConfig {
|
|
|
15
126
|
/** set to '4:2:0' to use chroma subsampling, default '4:4:4' */
|
|
16
127
|
chromaSubsampling?: ChromaSubsampling
|
|
17
128
|
}
|
|
129
|
+
|
|
18
130
|
/**
|
|
19
131
|
* https://en.wikipedia.org/wiki/Chroma_subsampling#Types_of_sampling_and_subsampling
|
|
20
132
|
* https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Video_concepts
|
|
@@ -57,6 +169,20 @@ export const enum ChromaSubsampling {
|
|
|
57
169
|
*/
|
|
58
170
|
Yuv400 = 3
|
|
59
171
|
}
|
|
172
|
+
|
|
173
|
+
export const enum CompressionType {
|
|
174
|
+
/** Default compression level */
|
|
175
|
+
Default = 0,
|
|
176
|
+
/** Fast, minimal compression */
|
|
177
|
+
Fast = 1,
|
|
178
|
+
/** High compression level */
|
|
179
|
+
Best = 2
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function compressJpeg(input: Buffer, options?: JpegCompressOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
183
|
+
|
|
184
|
+
export function compressJpegSync(input: Buffer, options?: JpegCompressOptions | undefined | null): Buffer
|
|
185
|
+
|
|
60
186
|
export const enum FastResizeFilter {
|
|
61
187
|
/**
|
|
62
188
|
* Each pixel of source image contributes to one pixel of the
|
|
@@ -96,45 +222,14 @@ export const enum FastResizeFilter {
|
|
|
96
222
|
*/
|
|
97
223
|
Lanczos3 = 5
|
|
98
224
|
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* (default) Preserving aspect ratio
|
|
102
|
-
* ensure the image covers both provided dimensions by cropping/clipping to fit.
|
|
103
|
-
*/
|
|
104
|
-
Cover = 0,
|
|
105
|
-
/** Ignore the aspect ratio of the input and stretch to both provided dimensions. */
|
|
106
|
-
Fill = 1,
|
|
107
|
-
/**
|
|
108
|
-
* Preserving aspect ratio
|
|
109
|
-
* resize the image to be as large as possible while ensuring its dimensions are less than or equal to both those specified.
|
|
110
|
-
*/
|
|
111
|
-
Inside = 2
|
|
112
|
-
}
|
|
225
|
+
|
|
113
226
|
export interface FastResizeOptions {
|
|
114
227
|
width: number
|
|
115
228
|
height?: number
|
|
116
229
|
filter?: FastResizeFilter
|
|
117
230
|
fit?: ResizeFit
|
|
118
231
|
}
|
|
119
|
-
|
|
120
|
-
/** Output quality, default is 100 (lossless) */
|
|
121
|
-
quality?: number
|
|
122
|
-
/**
|
|
123
|
-
* If true, it will use MozJPEG’s scan optimization. Makes progressive image files smaller.
|
|
124
|
-
* Default is `true`
|
|
125
|
-
*/
|
|
126
|
-
optimizeScans?: boolean
|
|
127
|
-
}
|
|
128
|
-
export function compressJpegSync(input: Buffer, options?: JpegCompressOptions | undefined | null): Buffer
|
|
129
|
-
export function compressJpeg(input: Buffer, options?: JpegCompressOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
130
|
-
export const enum CompressionType {
|
|
131
|
-
/** Default compression level */
|
|
132
|
-
Default = 0,
|
|
133
|
-
/** Fast, minimal compression */
|
|
134
|
-
Fast = 1,
|
|
135
|
-
/** High compression level */
|
|
136
|
-
Best = 2
|
|
137
|
-
}
|
|
232
|
+
|
|
138
233
|
export const enum FilterType {
|
|
139
234
|
/**
|
|
140
235
|
* No processing done, best used for low bit depth greyscale or data with a
|
|
@@ -155,24 +250,72 @@ export const enum FilterType {
|
|
|
155
250
|
*/
|
|
156
251
|
Adaptive = 5
|
|
157
252
|
}
|
|
253
|
+
|
|
254
|
+
export interface JpegCompressOptions {
|
|
255
|
+
/** Output quality, default is 100 (lossless) */
|
|
256
|
+
quality?: number
|
|
257
|
+
/**
|
|
258
|
+
* If true, it will use MozJPEG’s scan optimization. Makes progressive image files smaller.
|
|
259
|
+
* Default is `true`
|
|
260
|
+
*/
|
|
261
|
+
optimizeScans?: boolean
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export const enum JsColorType {
|
|
265
|
+
/** Pixel is 8-bit luminance */
|
|
266
|
+
L8 = 0,
|
|
267
|
+
/** Pixel is 8-bit luminance with an alpha channel */
|
|
268
|
+
La8 = 1,
|
|
269
|
+
/** Pixel contains 8-bit R, G and B channels */
|
|
270
|
+
Rgb8 = 2,
|
|
271
|
+
/** Pixel is 8-bit RGB with an alpha channel */
|
|
272
|
+
Rgba8 = 3,
|
|
273
|
+
/** Pixel is 16-bit luminance */
|
|
274
|
+
L16 = 4,
|
|
275
|
+
/** Pixel is 16-bit luminance with an alpha channel */
|
|
276
|
+
La16 = 5,
|
|
277
|
+
/** Pixel is 16-bit RGB */
|
|
278
|
+
Rgb16 = 6,
|
|
279
|
+
/** Pixel is 16-bit RGBA */
|
|
280
|
+
Rgba16 = 7,
|
|
281
|
+
/** Pixel is 32-bit float RGB */
|
|
282
|
+
Rgb32F = 8,
|
|
283
|
+
/** Pixel is 32-bit float RGBA */
|
|
284
|
+
Rgba32F = 9
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export function losslessCompressPng(input: Buffer, options?: PNGLosslessOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
288
|
+
|
|
289
|
+
export function losslessCompressPngSync(input: Buffer, options?: PNGLosslessOptions | undefined | null): Buffer
|
|
290
|
+
|
|
291
|
+
export interface Metadata {
|
|
292
|
+
width: number
|
|
293
|
+
height: number
|
|
294
|
+
exif?: Record<string, string>
|
|
295
|
+
orientation?: number
|
|
296
|
+
format: string
|
|
297
|
+
colorType: JsColorType
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export const enum Orientation {
|
|
301
|
+
/** Normal */
|
|
302
|
+
Horizontal = 1,
|
|
303
|
+
MirrorHorizontal = 2,
|
|
304
|
+
Rotate180 = 3,
|
|
305
|
+
MirrorVertical = 4,
|
|
306
|
+
MirrorHorizontalAndRotate270Cw = 5,
|
|
307
|
+
Rotate90Cw = 6,
|
|
308
|
+
MirrorHorizontalAndRotate90Cw = 7,
|
|
309
|
+
Rotate270Cw = 8
|
|
310
|
+
}
|
|
311
|
+
|
|
158
312
|
export interface PngEncodeOptions {
|
|
159
313
|
/** Default is `CompressionType::Default` */
|
|
160
314
|
compressionType?: CompressionType
|
|
161
315
|
/** Default is `FilterType::NoFilter` */
|
|
162
316
|
filterType?: FilterType
|
|
163
317
|
}
|
|
164
|
-
|
|
165
|
-
None = 0,
|
|
166
|
-
Sub = 1,
|
|
167
|
-
Up = 2,
|
|
168
|
-
Average = 3,
|
|
169
|
-
Paeth = 4,
|
|
170
|
-
MinSum = 5,
|
|
171
|
-
Entropy = 6,
|
|
172
|
-
Bigrams = 7,
|
|
173
|
-
BigEnt = 8,
|
|
174
|
-
Brute = 9
|
|
175
|
-
}
|
|
318
|
+
|
|
176
319
|
export interface PNGLosslessOptions {
|
|
177
320
|
/**
|
|
178
321
|
* Attempt to fix errors when decoding the input file rather than returning an Err.
|
|
@@ -215,8 +358,11 @@ export interface PNGLosslessOptions {
|
|
|
215
358
|
/** Whether to remove ***All non-critical headers*** on PNG */
|
|
216
359
|
strip?: boolean
|
|
217
360
|
}
|
|
218
|
-
|
|
219
|
-
export function
|
|
361
|
+
|
|
362
|
+
export function pngQuantize(input: Buffer, options?: PngQuantOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
363
|
+
|
|
364
|
+
export function pngQuantizeSync(input: Buffer, options?: PngQuantOptions | undefined | null): Buffer
|
|
365
|
+
|
|
220
366
|
export interface PngQuantOptions {
|
|
221
367
|
/** default is 70 */
|
|
222
368
|
minQuality?: number
|
|
@@ -234,19 +380,20 @@ export interface PngQuantOptions {
|
|
|
234
380
|
*/
|
|
235
381
|
posterization?: number
|
|
236
382
|
}
|
|
237
|
-
|
|
238
|
-
export
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
383
|
+
|
|
384
|
+
export const enum PngRowFilter {
|
|
385
|
+
None = 0,
|
|
386
|
+
Sub = 1,
|
|
387
|
+
Up = 2,
|
|
388
|
+
Average = 3,
|
|
389
|
+
Paeth = 4,
|
|
390
|
+
MinSum = 5,
|
|
391
|
+
Entropy = 6,
|
|
392
|
+
Bigrams = 7,
|
|
393
|
+
BigEnt = 8,
|
|
394
|
+
Brute = 9
|
|
249
395
|
}
|
|
396
|
+
|
|
250
397
|
/**
|
|
251
398
|
* Available Sampling Filters.
|
|
252
399
|
*
|
|
@@ -327,151 +474,26 @@ export const enum ResizeFilterType {
|
|
|
327
474
|
/** Lanczos with window 3 */
|
|
328
475
|
Lanczos3 = 4
|
|
329
476
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
Rgb16 = 6,
|
|
345
|
-
/** Pixel is 16-bit RGBA */
|
|
346
|
-
Rgba16 = 7,
|
|
347
|
-
/** Pixel is 32-bit float RGB */
|
|
348
|
-
Rgb32F = 8,
|
|
349
|
-
/** Pixel is 32-bit float RGBA */
|
|
350
|
-
Rgba32F = 9
|
|
351
|
-
}
|
|
352
|
-
export interface Metadata {
|
|
353
|
-
width: number
|
|
354
|
-
height: number
|
|
355
|
-
exif?: Record<string, string>
|
|
356
|
-
orientation?: number
|
|
357
|
-
format: string
|
|
358
|
-
colorType: JsColorType
|
|
477
|
+
|
|
478
|
+
export const enum ResizeFit {
|
|
479
|
+
/**
|
|
480
|
+
* (default) Preserving aspect ratio
|
|
481
|
+
* ensure the image covers both provided dimensions by cropping/clipping to fit.
|
|
482
|
+
*/
|
|
483
|
+
Cover = 0,
|
|
484
|
+
/** Ignore the aspect ratio of the input and stretch to both provided dimensions. */
|
|
485
|
+
Fill = 1,
|
|
486
|
+
/**
|
|
487
|
+
* Preserving aspect ratio
|
|
488
|
+
* resize the image to be as large as possible while ensuring its dimensions are less than or equal to both those specified.
|
|
489
|
+
*/
|
|
490
|
+
Inside = 2
|
|
359
491
|
}
|
|
492
|
+
|
|
360
493
|
export interface ResizeOptions {
|
|
361
494
|
width: number
|
|
362
495
|
height?: number
|
|
363
496
|
filter?: ResizeFilterType
|
|
364
497
|
fit?: ResizeFit
|
|
365
498
|
}
|
|
366
|
-
|
|
367
|
-
constructor(input: Buffer)
|
|
368
|
-
/** Support CSS3 color, e.g. rgba(255, 255, 255, .8) */
|
|
369
|
-
static fromSvg(input: string | Buffer, background?: string | undefined | null): Transformer
|
|
370
|
-
static fromRgbaPixels(input: Uint8Array | Uint8ClampedArray, width: number, height: number): Transformer
|
|
371
|
-
metadata(withExif?: boolean | undefined | null, signal?: AbortSignal | undefined | null): Promise<Metadata>
|
|
372
|
-
/**
|
|
373
|
-
* Rotate with exif orientation
|
|
374
|
-
* If the orientation param is not null,
|
|
375
|
-
* the new orientation value will override the exif orientation value
|
|
376
|
-
*/
|
|
377
|
-
rotate(orientation?: Orientation | undefined | null): this
|
|
378
|
-
/**
|
|
379
|
-
* Return a grayscale version of this image.
|
|
380
|
-
* Returns `Luma` images in most cases. However, for `f32` images,
|
|
381
|
-
* this will return a greyscale `Rgb/Rgba` image instead.
|
|
382
|
-
*/
|
|
383
|
-
grayscale(): this
|
|
384
|
-
/** Invert the colors of this image. */
|
|
385
|
-
invert(): this
|
|
386
|
-
/**
|
|
387
|
-
* Resize this image using the specified filter algorithm.
|
|
388
|
-
* The image is scaled to the maximum possible size that fits
|
|
389
|
-
* within the bounds specified by `width` and `height`.
|
|
390
|
-
*/
|
|
391
|
-
resize(widthOrOptions: number | ResizeOptions, height?: number | undefined | null, filter?: ResizeFilterType | undefined | null, fit?: ResizeFit | undefined | null): this
|
|
392
|
-
/**
|
|
393
|
-
* Resize this image using the specified filter algorithm.
|
|
394
|
-
* The image is scaled to the maximum possible size that fits
|
|
395
|
-
* within the bounds specified by `width` and `height`.
|
|
396
|
-
*
|
|
397
|
-
* This is using faster SIMD based resize implementation
|
|
398
|
-
* the resize filter is different from `resize` method
|
|
399
|
-
*/
|
|
400
|
-
fastResize(options: FastResizeOptions): this
|
|
401
|
-
/**
|
|
402
|
-
* Performs a Gaussian blur on this image.
|
|
403
|
-
* `sigma` is a measure of how much to blur by.
|
|
404
|
-
*/
|
|
405
|
-
blur(sigma: number): this
|
|
406
|
-
/**
|
|
407
|
-
* Performs an unsharpen mask on this image.
|
|
408
|
-
* `sigma` is the amount to blur the image by.
|
|
409
|
-
* `threshold` is a control of how much to sharpen.
|
|
410
|
-
*
|
|
411
|
-
* See <https://en.wikipedia.org/wiki/Unsharp_masking#Digital_unsharp_masking>
|
|
412
|
-
*/
|
|
413
|
-
unsharpen(sigma: number, threshold: number): this
|
|
414
|
-
/** Filters this image with the specified 3x3 kernel. */
|
|
415
|
-
filter3x3(kernel: Array<number>): this
|
|
416
|
-
/**
|
|
417
|
-
* Adjust the contrast of this image.
|
|
418
|
-
* `contrast` is the amount to adjust the contrast by.
|
|
419
|
-
* Negative values decrease the contrast and positive values increase the contrast.
|
|
420
|
-
*/
|
|
421
|
-
adjustContrast(contrast: number): this
|
|
422
|
-
/**
|
|
423
|
-
* Brighten the pixels of this image.
|
|
424
|
-
* `value` is the amount to brighten each pixel by.
|
|
425
|
-
* Negative values decrease the brightness and positive values increase it.
|
|
426
|
-
*/
|
|
427
|
-
brighten(brightness: number): this
|
|
428
|
-
/**
|
|
429
|
-
* Hue rotate the supplied image.
|
|
430
|
-
* `value` is the degrees to rotate each pixel by.
|
|
431
|
-
* 0 and 360 do nothing, the rest rotates by the given degree value.
|
|
432
|
-
* just like the css webkit filter hue-rotate(180)
|
|
433
|
-
*/
|
|
434
|
-
huerotate(hue: number): this
|
|
435
|
-
/** Crop a cut-out of this image delimited by the bounding rectangle. */
|
|
436
|
-
crop(x: number, y: number, width: number, height: number): this
|
|
437
|
-
/** Overlay an image at a given coordinate (x, y) */
|
|
438
|
-
overlay(onTop: Buffer, x: number, y: number): this
|
|
439
|
-
/** Return this image's pixels as a native endian byte slice. */
|
|
440
|
-
rawPixels(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
441
|
-
/** Return this image's pixels as a native endian byte slice. */
|
|
442
|
-
rawPixelsSync(): Buffer
|
|
443
|
-
/**
|
|
444
|
-
* The quality factor `quality_factor` ranges from 0 to 100 and controls the loss and quality during compression.
|
|
445
|
-
* The value 0 corresponds to low quality and small output sizes, whereas 100 is the highest quality and largest output size.
|
|
446
|
-
* https://developers.google.com/speed/webp/docs/api#simple_encoding_api
|
|
447
|
-
*/
|
|
448
|
-
webp(qualityFactor?: number | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
449
|
-
/**
|
|
450
|
-
* The quality factor `quality_factor` ranges from 0 to 100 and controls the loss and quality during compression.
|
|
451
|
-
* The value 0 corresponds to low quality and small output sizes, whereas 100 is the highest quality and largest output size.
|
|
452
|
-
* https://developers.google.com/speed/webp/docs/api#simple_encoding_api
|
|
453
|
-
*/
|
|
454
|
-
webpSync(qualityFactor?: number | undefined | null): Buffer
|
|
455
|
-
webpLossless(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
456
|
-
webpLosslessSync(): Buffer
|
|
457
|
-
avif(options?: AvifConfig | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
458
|
-
avifSync(options?: AvifConfig | undefined | null): Buffer
|
|
459
|
-
png(options?: PngEncodeOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
460
|
-
pngSync(options?: PngEncodeOptions | undefined | null): Buffer
|
|
461
|
-
/** default `quality` is 90 */
|
|
462
|
-
jpeg(quality?: number | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
463
|
-
/** default `quality` is 90 */
|
|
464
|
-
jpegSync(quality?: number | undefined | null): Buffer
|
|
465
|
-
bmp(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
466
|
-
bmpSync(): Buffer
|
|
467
|
-
ico(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
468
|
-
icoSync(): Buffer
|
|
469
|
-
tiff(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
470
|
-
tiffSync(): Buffer
|
|
471
|
-
pnm(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
472
|
-
pnmSync(): Buffer
|
|
473
|
-
tga(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
474
|
-
tgaSync(): Buffer
|
|
475
|
-
farbfeld(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
476
|
-
farbfeldSync(): Buffer
|
|
477
|
-
}
|
|
499
|
+
|
package/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// prettier-ignore
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
/* prettier-ignore */
|
|
4
|
-
|
|
5
3
|
/* auto-generated by NAPI-RS */
|
|
6
4
|
|
|
7
5
|
const { existsSync, readFileSync } = require('fs')
|
|
@@ -13,18 +11,52 @@ let nativeBinding = null
|
|
|
13
11
|
let localFileExisted = false
|
|
14
12
|
let loadError = null
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
14
|
+
const isMusl = () => {
|
|
15
|
+
let musl = false
|
|
16
|
+
if (process.platform === 'linux') {
|
|
17
|
+
musl = isMuslFromFilesystem()
|
|
18
|
+
if (musl === null) {
|
|
19
|
+
musl = isMuslFromReport()
|
|
20
|
+
}
|
|
21
|
+
if (musl === null) {
|
|
22
|
+
musl = isMuslFromChildProcess()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return musl
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
29
|
+
|
|
30
|
+
const isMuslFromFilesystem = () => {
|
|
31
|
+
try {
|
|
32
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
33
|
+
} catch {
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const isMuslFromReport = () => {
|
|
39
|
+
const report = typeof process.report.getReport === 'function' ? process.report.getReport() : null
|
|
40
|
+
if (!report) {
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
47
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
23
48
|
return true
|
|
24
49
|
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
50
|
+
}
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const isMuslFromChildProcess = () => {
|
|
55
|
+
try {
|
|
56
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
57
|
+
} catch (e) {
|
|
58
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
59
|
+
return false
|
|
28
60
|
}
|
|
29
61
|
}
|
|
30
62
|
|
|
@@ -237,6 +269,49 @@ switch (platform) {
|
|
|
237
269
|
loadError = e
|
|
238
270
|
}
|
|
239
271
|
break
|
|
272
|
+
case 'riscv64':
|
|
273
|
+
if (isMusl()) {
|
|
274
|
+
localFileExisted = existsSync(
|
|
275
|
+
join(__dirname, 'image.linux-riscv64-musl.node')
|
|
276
|
+
)
|
|
277
|
+
try {
|
|
278
|
+
if (localFileExisted) {
|
|
279
|
+
nativeBinding = require('./image.linux-riscv64-musl.node')
|
|
280
|
+
} else {
|
|
281
|
+
nativeBinding = require('@napi-rs/image-linux-riscv64-musl')
|
|
282
|
+
}
|
|
283
|
+
} catch (e) {
|
|
284
|
+
loadError = e
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
localFileExisted = existsSync(
|
|
288
|
+
join(__dirname, 'image.linux-riscv64-gnu.node')
|
|
289
|
+
)
|
|
290
|
+
try {
|
|
291
|
+
if (localFileExisted) {
|
|
292
|
+
nativeBinding = require('./image.linux-riscv64-gnu.node')
|
|
293
|
+
} else {
|
|
294
|
+
nativeBinding = require('@napi-rs/image-linux-riscv64-gnu')
|
|
295
|
+
}
|
|
296
|
+
} catch (e) {
|
|
297
|
+
loadError = e
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
break
|
|
301
|
+
case 's390x':
|
|
302
|
+
localFileExisted = existsSync(
|
|
303
|
+
join(__dirname, 'image.linux-s390x-gnu.node')
|
|
304
|
+
)
|
|
305
|
+
try {
|
|
306
|
+
if (localFileExisted) {
|
|
307
|
+
nativeBinding = require('./image.linux-s390x-gnu.node')
|
|
308
|
+
} else {
|
|
309
|
+
nativeBinding = require('@napi-rs/image-linux-s390x-gnu')
|
|
310
|
+
}
|
|
311
|
+
} catch (e) {
|
|
312
|
+
loadError = e
|
|
313
|
+
}
|
|
314
|
+
break
|
|
240
315
|
default:
|
|
241
316
|
throw new Error(`Unsupported architecture on Linux: ${arch}`)
|
|
242
317
|
}
|
|
@@ -245,6 +320,25 @@ switch (platform) {
|
|
|
245
320
|
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
|
|
246
321
|
}
|
|
247
322
|
|
|
323
|
+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
324
|
+
try {
|
|
325
|
+
nativeBinding = require('./image.wasi.cjs')
|
|
326
|
+
} catch (err) {
|
|
327
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
328
|
+
console.error(err)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (!nativeBinding) {
|
|
332
|
+
try {
|
|
333
|
+
nativeBinding = require('@napi-rs/image-wasm32-wasi')
|
|
334
|
+
} catch (err) {
|
|
335
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
336
|
+
console.error(err)
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
248
342
|
if (!nativeBinding) {
|
|
249
343
|
if (loadError) {
|
|
250
344
|
throw loadError
|
|
@@ -252,21 +346,19 @@ if (!nativeBinding) {
|
|
|
252
346
|
throw new Error(`Failed to load native binding`)
|
|
253
347
|
}
|
|
254
348
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
module.exports.
|
|
258
|
-
module.exports.
|
|
259
|
-
module.exports.
|
|
260
|
-
module.exports.
|
|
261
|
-
module.exports.
|
|
262
|
-
module.exports.
|
|
263
|
-
module.exports.
|
|
264
|
-
module.exports.
|
|
265
|
-
module.exports.
|
|
266
|
-
module.exports.
|
|
267
|
-
module.exports.pngQuantizeSync = pngQuantizeSync
|
|
268
|
-
module.exports.
|
|
269
|
-
module.exports.
|
|
270
|
-
module.exports.
|
|
271
|
-
module.exports.JsColorType = JsColorType
|
|
272
|
-
module.exports.Transformer = Transformer
|
|
349
|
+
module.exports.Transformer = nativeBinding.Transformer
|
|
350
|
+
module.exports.ChromaSubsampling = nativeBinding.ChromaSubsampling
|
|
351
|
+
module.exports.CompressionType = nativeBinding.CompressionType
|
|
352
|
+
module.exports.compressJpeg = nativeBinding.compressJpeg
|
|
353
|
+
module.exports.compressJpegSync = nativeBinding.compressJpegSync
|
|
354
|
+
module.exports.FastResizeFilter = nativeBinding.FastResizeFilter
|
|
355
|
+
module.exports.FilterType = nativeBinding.FilterType
|
|
356
|
+
module.exports.JsColorType = nativeBinding.JsColorType
|
|
357
|
+
module.exports.losslessCompressPng = nativeBinding.losslessCompressPng
|
|
358
|
+
module.exports.losslessCompressPngSync = nativeBinding.losslessCompressPngSync
|
|
359
|
+
module.exports.Orientation = nativeBinding.Orientation
|
|
360
|
+
module.exports.pngQuantize = nativeBinding.pngQuantize
|
|
361
|
+
module.exports.pngQuantizeSync = nativeBinding.pngQuantizeSync
|
|
362
|
+
module.exports.PngRowFilter = nativeBinding.PngRowFilter
|
|
363
|
+
module.exports.ResizeFilterType = nativeBinding.ResizeFilterType
|
|
364
|
+
module.exports.ResizeFit = nativeBinding.ResizeFit
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/image",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"main": "index.js",
|
|
5
|
+
"browser": "browser.js",
|
|
5
6
|
"types": "index.d.ts",
|
|
6
7
|
"description": "Image processing library",
|
|
7
8
|
"author": {
|
|
@@ -27,20 +28,21 @@
|
|
|
27
28
|
"access": "public"
|
|
28
29
|
},
|
|
29
30
|
"napi": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
"binaryName": "image",
|
|
32
|
+
"targets": [
|
|
33
|
+
"x86_64-apple-darwin",
|
|
34
|
+
"x86_64-pc-windows-msvc",
|
|
35
|
+
"x86_64-unknown-linux-gnu",
|
|
36
|
+
"aarch64-apple-darwin",
|
|
37
|
+
"aarch64-linux-android",
|
|
38
|
+
"aarch64-unknown-linux-gnu",
|
|
39
|
+
"aarch64-unknown-linux-musl",
|
|
40
|
+
"armv7-unknown-linux-gnueabihf",
|
|
41
|
+
"x86_64-unknown-linux-musl",
|
|
42
|
+
"x86_64-unknown-freebsd",
|
|
43
|
+
"i686-pc-windows-msvc",
|
|
44
|
+
"wasm32-wasi-preview1-threads"
|
|
45
|
+
]
|
|
44
46
|
},
|
|
45
47
|
"license": "MIT",
|
|
46
48
|
"engines": {
|
|
@@ -58,25 +60,26 @@
|
|
|
58
60
|
"format:prettier": "prettier --config ./package.json -w .",
|
|
59
61
|
"format:rs": "cargo fmt --all",
|
|
60
62
|
"prepublishOnly": "napi prepublish",
|
|
61
|
-
"version": "napi version"
|
|
63
|
+
"version": "napi version && git add npm"
|
|
62
64
|
},
|
|
63
65
|
"repository": "git@github.com:Brooooooklyn/Image.git",
|
|
64
66
|
"devDependencies": {
|
|
65
|
-
"@napi-rs/cli": "^
|
|
67
|
+
"@napi-rs/cli": "^3.0.0-alpha.40",
|
|
68
|
+
"@napi-rs/wasm-runtime": "^0.1.1"
|
|
66
69
|
},
|
|
67
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "caeb47b4e0b58de9280f5bdd2dab4d16c643d6b7",
|
|
68
71
|
"optionalDependencies": {
|
|
69
|
-
"@napi-rs/image-
|
|
70
|
-
"@napi-rs/image-
|
|
71
|
-
"@napi-rs/image-linux-x64-gnu": "1.
|
|
72
|
-
"@napi-rs/image-darwin-arm64": "1.
|
|
73
|
-
"@napi-rs/image-android-arm64": "1.
|
|
74
|
-
"@napi-rs/image-linux-arm64-gnu": "1.
|
|
75
|
-
"@napi-rs/image-linux-arm64-musl": "1.
|
|
76
|
-
"@napi-rs/image-linux-arm-gnueabihf": "1.
|
|
77
|
-
"@napi-rs/image-linux-x64-musl": "1.
|
|
78
|
-
"@napi-rs/image-freebsd-x64": "1.
|
|
79
|
-
"@napi-rs/image-win32-ia32-msvc": "1.
|
|
80
|
-
"@napi-rs/image-
|
|
72
|
+
"@napi-rs/image-darwin-x64": "1.9.0",
|
|
73
|
+
"@napi-rs/image-win32-x64-msvc": "1.9.0",
|
|
74
|
+
"@napi-rs/image-linux-x64-gnu": "1.9.0",
|
|
75
|
+
"@napi-rs/image-darwin-arm64": "1.9.0",
|
|
76
|
+
"@napi-rs/image-android-arm64": "1.9.0",
|
|
77
|
+
"@napi-rs/image-linux-arm64-gnu": "1.9.0",
|
|
78
|
+
"@napi-rs/image-linux-arm64-musl": "1.9.0",
|
|
79
|
+
"@napi-rs/image-linux-arm-gnueabihf": "1.9.0",
|
|
80
|
+
"@napi-rs/image-linux-x64-musl": "1.9.0",
|
|
81
|
+
"@napi-rs/image-freebsd-x64": "1.9.0",
|
|
82
|
+
"@napi-rs/image-win32-ia32-msvc": "1.9.0",
|
|
83
|
+
"@napi-rs/image-wasm32-wasi": "1.9.0"
|
|
81
84
|
}
|
|
82
85
|
}
|