Skip to content

Instantly share code, notes, and snippets.

@aanndryyyy
Created July 24, 2020 14:32
Show Gist options
  • Save aanndryyyy/39bdee3271d23a272c73969ac7a91f0a to your computer and use it in GitHub Desktop.
Save aanndryyyy/39bdee3271d23a272c73969ac7a91f0a to your computer and use it in GitHub Desktop.
WebP Generator
#!/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