Skip to content

Instantly share code, notes, and snippets.

@epreston
Created August 8, 2023 07:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save epreston/7c47122709f1ed1492bfbba6686e695a to your computer and use it in GitHub Desktop.
javascript - node tool - deeply compress images in a folder
import imagemin from 'imagemin';
import imageminWebp from 'imagemin-webp';
import imageminPngquant from 'imagemin-pngquant';
const produceWebP = async () => {
const outputFolder = './images/webp';
await imagemin(['images/*.png'], {
destination: outputFolder,
plugins: [
imageminWebp ({
// lossless: true
strip: true
})
]
});
console.log('PNGs processed');
await imagemin(['images/*.{jpg,jpeg}'], {
destination: outputFolder,
plugins: [
imageminWebp ({
// quality: 65
strip: true
})
]
});
console.log('JPGs and JPEGs processed')
};
const producePNG = async () => {
const outputFolder = './images/png';
await imagemin(['images/*.png'], {
destination: outputFolder,
plugins: [
imageminPngquant ({
strip: true
})
]
});
console.log('PNGs processed');
await imagemin(['images/*.{jpg,jpeg}'], {
destination: outputFolder,
plugins: [
imageminPngquant ({
strip: true
})
]
});
console.log('JPGs and JPEGs processed')
};
produceWebP();
producePNG();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment