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.
35 lines
735 B
35 lines
735 B
'use strict';
|
|
const execa = require('execa');
|
|
const gifsicle = require('gifsicle');
|
|
const isGif = require('is-gif');
|
|
|
|
module.exports = (options = {}) => async input => {
|
|
if (!Buffer.isBuffer(input)) {
|
|
throw new TypeError(`Expected \`input\` to be of type \`Buffer\` but received type \`${typeof input}\``);
|
|
}
|
|
|
|
if (!isGif(input)) {
|
|
return input;
|
|
}
|
|
|
|
const args = ['--no-warnings', '--no-app-extensions'];
|
|
|
|
if (options.interlaced) {
|
|
args.push('--interlace');
|
|
}
|
|
|
|
if (options.optimizationLevel) {
|
|
args.push(`--optimize=${options.optimizationLevel}`);
|
|
}
|
|
|
|
if (options.colors) {
|
|
args.push(`--colors=${options.colors}`);
|
|
}
|
|
|
|
const {stdout} = await execa(gifsicle, args, {
|
|
encoding: null,
|
|
input
|
|
});
|
|
|
|
return stdout;
|
|
};
|
|
|