Last active
May 30, 2018 22:09
-
-
Save egladman/2e067b373bc49da180f666128ff3d5e5 to your computer and use it in GitHub Desktop.
Extract all frames of a gif to their respective images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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