UPNG.js is a small, fast, and advanced PNG/APNG encoder and decoder, used as the core PNG engine in the Photopea image editor (current stable: 2.1.0). It supports encoding single PNGs and APNG animations with optional lossy color quantization (k-means) for file size reduction, decoding all color types, bit depths (1–16), interlaced images, and additional PNG chunks. Key differentiators include handling PNGs that other libraries cannot open, lossy compression akin to TinyPNG, and a lightweight footprint.
npm install upng-jsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates decoding a PNG file to get metadata and RGBA data, and encoding a 2x2 red image as a PNG. Includes reading/writing via Node.js fs.
Run 'npm install pako' or 'npm install upng-js' (will auto-install pako).
Use .buffer property on typed arrays: e.g., UPNG.encode([uint8array.buffer], w, h, cnum).
Use const rgba = UPNG.toRGBA8(img)[0]; to obtain the first frame's data.
Use cnum=0 for lossless, or cnum=256 for typical lossy; test with your own images.
Consider forking or using alternative libraries like sharp or lwip for active development.
Use 'import UPNG from 'upng-js'' then call UPNG.encode(...).
Run 'npm install pako' or reinstall upng-js to ensure pako is present.
Convert Buffer to ArrayBuffer: e.g., UPNG.decode(data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)).
Access the first frame with [0]: const frame = UPNG.toRGBA8(img)[0];