How to convert JPGs to WebP automatically

The easiest way to convert a ton of JPGs to WebP is to use the cwebp command line utility written by the WebP team. Here’s how I do it using a very simple Bash script:

for f in `find ./source/uploads -name *.jpg` ; do
	dir=$(dirname "$f")
    filename=$(basename -- "$f")
    cwebp -q 90 $f -o $dir/$filename.webp;

This goes through all JPG files in ./source/uploads folder, converts them with a 90% quality rate and writes the output to the same origin.

Leave a Reply

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