@nodedk/optimize
optimize#
Create WebP copies of images in a directory and its subdirectories.
Usage#
npx @nodedk/optimize ./app/assets/img
Converts .jpg, .jpeg, .png, and .tiff files at quality 85. Each WebP
file is written beside its source. Existing WebP files are skipped and source
images are kept.
JavaScript API#
npm i @nodedk/optimize
var { runOptimization } = require('@nodedk/optimize')
async function main() {
var result = await runOptimization('./app/assets/img')
console.log(result.count, result.saved)
}
main().catch(console.error)
runOptimization(targetPath) accepts a directory path and returns a Promise
of { count, saved }: the number of converted images and bytes saved.
Savings count only positive reductions in file size. Conversion errors skip
individual files; a missing directory rejects the Promise. Run calls
sequentially because they share the statistics object.
Created by Vidar Eldøy