I have a project where I need to bulk convert large amounts of .png files to .jpgs, with some control over compression quality. Using the node module sharp
works like a charm on individual files, e.g.:
const sharp = require("sharp");
sharp("input/82.png")
.toFormat("jpeg")
.jpeg({ quality: 70 })
.toFile("output/82.jpg");
But I have hundreds of files I need to convert at a shot. I had hoped to be able to use some wildcard for files, like:
sharp("input/*.png")
.toFormat("jpeg")
.jpeg({ quality: 70 })
.toFile("output/*.jpg");
though that of course doesn't work, nor has any attempt I've done to loop through all the files, or using the node module glob
. Appreciate any guidance that can be provided here.