Package Exports
- @canvacord/gif
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@canvacord/gif) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@canvacord/gif
GIF Encoder and Decoder for Canvacord.
Installation
$ npm install --save @canvacord/gif
// or
$ yarn add @canvacord/gif
Examples
Decoding GIF
// es6
import { Decoder } from '@canvacord/gif';
import { readFileSync, createWriteStream } from 'fs';
// cjs
const { Decoder } = require('@canvacord/gif');
const { readFileSync, createWriteStream } = require('fs');
const source = readFileSync('./img.gif');
const decoder = new Decoder(source);
const rawFrames = decoder.decode();
// log raw frames data
console.log(rawFrames);
// get png image of each frame
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
// es6
import { Decoder, Encoder } from '@canvacord/gif';
import { readFileSync, createWriteStream } from 'fs';
// cjs
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();
// encode each frames into gif
for (let i = 0; i < rawFrames.length; i++) {
const frame = new Encoder(rawFrames[i]).encode();
frame.pipe(createWriteStream(`./frame_${i}.gif`));
}