Skip to content

Instantly share code, notes, and snippets.

@colinrtwhite
Created February 2, 2018 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colinrtwhite/6b27e6bb648682535a98e45b7c966d30 to your computer and use it in GitHub Desktop.
Save colinrtwhite/6b27e6bb648682535a98e45b7c966d30 to your computer and use it in GitHub Desktop.
Shell scripts for recursively compressing files to PNG/WebP
#!/usr/bin/env sh
compress() {
while [ "$1" ]; do
if [ -d "$1" ]; then
compress "$1"/*
else
zopflipng -m -y $1 $1
fi
shift
done
}
compress *
#!/usr/bin/env sh
compress() {
while [ "$1" ]; do
if [ -d "$1" ]; then
compress "$1"/*
else
cwebp -af -mt -q 100 -lossless "$1" -o "${1%.*}.webp"
if [ "$1" != "${1%.*}.webp" ] && [ -f "${1%.*}.webp" ]; then
rm "$1"
fi
fi
shift
done
}
compress *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment