silver imac displaying collage photos

How to batch convert images to WebP with Imagemagick

What is WebP?

webp logo image

WebP is a modern image format developed by google, that provides superior lossless and lossy compression for images on the web. Using WebP, webmasters and web developers can create smaller, richer images that make the web faster. WebP lossless images are 26% smaller in size compared to PNGs.

What is ImageMagick?

imagemagick

ImageMagick® is a free, open-source software suite, used for editing and manipulating digital images. It can be used to create, edit, compose, or convert bitmap images, and supports a wide range of file formats, including JPEG, PNG, GIF, TIFF, and PDF.

pagespeed insight

How to convert your files?

  1. Install the application:

If you already have imagemagick installed on your device you can ignore the following steps.

On Mac

brew install imagemagick

On Linux & Windows visit https://imagemagick.org/script/download.php

2. Create an empty directory:

mkdir ~convert/webp

3. Navigate to the folder of png or jpg images you want to convert to WebP in your terminal.

cd ~/yourImages/

4. Issue the following command replacing “.jpg” with the file extension of the files you need converted (the source files).

magick mogrify -format webP -path ~/Pictures/WebP/ *.jpg

5. To change the quality of your images using lossless compression, you can use the “-quality” and “-define” arguements like so…

magick mogrify -format webP -quality 80 -define webp:lossless=true -path ~/Pictures/WebP/ *.jpg

6. Wait for the images to be converted. Your newly converted images can be found in your ~/Pictures/WebP folder after its complete.

Considering the great effect on loading times, virtually any site or social media can benefit from WebP format. As we mentioned in the WebP pros and cons, the one glaring red flag is that not all browsers use it—be sure to double-check with your usage analytics to see which browsers your visitors prefer and whether switching to WebP will affect them.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.