You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

41 lines
816 B

'use strict';
const execBuffer = require('exec-buffer');
const gifsicle = require('gifsicle');
const isGif = require('is-gif');
module.exports = opts => buf => {
opts = Object.assign({}, opts);
if (!Buffer.isBuffer(buf)) {
return Promise.reject(new TypeError('Expected a buffer'));
}
if (!isGif(buf)) {
return Promise.resolve(buf);
}
const args = ['--no-warnings', '--no-app-extensions'];
if (opts.interlaced) {
args.push('--interlace');
}
if (opts.optimizationLevel) {
args.push(`--optimize=${opts.optimizationLevel}`);
}
if (opts.colors) {
args.push(`--colors=${opts.colors}`);
}
args.push('--output', execBuffer.output, execBuffer.input);
return execBuffer({
input: buf,
bin: gifsicle,
args
}).catch(err => {
err.message = err.stderr || err.message;
throw err;
});
};