schnee effeckt und fehler Korektur
This commit is contained in:
88
node_modules/imagemin-optipng/index.js
generated
vendored
88
node_modules/imagemin-optipng/index.js
generated
vendored
@@ -1,50 +1,62 @@
|
||||
'use strict';
|
||||
var ExecBuffer = require('exec-buffer');
|
||||
var isPng = require('is-png');
|
||||
var optipng = require('optipng-bin');
|
||||
var through = require('through2');
|
||||
const execBuffer = require('exec-buffer');
|
||||
const isPng = require('is-png');
|
||||
const optipng = require('optipng-bin');
|
||||
|
||||
module.exports = function (opts) {
|
||||
opts = opts || {};
|
||||
module.exports = options => async buffer => {
|
||||
options = {
|
||||
optimizationLevel: 3,
|
||||
bitDepthReduction: true,
|
||||
colorTypeReduction: true,
|
||||
paletteReduction: true,
|
||||
interlaced: false,
|
||||
errorRecovery: true,
|
||||
...options
|
||||
};
|
||||
|
||||
return through.ctor({objectMode: true}, function (file, enc, cb) {
|
||||
if (file.isNull()) {
|
||||
cb(null, file);
|
||||
return;
|
||||
}
|
||||
if (!Buffer.isBuffer(buffer)) {
|
||||
throw new TypeError('Expected a buffer');
|
||||
}
|
||||
|
||||
if (file.isStream()) {
|
||||
cb(new Error('Streaming is not supported'));
|
||||
return;
|
||||
}
|
||||
if (!isPng(buffer)) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
if (!isPng(file.contents)) {
|
||||
cb(null, file);
|
||||
return;
|
||||
}
|
||||
const arguments_ = [
|
||||
'-strip',
|
||||
'all',
|
||||
'-clobber',
|
||||
'-o',
|
||||
options.optimizationLevel,
|
||||
'-out',
|
||||
execBuffer.output
|
||||
];
|
||||
|
||||
var execBuffer = new ExecBuffer();
|
||||
var args = ['-strip', 'all', '-clobber', '-force', '-fix'];
|
||||
var optimizationLevel = opts.optimizationLevel || 2;
|
||||
if (options.errorRecovery) {
|
||||
arguments_.push('-fix');
|
||||
}
|
||||
|
||||
if (typeof optimizationLevel === 'number') {
|
||||
args.push('-o', optimizationLevel);
|
||||
}
|
||||
if (!options.bitDepthReduction) {
|
||||
arguments_.push('-nb');
|
||||
}
|
||||
|
||||
execBuffer
|
||||
.use(optipng, args.concat(['-out', execBuffer.dest(), execBuffer.src()]))
|
||||
.run(file.contents, function (err, buf) {
|
||||
if (err) {
|
||||
err.fileName = file.path;
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
if (typeof options.interlaced === 'boolean') {
|
||||
arguments_.push('-i', options.interlaced ? '1' : '0');
|
||||
}
|
||||
|
||||
if (buf.length < file.contents.length) {
|
||||
file.contents = buf;
|
||||
}
|
||||
if (!options.colorTypeReduction) {
|
||||
arguments_.push('-nc');
|
||||
}
|
||||
|
||||
cb(null, file);
|
||||
});
|
||||
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