@napi-rs/image 1.4.2 → 1.5.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/README.md +22 -0
- package/index.d.ts +90 -4
- package/index.js +4 -1
- package/package.json +15 -15
package/README.md
CHANGED
|
@@ -419,6 +419,28 @@ export const enum ResizeFilterType {
|
|
|
419
419
|
}
|
|
420
420
|
```
|
|
421
421
|
|
|
422
|
+
#### `overlay`
|
|
423
|
+
|
|
424
|
+
```ts
|
|
425
|
+
/**
|
|
426
|
+
* Overlay an image at a given coordinate (x, y)
|
|
427
|
+
*/
|
|
428
|
+
overlay(onTop: Buffer, x: number, y: number): this
|
|
429
|
+
```
|
|
430
|
+
```ts
|
|
431
|
+
import { writeFileSync } from 'fs'
|
|
432
|
+
|
|
433
|
+
import { Transformer } from '@napi-rs/image'
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
const imageOutputPng = await new Transformer(PNG).overlay(PNG, 200, 200).png()
|
|
437
|
+
|
|
438
|
+
writeFileSync(
|
|
439
|
+
'output-overlay-png.png',
|
|
440
|
+
imageOutputPng
|
|
441
|
+
)
|
|
442
|
+
```
|
|
443
|
+
|
|
422
444
|
**ResizeFilterType**:
|
|
423
445
|
|
|
424
446
|
To test the different sampling filters on a real example, you can find two
|
package/index.d.ts
CHANGED
|
@@ -57,6 +57,65 @@ export const enum ChromaSubsampling {
|
|
|
57
57
|
*/
|
|
58
58
|
Yuv400 = 3
|
|
59
59
|
}
|
|
60
|
+
export const enum FastResizeFilter {
|
|
61
|
+
/**
|
|
62
|
+
* Each pixel of source image contributes to one pixel of the
|
|
63
|
+
* destination image with identical weights. For upscaling is equivalent
|
|
64
|
+
* of `Nearest` resize algorithm.
|
|
65
|
+
*/
|
|
66
|
+
Box = 0,
|
|
67
|
+
/**
|
|
68
|
+
* Bilinear filter calculate the output pixel value using linear
|
|
69
|
+
* interpolation on all pixels that may contribute to the output value.
|
|
70
|
+
*/
|
|
71
|
+
Bilinear = 1,
|
|
72
|
+
/**
|
|
73
|
+
* Hamming filter has the same performance as `Bilinear` filter while
|
|
74
|
+
* providing the image downscaling quality comparable to bicubic
|
|
75
|
+
* (`CatmulRom` or `Mitchell`). Produces a sharper image than `Bilinear`,
|
|
76
|
+
* doesn't have dislocations on local level like with `Box`.
|
|
77
|
+
* The filter don’t show good quality for the image upscaling.
|
|
78
|
+
*/
|
|
79
|
+
Hamming = 2,
|
|
80
|
+
/**
|
|
81
|
+
* Catmull-Rom bicubic filter calculate the output pixel value using
|
|
82
|
+
* cubic interpolation on all pixels that may contribute to the output
|
|
83
|
+
* value.
|
|
84
|
+
*/
|
|
85
|
+
CatmullRom = 3,
|
|
86
|
+
/**
|
|
87
|
+
* Mitchell–Netravali bicubic filter calculate the output pixel value
|
|
88
|
+
* using cubic interpolation on all pixels that may contribute to the
|
|
89
|
+
* output value.
|
|
90
|
+
*/
|
|
91
|
+
Mitchell = 4,
|
|
92
|
+
/**
|
|
93
|
+
* Lanczos3 filter calculate the output pixel value using a high-quality
|
|
94
|
+
* Lanczos filter (a truncated sinc) on all pixels that may contribute
|
|
95
|
+
* to the output value.
|
|
96
|
+
*/
|
|
97
|
+
Lanczos3 = 5
|
|
98
|
+
}
|
|
99
|
+
export const enum ResizeFit {
|
|
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
|
+
}
|
|
113
|
+
export interface FastResizeOptions {
|
|
114
|
+
width: number
|
|
115
|
+
height?: number
|
|
116
|
+
filter?: FastResizeFilter
|
|
117
|
+
fit?: ResizeFit
|
|
118
|
+
}
|
|
60
119
|
export interface JpegCompressOptions {
|
|
61
120
|
/** Output quality, default is 100 (lossless) */
|
|
62
121
|
quality?: number
|
|
@@ -102,6 +161,18 @@ export interface PngEncodeOptions {
|
|
|
102
161
|
/** Default is `FilterType::NoFilter` */
|
|
103
162
|
filterType?: FilterType
|
|
104
163
|
}
|
|
164
|
+
export const enum PngRowFilter {
|
|
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
|
+
}
|
|
105
176
|
export interface PNGLosslessOptions {
|
|
106
177
|
/**
|
|
107
178
|
* Attempt to fix errors when decoding the input file rather than returning an Err.
|
|
@@ -114,7 +185,7 @@ export interface PNGLosslessOptions {
|
|
|
114
185
|
*/
|
|
115
186
|
force?: boolean
|
|
116
187
|
/** Which filters to try on the file (0-5) */
|
|
117
|
-
filter?: Array<
|
|
188
|
+
filter?: Array<PngRowFilter>
|
|
118
189
|
/**
|
|
119
190
|
* Whether to attempt bit depth reduction
|
|
120
191
|
* Default: `true`
|
|
@@ -143,8 +214,6 @@ export interface PNGLosslessOptions {
|
|
|
143
214
|
idatRecoding?: boolean
|
|
144
215
|
/** Whether to remove ***All non-critical headers*** on PNG */
|
|
145
216
|
strip?: boolean
|
|
146
|
-
/** Whether to use heuristics to pick the best filter and compression */
|
|
147
|
-
useHeuristics?: boolean
|
|
148
217
|
}
|
|
149
218
|
export function losslessCompressPngSync(input: Buffer, options?: PNGLosslessOptions | undefined | null): Buffer
|
|
150
219
|
export function losslessCompressPng(input: Buffer, options?: PNGLosslessOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
@@ -288,6 +357,12 @@ export interface Metadata {
|
|
|
288
357
|
format: string
|
|
289
358
|
colorType: JsColorType
|
|
290
359
|
}
|
|
360
|
+
export interface ResizeOptions {
|
|
361
|
+
width: number
|
|
362
|
+
height?: number
|
|
363
|
+
filter?: ResizeFilterType
|
|
364
|
+
fit?: ResizeFit
|
|
365
|
+
}
|
|
291
366
|
export class Transformer {
|
|
292
367
|
constructor(input: Buffer)
|
|
293
368
|
static fromRgbaPixels(input: Buffer | Uint8ClampedArray, width: number, height: number): Transformer
|
|
@@ -311,7 +386,16 @@ export class Transformer {
|
|
|
311
386
|
* The image is scaled to the maximum possible size that fits
|
|
312
387
|
* within the bounds specified by `width` and `height`.
|
|
313
388
|
*/
|
|
314
|
-
resize(
|
|
389
|
+
resize(widthOrOptions: number | ResizeOptions, height?: number | undefined | null, filter?: ResizeFilterType | undefined | null, fit?: ResizeFit | undefined | null): this
|
|
390
|
+
/**
|
|
391
|
+
* Resize this image using the specified filter algorithm.
|
|
392
|
+
* The image is scaled to the maximum possible size that fits
|
|
393
|
+
* within the bounds specified by `width` and `height`.
|
|
394
|
+
*
|
|
395
|
+
* This is using faster SIMD based resize implementation
|
|
396
|
+
* the resize filter is different from `resize` method
|
|
397
|
+
*/
|
|
398
|
+
fastResize(options: FastResizeOptions): this
|
|
315
399
|
/**
|
|
316
400
|
* Performs a Gaussian blur on this image.
|
|
317
401
|
* `sigma` is a measure of how much to blur by.
|
|
@@ -348,6 +432,8 @@ export class Transformer {
|
|
|
348
432
|
huerotate(hue: number): this
|
|
349
433
|
/** Crop a cut-out of this image delimited by the bounding rectangle. */
|
|
350
434
|
crop(x: number, y: number, width: number, height: number): this
|
|
435
|
+
/** Overlay an image at a given coordinate (x, y) */
|
|
436
|
+
overlay(onTop: Buffer, x: number, y: number): this
|
|
351
437
|
/** Return this image's pixels as a native endian byte slice. */
|
|
352
438
|
rawPixels(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
353
439
|
/** Return this image's pixels as a native endian byte slice. */
|
package/index.js
CHANGED
|
@@ -246,13 +246,16 @@ if (!nativeBinding) {
|
|
|
246
246
|
throw new Error(`Failed to load native binding`)
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
const { ChromaSubsampling, compressJpegSync, compressJpeg, CompressionType, FilterType, losslessCompressPngSync, losslessCompressPng, pngQuantizeSync, pngQuantize, Orientation, ResizeFilterType, JsColorType, Transformer } = nativeBinding
|
|
249
|
+
const { ChromaSubsampling, FastResizeFilter, ResizeFit, compressJpegSync, compressJpeg, CompressionType, FilterType, PngRowFilter, losslessCompressPngSync, losslessCompressPng, pngQuantizeSync, pngQuantize, Orientation, ResizeFilterType, JsColorType, Transformer } = nativeBinding
|
|
250
250
|
|
|
251
251
|
module.exports.ChromaSubsampling = ChromaSubsampling
|
|
252
|
+
module.exports.FastResizeFilter = FastResizeFilter
|
|
253
|
+
module.exports.ResizeFit = ResizeFit
|
|
252
254
|
module.exports.compressJpegSync = compressJpegSync
|
|
253
255
|
module.exports.compressJpeg = compressJpeg
|
|
254
256
|
module.exports.CompressionType = CompressionType
|
|
255
257
|
module.exports.FilterType = FilterType
|
|
258
|
+
module.exports.PngRowFilter = PngRowFilter
|
|
256
259
|
module.exports.losslessCompressPngSync = losslessCompressPngSync
|
|
257
260
|
module.exports.losslessCompressPng = losslessCompressPng
|
|
258
261
|
module.exports.pngQuantizeSync = pngQuantizeSync
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/image",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"description": "Image processing library",
|
|
@@ -61,21 +61,21 @@
|
|
|
61
61
|
},
|
|
62
62
|
"repository": "git@github.com:Brooooooklyn/Image.git",
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@napi-rs/cli": "^2.
|
|
64
|
+
"@napi-rs/cli": "^2.14.3"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "c111cd9d79b36943b3c082fabc3510ca9e4f5645",
|
|
67
67
|
"optionalDependencies": {
|
|
68
|
-
"@napi-rs/image-win32-x64-msvc": "1.
|
|
69
|
-
"@napi-rs/image-darwin-x64": "1.
|
|
70
|
-
"@napi-rs/image-linux-x64-gnu": "1.
|
|
71
|
-
"@napi-rs/image-darwin-arm64": "1.
|
|
72
|
-
"@napi-rs/image-android-arm64": "1.
|
|
73
|
-
"@napi-rs/image-linux-arm64-gnu": "1.
|
|
74
|
-
"@napi-rs/image-linux-arm64-musl": "1.
|
|
75
|
-
"@napi-rs/image-linux-arm-gnueabihf": "1.
|
|
76
|
-
"@napi-rs/image-linux-x64-musl": "1.
|
|
77
|
-
"@napi-rs/image-freebsd-x64": "1.
|
|
78
|
-
"@napi-rs/image-win32-ia32-msvc": "1.
|
|
79
|
-
"@napi-rs/image-android-arm-eabi": "1.
|
|
68
|
+
"@napi-rs/image-win32-x64-msvc": "1.5.0",
|
|
69
|
+
"@napi-rs/image-darwin-x64": "1.5.0",
|
|
70
|
+
"@napi-rs/image-linux-x64-gnu": "1.5.0",
|
|
71
|
+
"@napi-rs/image-darwin-arm64": "1.5.0",
|
|
72
|
+
"@napi-rs/image-android-arm64": "1.5.0",
|
|
73
|
+
"@napi-rs/image-linux-arm64-gnu": "1.5.0",
|
|
74
|
+
"@napi-rs/image-linux-arm64-musl": "1.5.0",
|
|
75
|
+
"@napi-rs/image-linux-arm-gnueabihf": "1.5.0",
|
|
76
|
+
"@napi-rs/image-linux-x64-musl": "1.5.0",
|
|
77
|
+
"@napi-rs/image-freebsd-x64": "1.5.0",
|
|
78
|
+
"@napi-rs/image-win32-ia32-msvc": "1.5.0",
|
|
79
|
+
"@napi-rs/image-android-arm-eabi": "1.5.0"
|
|
80
80
|
}
|
|
81
81
|
}
|