A CLI tool that converts all valid images and GIFs in a directory (and all nested subdirectories) to WebP.
-
Download
webp.py
. -
Run
chmod a+x webp.py
. -
Create a soft link to the script using
sudo ln -s /path/to/downloads/webp.py /usr/bin/webp
. -
Install the appropriate libwebp precompiled utilities from Google.
The tool converts all valid images in a directory, and all nested subdirectories, to WebP and generates the output files for those images. Static images are converted using the cwebp
CLI utility. Animated GIFs are converted using the gif2webp
utility that comes with the download.
Syntax:
webp [options] path/to/images
For a list of options, please see Google's documentation for cwebp.
Example usage:
webp -q 80 ~/img/
This would convert all images under the ~/img/
directory, as well as all images in any nested subdirectories, to WebP.
Note: If you're using WSL on Windows, copy the directory from File Explorer and feed it to the built-in wslpath
utility:
webp [options] "$(wslpath "/path/to/images")"