Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.forEach(async (png) => {
const original = statSync(png).size;
// TinyPNG
const image = tinify.fromFile(png);
await image.toFile(png);
const optimized = statSync(png).size;
// AdvPNG
execSync(`advpng -l -4 ${png}`);
const recompressed = statSync(png).size
console.log(`${png} ${original} bytes -> TinyPNG ${optimized} bytes -> AdvPNG ${recompressed}`);
// stage optimized PNG for inclusion in commit
execSync(`git add ${png}`);
});
const task = file => {
const source = tinify.fromFile(file.fromFile);
source.toFile(file.toFile);
return source._url;
}
// 通过输入文件夹和输出文件夹,返回一个数组
var source = tinifypng.fromFile(input);
var copyrighted = source.preserve(enginepng.png.command[0]);
copyrighted.toFile(output);
}else if(enginepng.png.command.length === 2){
var source = tinifypng.fromFile(input);
var copyrighted = source.preserve(enginepng.png.command[0], enginepng.png.command[1]);
copyrighted.toFile(output);
}else if(enginepng.png.command.length === 3){
var source = tinifypng.fromFile(input);
var copyrighted = source.preserve(enginepng.png.command[0], enginepng.png.command[1], enginepng.png.command[2]);
copyrighted.toFile(output);
}
}else{
tinifypng.fromFile(input).toFile(output);
}
}
}else{
console.log(colors.red("Don't [png] find ["+enginepng.png.engine+"] engine!"));
}
}
//- - - - - - - - - - - - - - - - - - - - - - - -
});
});
});
//-------------------------------------------------
}else{
var array;
if(false != enginejpg.jpg.command){
if(enginejpg.jpg.command.length === 1){
var source = tinifyjpeg.fromFile(input);
var copyrighted = source.preserve(enginejpg.jpg.command[0]);
copyrighted.toFile(output);
}else if(enginejpg.jpg.command.length === 2){
var source = tinifyjpeg.fromFile(input);
var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1]);
copyrighted.toFile(output);
}else if(enginejpg.jpg.command.length === 3){
var source = tinifyjpeg.fromFile(input);
var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1], enginejpg.jpg.command[2]);
copyrighted.toFile(output);
}
}else{
tinifyjpeg.fromFile(input).toFile(output);
}
}
}else{
console.log(colors.red("Don't [jpg] find ["+enginejpg.jpg.engine+"] engine!"));
}
}
var source = tinifypng.fromFile(input);
var copyrighted = source.preserve(enginepng.png.command[0]);
copyrighted.toFile(output);
}else if(enginepng.png.command.length === 2){
var source = tinifypng.fromFile(input);
var copyrighted = source.preserve(enginepng.png.command[0], enginepng.png.command[1]);
copyrighted.toFile(output);
}else if(enginepng.png.command.length === 3){
var source = tinifypng.fromFile(input);
var copyrighted = source.preserve(enginepng.png.command[0], enginepng.png.command[1], enginepng.png.command[2]);
copyrighted.toFile(output);
}
}else{
tinifypng.fromFile(input).toFile(output);
}
}
}else{
console.log(colors.red("Don't [png] find ["+enginepng.png.engine+"] engine!"));
}
}
var source = tinifyjpeg.fromFile(input);
var copyrighted = source.preserve(enginejpg.jpg.command[0]);
copyrighted.toFile(output);
}else if(enginejpg.jpg.command.length === 2){
var source = tinifyjpeg.fromFile(input);
var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1]);
copyrighted.toFile(output);
}else if(enginejpg.jpg.command.length === 3){
var source = tinifyjpeg.fromFile(input);
var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1], enginejpg.jpg.command[2]);
copyrighted.toFile(output);
}
}else{
tinifyjpeg.fromFile(input).toFile(output);
}
}
}else{
console.log(colors.red("Don't [jpg] find ["+enginejpg.jpg.engine+"] engine!"));
}
}
}else{
return callback(0, 0, 0, err);
}
});
//-------------------------------------------------
}else{
var array;
if(false != enginejpg.jpg.command){
if(enginejpg.jpg.command.length === 1){
var source = tinifyjpeg.fromFile(input);
var copyrighted = source.preserve(enginejpg.jpg.command[0]);
copyrighted.toFile(output);
}else if(enginejpg.jpg.command.length === 2){
var source = tinifyjpeg.fromFile(input);
var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1]);
copyrighted.toFile(output);
}else if(enginejpg.jpg.command.length === 3){
var source = tinifyjpeg.fromFile(input);
var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1], enginejpg.jpg.command[2]);
copyrighted.toFile(output);
}
}else{
tinifyjpeg.fromFile(input).toFile(output);
}
}
}else{
console.log(colors.red("Don't [jpg] find ["+enginejpg.jpg.engine+"] engine!"));
.then(function(msg) {
console.log(colors.green(msg))
for (let index in images) {
const image = images[index]
console.log(colors.blue("compressing: " + image))
tinify.fromFile(image).toFile(image, function(err, data) {
if (err) {
reject(new TinyPngError(err))
} else {
console.log(colors.green("compressed: " + image))
compressedCount++
if (compressedCount == images.length) {
console.log(colors.green("finish tinyPng compression."))
resolve(images)
}
}
})
}
})
.catch(function(err) {
return callback(size_in, size_output, percent, null);
//- - - - - - - - - - - - - - - - - - - - - - - -
});
});
//--------------------------------------
}else{
return callback(0, 0, 0, err);
}
});
//-------------------------------------------------
}else{
var array;
if(false != enginejpg.jpg.command){
if(enginejpg.jpg.command.length === 1){
var source = tinifyjpeg.fromFile(input);
var copyrighted = source.preserve(enginejpg.jpg.command[0]);
copyrighted.toFile(output);
}else if(enginejpg.jpg.command.length === 2){
var source = tinifyjpeg.fromFile(input);
var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1]);
copyrighted.toFile(output);
}else if(enginejpg.jpg.command.length === 3){
var source = tinifyjpeg.fromFile(input);
var copyrighted = source.preserve(enginejpg.jpg.command[0], enginejpg.jpg.command[1], enginejpg.jpg.command[2]);
copyrighted.toFile(output);
}
}else{
tinifyjpeg.fromFile(input).toFile(output);
}