forked from imagemin/imagemin-gifsicle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (29 loc) · 802 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
36
37
38
import {Buffer} from 'node:buffer';
import {execa} from 'execa';
import gifsicle from 'gifsicle';
import isGif from 'is-gif';
const main = (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,
maxBuffer: Number.POSITIVE_INFINITY,
input,
});
return stdout;
};
export default main;