Skip to content

Instantly share code, notes, and snippets.

@egladman
Last active May 30, 2018 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egladman/2e067b373bc49da180f666128ff3d5e5 to your computer and use it in GitHub Desktop.
Save egladman/2e067b373bc49da180f666128ff3d5e5 to your computer and use it in GitHub Desktop.
Extract all frames of a gif to their respective images
// Quick and dirty script that I'll only use once...
// Grabs all the frames in a gif and write them to individual files
//
// Example
// node extractFrames.js --gif path/to/gif
const gifFrames = require('gif-frames');
const argv = require('yargs').argv
const fs = require('fs');
gifFrames(
{ url: argv.gif, frames: 'all', outputType: 'png', cumulative: true },
function (err, frameData) {
if (err) {
throw err;
}
frameData.forEach(function (frame) {
frame.getImage().pipe(fs.createWriteStream(
`${basename(argv.gif)}-${frame.frameIndex}.png`
));
});
}
);
// Helper
function basename(path) {
return path.split('/').reverse()[0].split('.')[0];
}
{
"name": "extractframes",
"private": true,
"version": "0.0.1",
"description": "Extract all frames of a gif to their respective images",
"main": "extractFrames.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Eli Gladman",
"license": "MIT",
"dependencies": {
"gif-frames": "^0.4.0",
"yargs": "^11.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment