1.0.3 • Published 3 years ago
giflib-wasm v1.0.3
interface FrameItem {
data: Uint8ClampedArray;
keyframe: boolean;
duration: number;
}
declare const decode: (data: Uint8Array) => Promise<{
width: number;
height: number;
frameList: FrameItem[];
bgColor: number;
loopCount: number;
}>;
declare const encode: (config: {
width: number;
height: number;
frameList: {
data: Uint8ClampedArray | Uint8Array;
keyframe?: boolean;
duration?: number;
}[];
}) => Promise<Uint8Array>;
export { decode, encode };
import { decode, encode } from "../src";
import fs from "fs";
import path from "path";
async function main() {
const cwd = path.resolve(".");
const p = path.join(cwd, "./gifs/w.gif");
const buf = fs.readFileSync(p);
const { height, width, frameList, bgColor, loopCount } = await decode(buf);
console.log(height);
console.log(width);
console.log(loopCount);
console.log(frameList.length);
console.log("duration", frameList[0].duration);
console.log(bgColor);
const gifBuf = await encode({
width,
height,
frameList,
});
fs.writeFileSync("./t.gif", gifBuf);
}
main();