Last active
November 9, 2023 14:03
-
-
Save pocc/908b3ecec33ae687372d8a25f8eca43c to your computer and use it in GitHub Desktop.
Convert all png images to webp recursively
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
#!/usr/bin/env bash | |
# This script will get a list of all jpg and png files recursively | |
# and convert them all in place to webp files. | |
# cwebp options for max compression: `-m 6 -q 100 -z 9` | |
shopt -s globstar | |
for image in $PWD/**/*.png; do | |
echo "File is $image" | |
outfile=${image::-4}.webp | |
echo "outfile is $outfile" | |
cwebp "$image" -lossless -m 6 -q 100 -z 9 -o "$outfile" | |
echo "Deleting $image" | |
rm "$image" | |
done | |
# Recursively replace all instances of .png with .webp. This is dumb regex, so it may break things. | |
for file in $(find content layouts -type f); do | |
sed -E -i '' "s/\.png/\.webp/g" $file | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment