What are you trying to achieve?
I am trying to convert the full images folder (all images inside are jpg png) into webp is it possible with sharp?
That's a perfect use case for sharp.
Here's a quick demo how to do it:
const fs = require('fs')
const sharp = require('sharp')
const files = fs.readdirSync('/tmp/images')
const convert = (dir, name) => {
const fullname = dir + '/' + name
const i = sharp(fs.readFileSync(fullname));
i.toFormat('webp', { quality: 80 })
return i.toFile('/tmp/converted-images/' + name + '.webp')
.then(() => console.log('Converted', fullname))
.catch(e => console.log('Failed converting', fullname, e, 'skipping...'))
}
const promises = files.map(name => convert('/tmp/images/', name))
Promise.all(promises)
.then(() => console.log('Done'))
.catch(e => console.error(e));
Most helpful comment
That's a perfect use case for sharp.
Here's a quick demo how to do it: