@canvacord/gif
GIF Encoder and Decoder for Canvacord.
Installation
$ npm install --save @canvacord/gif
// or
$ yarn add @canvacord/gif
Examples
Decoding GIF
import { Decoder } from '@canvacord/gif';
import { readFileSync, createWriteStream } from 'fs';
const { Decoder } = require('@canvacord/gif');
const { readFileSync, createWriteStream } = require('fs');
const source = readFileSync('./img.gif');
const decoder = new Decoder(source);
const rawFrames = decoder.decode();
console.log(rawFrames);
const pngFrames = decoder.toPNG(rawFrames);
for (let i = 0; i < pngFrames.length; i++) {
const frame = pngFrames[i];
frame.pipe(createWriteStream(`./frame_${i}.png`));
}
Encoding raw frame to GIF
import { Decoder, Encoder } from '@canvacord/gif';
import { readFileSync, createWriteStream } from 'fs';
const { Decoder, Encoder } = require('@canvacord/gif');
const { readFileSync, createWriteStream } = require('fs');
const source = readFileSync('./img.gif');
const decoder = new Decoder(source);
const rawFrames = decoder.decode();
for (let i = 0; i < rawFrames.length; i++) {
const frame = new Encoder(rawFrames[i]).encode();
frame.pipe(createWriteStream(`./frame_${i}.gif`));
}