Created
March 1, 2024 11:53
-
-
Save perguth/afba21fff5d8cf636a91b5f1094cf1e5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# Convert all JPGs and PNGs in a directory and its | |
# subdirectories into WEBP images. | |
# converting JPEG images | |
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;' {} \; | |
# converting PNG images | |
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