ubdate
This commit is contained in:
57
node_modules/imagemin-optipng/index.js
generated
vendored
Normal file
57
node_modules/imagemin-optipng/index.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
const execBuffer = require('exec-buffer');
|
||||
const isPng = require('is-png');
|
||||
const optipng = require('optipng-bin');
|
||||
|
||||
module.exports = options => async buffer => {
|
||||
options = {
|
||||
optimizationLevel: 3,
|
||||
bitDepthReduction: true,
|
||||
colorTypeReduction: true,
|
||||
paletteReduction: true,
|
||||
errorRecovery: true,
|
||||
...options
|
||||
};
|
||||
|
||||
if (!Buffer.isBuffer(buffer)) {
|
||||
throw new TypeError('Expected a buffer');
|
||||
}
|
||||
|
||||
if (!isPng(buffer)) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
const arguments_ = [
|
||||
'-strip',
|
||||
'all',
|
||||
'-clobber',
|
||||
'-o',
|
||||
options.optimizationLevel,
|
||||
'-out',
|
||||
execBuffer.output
|
||||
];
|
||||
|
||||
if (options.errorRecovery) {
|
||||
arguments_.push('-fix');
|
||||
}
|
||||
|
||||
if (!options.bitDepthReduction) {
|
||||
arguments_.push('-nb');
|
||||
}
|
||||
|
||||
if (!options.colorTypeReduction) {
|
||||
arguments_.push('-nc');
|
||||
}
|
||||
|
||||
if (!options.paletteReduction) {
|
||||
arguments_.push('-np');
|
||||
}
|
||||
|
||||
arguments_.push(execBuffer.input);
|
||||
|
||||
return execBuffer({
|
||||
input: buffer,
|
||||
bin: optipng,
|
||||
args: arguments_
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user