forked from imagemin/imagemin-gifsicle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (27 loc) · 735 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'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;
};