@napi-rs/image 1.4.4 → 1.5.1

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.
Files changed (4) hide show
  1. package/README.md +22 -0
  2. package/index.d.ts +77 -1
  3. package/index.js +3 -1
  4. 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
@@ -298,6 +357,12 @@ export interface Metadata {
298
357
  format: string
299
358
  colorType: JsColorType
300
359
  }
360
+ export interface ResizeOptions {
361
+ width: number
362
+ height?: number
363
+ filter?: ResizeFilterType
364
+ fit?: ResizeFit
365
+ }
301
366
  export class Transformer {
302
367
  constructor(input: Buffer)
303
368
  static fromRgbaPixels(input: Buffer | Uint8ClampedArray, width: number, height: number): Transformer
@@ -321,7 +386,16 @@ export class Transformer {
321
386
  * The image is scaled to the maximum possible size that fits
322
387
  * within the bounds specified by `width` and `height`.
323
388
  */
324
- resize(width: number, height?: number | undefined | null, filterType?: ResizeFilterType | undefined | null): this
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
325
399
  /**
326
400
  * Performs a Gaussian blur on this image.
327
401
  * `sigma` is a measure of how much to blur by.
@@ -358,6 +432,8 @@ export class Transformer {
358
432
  huerotate(hue: number): this
359
433
  /** Crop a cut-out of this image delimited by the bounding rectangle. */
360
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
361
437
  /** Return this image's pixels as a native endian byte slice. */
362
438
  rawPixels(signal?: AbortSignal | undefined | null): Promise<Buffer>
363
439
  /** Return this image's pixels as a native endian byte slice. */
package/index.js CHANGED
@@ -246,9 +246,11 @@ if (!nativeBinding) {
246
246
  throw new Error(`Failed to load native binding`)
247
247
  }
248
248
 
249
- const { ChromaSubsampling, compressJpegSync, compressJpeg, CompressionType, FilterType, PngRowFilter, 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/image",
3
- "version": "1.4.4",
3
+ "version": "1.5.1",
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.14.1"
64
+ "@napi-rs/cli": "^2.14.3"
65
65
  },
66
- "gitHead": "fdd80a15bf0f215383c622a4361a3b74dd22bddd",
66
+ "gitHead": "21d75bbe1650438b5901a51de34f1dccfc149359",
67
67
  "optionalDependencies": {
68
- "@napi-rs/image-win32-x64-msvc": "1.4.4",
69
- "@napi-rs/image-darwin-x64": "1.4.4",
70
- "@napi-rs/image-linux-x64-gnu": "1.4.4",
71
- "@napi-rs/image-darwin-arm64": "1.4.4",
72
- "@napi-rs/image-android-arm64": "1.4.4",
73
- "@napi-rs/image-linux-arm64-gnu": "1.4.4",
74
- "@napi-rs/image-linux-arm64-musl": "1.4.4",
75
- "@napi-rs/image-linux-arm-gnueabihf": "1.4.4",
76
- "@napi-rs/image-linux-x64-musl": "1.4.4",
77
- "@napi-rs/image-freebsd-x64": "1.4.4",
78
- "@napi-rs/image-win32-ia32-msvc": "1.4.4",
79
- "@napi-rs/image-android-arm-eabi": "1.4.4"
68
+ "@napi-rs/image-win32-x64-msvc": "1.5.1",
69
+ "@napi-rs/image-darwin-x64": "1.5.1",
70
+ "@napi-rs/image-linux-x64-gnu": "1.5.1",
71
+ "@napi-rs/image-darwin-arm64": "1.5.1",
72
+ "@napi-rs/image-android-arm64": "1.5.1",
73
+ "@napi-rs/image-linux-arm64-gnu": "1.5.1",
74
+ "@napi-rs/image-linux-arm64-musl": "1.5.1",
75
+ "@napi-rs/image-linux-arm-gnueabihf": "1.5.1",
76
+ "@napi-rs/image-linux-x64-musl": "1.5.1",
77
+ "@napi-rs/image-freebsd-x64": "1.5.1",
78
+ "@napi-rs/image-win32-ia32-msvc": "1.5.1",
79
+ "@napi-rs/image-android-arm-eabi": "1.5.1"
80
80
  }
81
81
  }