baszczewski / webp-animation-generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create WebP animation from sample images. You can use image data or canvas directly.

Important notice: this library is optimised only for web usage at the moment.

import { AnimationGenerator } from '../dist/main.js';

const instance = new AnimationGenerator();

await instance.init('/dist/worker.js');

const file1 = await (await fetch('/file-01.webp').then(resp => resp.blob())).arrayBuffer();
const file2 = await (await fetch('/file-02.webp').then(resp => resp.blob())).arrayBuffer();

instance.addFrame(new Uint8Array(file1), { delay: 1000 });
instance.addFrame(new Uint8Array(file2), { delay: 1000 });

const result = await instance.generate();

const blob = new Blob([result.buffer], { type: 'image/webp' });
const img = document.createElement('img');
img.src = URL.createObjectURL(blob);
document.body.appendChild(img)

instance.release();

About


Languages

Language:TypeScript 76.9%Language:Shell 16.9%Language:JavaScript 6.2%