@fe-daily/libimagequant-wasm
Version:
WASM bindings for libimagequant image quantization library
72 lines • 2.28 kB
TypeScript
/**
* libimagequant WASM - Promise-based API for PNG image quantization in browsers
*
* This module provides a high-level, promise-based interface for the libimagequant
* image quantization library using WASM directly.
*/
export interface QuantizationOptions {
/** Speed vs quality trade-off (1-10, lower = better quality) */
speed?: number;
/** Quality settings */
quality?: {
min: number;
target: number;
};
/** Maximum colors in palette (2-256) */
maxColors?: number;
/** Dithering level (0.0-1.0) */
dithering?: number;
/** Posterization level (0-4) */
posterization?: number;
}
export interface QuantizationResult {
/** Color palette array */
palette: number[][];
/** PNG bytes (Uint8Array) - quantized image as indexed PNG */
pngBytes: Uint8Array;
/** ImageData object - quantized image as RGBA data */
imageData: ImageData;
/** Achieved quality (0-1) */
quality: number;
/** Number of colors in palette */
paletteLength: number;
/** Image width */
width: number;
/** Image height */
height: number;
}
export interface LibImageQuantOptions {
/** Custom path to WASM module directory (should contain libimagequant_wasm.js) */
wasmUrl?: string;
/** Pre-loaded WASM module (useful for Next.js and other bundlers) */
wasmModule?: any;
}
export default class LibImageQuant {
private wasmModule;
private isInitialized;
private wasmUrl?;
private preloadedWasmModule?;
private initPromise;
constructor(options?: LibImageQuantOptions);
/**
* Initialize the WASM module
*/
private initializeWasm;
/**
* Quantize a PNG from bytes or Blob
*/
quantizePng(pngData: Uint8Array | ArrayBuffer | Blob, options?: QuantizationOptions): Promise<QuantizationResult>;
/**
* Quantize from ImageData and return as PNG bytes or ImageData
*/
quantizeImageData(imageData: ImageData, options?: QuantizationOptions): Promise<QuantizationResult>;
/**
* Internal method to quantize RGBA data
*/
private quantizeRgbaData;
/**
* Clean up resources (no longer needed since we're not using workers)
*/
dispose(): void;
}
//# sourceMappingURL=index.d.ts.map