Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,28 @@ var debug = require('debug')('gify');
var mkdirp = require('mkdirp');
var uid = require('uid2');
var path = require('path');
const tempDirectory = require('temp-dir');

/**
* Expose `gify()`.
*/

module.exports = gify;
module.exports = {
gify,
setFFMPEGPath,
setGMPath
};

let ffmpegPath = 'ffmpeg';
let gmPath = 'gm';

function setFFMPEGPath(path) {
ffmpegPath = path;
}

function setGMPath(path) {
gmPath = path;
}

/**
* Convert `input` file to `output` gif with the given `opts`:
Expand Down Expand Up @@ -62,8 +78,9 @@ function gify(input, output, opts, fn) {

// tmpfile(s)
var id = uid(10);
var dir = path.resolve('/tmp/' + id);
var tmp = path.join(dir, '/%04d.png');
const dir = path.join(path.join(tempDirectory, 'gify'), id);
console.log("Gify Temp Directory", dir);
var tmp = path.join(dir, '%04d.png');

// escape paths
input = escape([input]);
Expand All @@ -83,9 +100,9 @@ function gify(input, output, opts, fn) {
debug('mkdir -p %s', dir);
mkdirp(dir, function(err){
if (err) return fn(err);

// convert to gif
var cmd = ['ffmpeg'];
var cmd = [ffmpegPath];
cmd.push('-i', input);
cmd.push('-filter:v', 'scale=' + scale);
cmd.push('-r', String(rate));
Expand All @@ -100,7 +117,7 @@ function gify(input, output, opts, fn) {
var cmd;
var wildcard = path.join(dir, '/*.png');

cmd = ['gm', 'convert'];
cmd = [gmPath, 'convert'];
cmd.push('-delay', String(delay || 0));
cmd.push('-loop', '0');
cmd.push(wildcard);
Expand All @@ -111,4 +128,4 @@ function gify(input, output, opts, fn) {
exec(cmd, gc);
});
});
}
}
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
"jbnicolai <joshua@jbna.nl>"
],
"dependencies": {
"shell-escape": "0.0.0",
"child_process": "^1.0.2",
"commander": "~2.0.0",
"debug": "*",
"uid2": "0.0.3",
"mkdirp": "~0.3.5",
"commander": "~2.0.0"
"os": "^0.1.1",
"path": "^0.12.7",
"shell-escape": "0.0.0",
"temp-dir": "^2.0.0",
"uid2": "0.0.3"
},
"devDependencies": {
"mocha": "*",
Expand Down
Loading