Skip to content
This repository has been archived by the owner on May 28, 2020. It is now read-only.
/ gif.node Public archive

Full-featured GIF encoder that runs in node. Modified from jnordberg/gif.js which is a Javascript GIF encoder runs in browser.

Notifications You must be signed in to change notification settings

leoding86/gif.node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gif.node

Full-featured GIF encoder that runs in node. Based on jnordberg/gif.js which is a Javascript GIF encoder runs in browser.

Installation

Before install this module, you need to install node-canvas first.

After you installed node-canvas, then install this.

$ npm install gif.node

Testing

$ npm run test

Run Demo

$ npm run demo

Then a gif.gif file will be placed in the root directory.

Sample usage

const { loadImage, createCanvas } = require('canvas');
const GIF = require('gif.node');
const fs = require('fs');
const path = require('path');

const images = [
  path.join(__dirname, '../test/images/001.png'),
  path.join(__dirname, '../test/images/002.png'),
  path.join(__dirname, '../test/images/003.png'),
];

const gif = new GIF({
  worker: 2,
  quality: 10,
  debug: true
});

let canvas, cxt;

function addFrames(images, index) {
  return new Promise(resolve => {
    let i = index ? index : 0;

    if (!images[i]) {
      resolve();
    }

    loadImage(images[i]).then(image => {
      if (!canvas) {
        canvas = createCanvas(image.width, image.height);
        cxt = canvas.getContext('2d');
      }

      cxt.drawImage(image, 0, 0);

      gif.addFrame(cxt.getImageData(0, 0, canvas.width, canvas.height), {
        delay: 500 * (1 + i)
      });

      resolve(addFrames(images, ++i));
    });
  });
}

gif.on('finished', buffer => {
  fs.writeFileSync('gif.gif', buffer);
});

addFrames(images).then(() => {
  gif.render();
});

Options

Please see here

About

Full-featured GIF encoder that runs in node. Modified from jnordberg/gif.js which is a Javascript GIF encoder runs in browser.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published