โ† flaviocopes.com

Optimize images from a Node.js script

Published Jan 20 2023

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.



Wanna go from noobie to expert?

I wrote an entire book on this topic ๐Ÿ‘‡

© 2023 Flavio Copes Flavio Copes using Notion to Site Notion to Site. Follow on Twitter

Solopreneur? Wannabe? Adventure awaits