Created
July 24, 2020 14:32
-
-
Save aanndryyyy/39bdee3271d23a272c73969ac7a91f0a to your computer and use it in GitHub Desktop.
WebP Generator
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 | |
# Remove orphan webp images. | |
FILES=$(find . -type f -regextype posix-extended \ | |
-regex "^\./(uploads)/.*\.(webp)$" \ | |
-not -regex ".*\/(\.|scraper|temp).*") | |
for file in $FILES; do | |
#echo "Processing $file:" | |
if [ -f "${file%.*}.jpg" ] || [ -f "${file%.*}.png" ]; then | |
continue | |
fi | |
echo "Found orphan $file. Deleting..." | |
rm -f "$file" | |
done | |
# Generate webp files. | |
FILES=$(find . -type f -regextype posix-extended \ | |
-regex "^\./(uploads)/.*\.(png|jpg)$" \ | |
-not -regex ".*\/(\.|scraper|temp).*") | |
for file in $FILES; do | |
#echo "Processing $file:" | |
cwebp -q 80 "$file" -o "${file%.*}.webp" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment