Google has introduced webp format for images which is extremely compressed and size-reduced with respect ro jpg format. Sometimes it decreases the size of an image more than 40%.

To setup and convert your images you should follow these steps:

sudo apt-get install webp

go inside the directory where all images are there make sure all images are in RGB color mode, otherwise you will get error for CMYK images. Convert all images to RGB by this command (you should install ImageMagik to do that)

for f in *.jpg; do convert -colorspace RGB "$f" "${f}"; done

finally convert all images to Webp format

for f in *.jpg; do cwebp -q 90 "$f" -o "${f}".webp; done

Now you have filename.jpg.webp beside filename.jpg for all your images. You can set the nginx or other webservers to conditionally show webp instead of jpg if browser support Read this page to setup it in nginx config :

I have also create a gist here :

0 thoughts on “bash script: batch convert jpg to webp in ubuntu linux”

Leave a Reply

Your email address will not be published. Required fields are marked *