Optimize images from a Node.js script
New Course Coming Soon:
Get Really Good at Git
One tool I’ve been using to optimize images is sharp.
import sharp from 'sharp'
Here’s how I used it to convert images to webp:
await sharp('image.png')
.webp({ lossless: true })
.toFile('image.webp')
It can do a lot more image processing stuff like rotate resize etc.
→ Get my Node.js Handbook
→ Read my
Node.js Tutorial
on The Valley of Code
Here is how can I help you:
- COURSES where I teach everything I know
- CODING BOOTCAMP cohort course - next edition in 2025
- BOOKS 16 coding ebooks you can download for free on JS Python C PHP and lots more
- Follow me on X