Created
October 2, 2013 05:34
-
-
Save tmpvar/6789505 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env node | |
if (process.argv.length < 4) { | |
return console.log('usage: togif 25 path/to/files/*.jpg path/to/output.gif'); | |
} | |
// node expands *.jpg | |
var images = process.argv.slice(2); | |
var delay = images.shift(); | |
console.log('DELAY', delay); | |
var outfile = images.pop(); | |
var matcher = /([0-9]+)/g; | |
images = images.sort(function(a, b) { | |
var ai = parseInt(a.match(matcher).pop(), 10); | |
var bi = parseInt(b.match(matcher).pop(), 10); | |
return bi > ai ? -1 : 1; | |
}); | |
images = images.concat(images.concat().reverse().slice(1)); | |
var exec = require('child_process').exec; | |
var flags = ['-quality 100%'].join(' '); | |
var inlineFlags = ' ' + [ '-delay ' + delay, '-quality 100%', '-depth 32'].join(' ') + ' '; | |
var args = ['convert', flags, inlineFlags + images.join(inlineFlags), inlineFlags + '-crop 618x928+9+87! -resize 50%! ' + outfile].join(' '); | |
exec(args, function(err) { | |
if (err) throw err; | |
console.log('done! see:', outfile); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment