ECMAScript compliant lightweight PNG editor
Function | BitDepth | TrueColor | GrayScale | Alpha | IndexedColor | Interlace |
---|---|---|---|---|---|---|
parse | 1, 4, 6, 8 | o | o | o | o | x |
pack | 1, 4, 6, 8 | o | o | o | x | x |
npm i png.es
import { parse } from 'png.es';
const pngObject = parse(rawData); // Input type is Uint8Array
import { PNG, pack, COLOR_TYPE } from 'png.es';
// 4px * 4px RGBA image
const pngObject = new PNG(4, 4, COLOR_TYPE.RGBA);
pngObject.setData([255, 255, ....]);
const uint8Array = pack(pngObject);
import { parse, pack } from 'png.es';
const pngObject = parse(rawData);
pngObject.setPixel(2, 2, [255, 0, 0, 255] ); // Set red to x2y2
const uint8Array = pack(pngObject);