@vereign/lib-png
v1.0.3
Published
JavaScript PNG encoder/decoder with metadata storage functionality
Downloads
2,488
Readme
Lib PNG
Table of contents
[[TOC]]
JavaScript PNG encoder/decoder with metadata storage functionality
Installation
- Set up authentication to the company NPM account
$ yarn add @vereign/lib-png
or$ npm install @vereign/lib-png
Usage
import PNG from "@vereign/png"
Initialization
Browser
function base64ToBytes(base64) {
var binary_string = window.atob(base64);
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes;
}
const pngBase64 = "iVBORw0KGgoAA...JRU5ErkJggg==";
const png = PNG.readPng(base64ToBytes(pngBase64));
Node.JS
const pngBase64 = "iVBORw0KGgoAA...JRU5ErkJggg==";
const png = PNG.readPng(Buffer.from(pngBase64, "base64"));
Google Script
const pngBase64 = "iVBORw0KGgoAA...JRU5ErkJggg==";
const png = PNG.readPng(new Uint8Array(Utilities.base64Decode(pngBase64)));
Metadata API
import { addMetaData, getMetaData } from "@veriegn/png"
const pngBase64 = "iVBORw0KGgoAA...JRU5ErkJggg==";
const png = PNG.readPng(Buffer.from(pngBase64, "base64"));
addMetaData(png, "abra", "cadabra");
addMetaData(png, "hello", "merlo");
const metaData = getMetaData(png);