Last active
December 31, 2021 02:10
-
-
Save seansch/7c99c4f634deababa8e3a186a9d78cbc to your computer and use it in GitHub Desktop.
WebP Convert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Source: https://www.digitalocean.com/community/tutorials/how-to-create-and-serve-webp-images-to-speed-up-your-website#step-3-%E2%80%94-converting-jpeg-and-png-images-in-a-directory | |
# Usage ./webp-convert.sh /path/to/images | |
if [ $# -eq 0 ]; then | |
echo "Usage ./webp-convert.sh /path/to/images" | |
exit 1 | |
fi | |
# Convert JPEG images to WEBP | |
find "$1" -type f -and \( -iname "*.jpg" -o -iname "*.jpeg" \) \ | |
-exec bash -c ' | |
webp_path=$(sed 's/\.[^.]*$/.webp/' <<< "$0"); | |
if [ ! -f "$webp_path" ]; then | |
cwebp -quiet -q 90 "$0" -o "$webp_path"; | |
fi;' {} \; | |
# Convert PNG images to WEBP | |
find "$1" -type f -and -iname "*.png" \ | |
-exec bash -c ' | |
webp_path=$(sed 's/\.[^.]*$/.webp/' <<< "$0"); | |
if [ ! -f "$webp_path" ]; then | |
cwebp -quiet -lossless "$0" -o "$webp_path"; | |
fi;' {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment