0.2.0 • Published 3 years ago

ligif v0.2.0

Weekly downloads
69
License
MIT
Repository
-
Last release
3 years ago

LIGIF

支持直接在浏览器生成和解析GIF图片的工具库

参考资料

Demo

example

Installation

yarn add ligif

or

npm i -S ligif

Usage

生成GIF

import { GIFEncoder } from 'ligif';
const img1 = document.getElementById('img1');
const img2 = document.getElementById('img2');
const img3 = document.getElementById('img3');

const encoder = new GIFEncoder(img1.width, img1.height);
encoder.addFrame({ img: img1 });
encoder.addFrame({ img: img2 });
encoder.addFrame({ img: img3 });

encoder.encode().then(() => {
    const img = document.createElement('img');
    img.src = URL.createObjectURL(encoder.toBlob());
    document.body.appendChild(img);
});

解析GIF

import { GIFDecoder } from 'ligif';

document.getElementById('main').addEventListener('drop', function (e) {
    e.stopPropagation();
    e.preventDefault();

    const field = e.dataTransfer.files[0];
    const gif = new GIFDecoder();
    gif.readData(field).then(gif => {
       gif.frames.forEach(f => document.body.appendChild(f.renderToCanvas().canvas));
    });
});

TODO

  • 支持video转GIF
  • 支持控制循环次数
  • 支持有损压缩
  • 对比wasm性能差异

License

MIT

0.2.0

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.11

5 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago