I have several directories of images that I have compressed using Imagemin. I would like to add my script to my build so when new images are added they are automatically compressed. How would I go about checking if an image is already compressed so it does not get compressed again? The script is written purely in JS as of now using mozjpg plugin and pngquant.
I would like this to be as much of an automated solution as possible without having to delete old images or create new directories manually.
const imagemin = require('imagemin');
const imageminMozjpeg = require('imagemin-mozjpeg');
const imageminPngquant = require('imagemin-pngquant');
var images = ["15 directories"];
var i;
for (i = 0; i < 14; i++) {
(async () => {
const files = await imagemin([images[i]], {
destination: images[i],
plugins: [
imageminMozjpeg({
quality: 70,
}),
]
});
console.log(files);
//=> [{data: <Buffer 89 50 4e …>, path: 'build/images/foo.jpg'}, …]
})();
(async () => {
const filesPNG = await imagemin([images[i]], {
destination: images[i],
plugins: [
imageminPngquant({ quality: [0.6, 0.7] })
]
});
console.log(filesPNG);
//=> [{data: <Buffer 89 50 4e …>, path: 'build/images/foo.jpg'}, …]
})();
}