first commit
This commit is contained in:
43
build/node_modules/imagemin-guetzli/index.js
generated
vendored
Normal file
43
build/node_modules/imagemin-guetzli/index.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
const execBuffer = require('exec-buffer');
|
||||
const isPng = require('is-png');
|
||||
const isJpg = require('is-jpg');
|
||||
const isInt = require('number-is-integer');
|
||||
const guetzli = require('guetzli');
|
||||
|
||||
module.exports = opts => buf => {
|
||||
opts = Object.assign({}, opts);
|
||||
|
||||
if (!Buffer.isBuffer(buf)) {
|
||||
return Promise.reject(new TypeError('Expected a buffer'));
|
||||
}
|
||||
|
||||
if (!isPng(buf) && !isJpg(buf)) {
|
||||
return Promise.resolve(buf);
|
||||
}
|
||||
|
||||
const args = [];
|
||||
|
||||
if (isInt(opts.quality) && opts.quality >= 0 && opts.quality <= 100) {
|
||||
args.push('--quality', opts.quality);
|
||||
}
|
||||
|
||||
if (isInt(opts.memlimit) && opts.memlimit > 0) {
|
||||
args.push('--memlimit', opts.memlimit);
|
||||
}
|
||||
|
||||
if (opts.nomemlimit) {
|
||||
args.push('--nomemlimit');
|
||||
}
|
||||
|
||||
args.push(execBuffer.input, execBuffer.output);
|
||||
|
||||
return execBuffer({
|
||||
input: buf,
|
||||
bin: guetzli,
|
||||
args
|
||||
}).catch(err => {
|
||||
err.message = err.stderr || err.message;
|
||||
throw err;
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user