Created
August 8, 2023 07:05
-
-
Save epreston/7c47122709f1ed1492bfbba6686e695a to your computer and use it in GitHub Desktop.
javascript - node tool - deeply compress images in a folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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