beautiful-image 0.2.2 → 0.2.4

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.
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("node:fs"),m=require("node:url"),l=require("node:path"),s=require("./image-processor-hqbPBWVw.cjs");var i=typeof document<"u"?document.currentScript:null;const h=l.dirname(m.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:i&&i.tagName.toUpperCase()==="SCRIPT"&&i.src||new URL("beautiful-image.node.cjs",document.baseURI).href));let a=!1;async function f(){if(!a){const t=l.join(h,"../wasm/beautiful_image_bg.wasm"),e=c.readFileSync(t);await s.__wbg_init({module_or_path:e}),a=!0}}class p extends s.ImageProcessor{constructor(e){super(e)}async toJpeg(e){await f();const u=new Uint8Array(this.file.buffer,this.file.byteOffset,this.file.byteLength),n=s.processImageFromBytes(u,this.targetWidth??null,e,this.ops.sharpenSigma??null,this.ops.sharpenThreshold??null,this.ops.blurSigma??null,this.ops.brightness??null,this.ops.contrast??null,this.ops.grayscale,this.ops.invert,this.ops.hueRotate??null),o=this.file.byteLength,r=n.length;return{data:Buffer.from(n),originalSize:o,optimizedSize:r,compressionRatio:1-r/o}}}const d=t=>new p(t);exports.processImageFromBytes=s.processImageFromBytes;exports.image=d;
@@ -0,0 +1,44 @@
1
+ export declare const image: (file: Buffer | Uint8Array) => ImageProcessorNode;
2
+
3
+ declare abstract class ImageProcessor<TInput, TResult> {
4
+ protected file: TInput;
5
+ protected targetWidth?: number;
6
+ protected ops: Operations;
7
+ constructor(file: TInput);
8
+ resize(width: number): this;
9
+ sharpen(sigma?: number, threshold?: number): this;
10
+ blur(sigma: number): this;
11
+ brightness(value: number): this;
12
+ contrast(value: number): this;
13
+ grayscale(): this;
14
+ invert(): this;
15
+ hueRotate(degrees: number): this;
16
+ abstract toJpeg(quality: number): Promise<TResult>;
17
+ }
18
+
19
+ declare class ImageProcessorNode extends ImageProcessor<Buffer | Uint8Array, NodeOptimizeResult> {
20
+ constructor(file: Buffer | Uint8Array);
21
+ toJpeg(quality: number): Promise<NodeOptimizeResult>;
22
+ }
23
+
24
+ export declare interface NodeOptimizeResult {
25
+ data: Buffer;
26
+ originalSize: number;
27
+ optimizedSize: number;
28
+ compressionRatio: number;
29
+ }
30
+
31
+ declare interface Operations {
32
+ sharpenSigma?: number;
33
+ sharpenThreshold?: number;
34
+ blurSigma?: number;
35
+ brightness?: number;
36
+ contrast?: number;
37
+ grayscale: boolean;
38
+ invert: boolean;
39
+ hueRotate?: number;
40
+ }
41
+
42
+ export declare function processImageFromBytes(image_data: Uint8Array, target_width: number | null | undefined, quality: number, sharpen_sigma: number | null | undefined, sharpen_threshold: number | null | undefined, blur_sigma: number | null | undefined, brightness: number | null | undefined, contrast: number | null | undefined, grayscale: boolean, invert: boolean, hue_rotate?: number | null): Uint8Array;
43
+
44
+ export { }
@@ -0,0 +1,44 @@
1
+ import { readFileSync as n } from "node:fs";
2
+ import { fileURLToPath as l } from "node:url";
3
+ import { dirname as m, join as h } from "node:path";
4
+ import { I as p, a as u, _ as c } from "./image-processor-CfaoYWMt.js";
5
+ const f = m(l(import.meta.url));
6
+ let r = !1;
7
+ async function g() {
8
+ if (!r) {
9
+ const s = h(f, "../wasm/beautiful_image_bg.wasm"), t = n(s);
10
+ await c({ module_or_path: t }), r = !0;
11
+ }
12
+ }
13
+ class d extends p {
14
+ constructor(t) {
15
+ super(t);
16
+ }
17
+ async toJpeg(t) {
18
+ await g();
19
+ const a = new Uint8Array(this.file.buffer, this.file.byteOffset, this.file.byteLength), e = u(
20
+ a,
21
+ this.targetWidth ?? null,
22
+ t,
23
+ this.ops.sharpenSigma ?? null,
24
+ this.ops.sharpenThreshold ?? null,
25
+ this.ops.blurSigma ?? null,
26
+ this.ops.brightness ?? null,
27
+ this.ops.contrast ?? null,
28
+ this.ops.grayscale,
29
+ this.ops.invert,
30
+ this.ops.hueRotate ?? null
31
+ ), i = this.file.byteLength, o = e.length;
32
+ return {
33
+ data: Buffer.from(e),
34
+ originalSize: i,
35
+ optimizedSize: o,
36
+ compressionRatio: 1 - o / i
37
+ };
38
+ }
39
+ }
40
+ const I = (s) => new d(s);
41
+ export {
42
+ I as image,
43
+ u as processImageFromBytes
44
+ };