Created
July 14, 2011 22:28
-
-
Save rik/1083622 to your computer and use it in GitHub Desktop.
Run jpegtran on every image in a directory (and subdirectories)
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
#!/usr/bin/env bash | |
function optimize | |
{ | |
echo $1 | |
filesize=`stat -f %z "$1"` | |
if [[ $filesize -lt 10000 ]]; then | |
jpegtran -copy none -optimize "$1" > "$1.bak" | |
echo "pet | |
else | |
jpegtran -copy none -progressive "$1" > "$1.bak" | |
echo "grand" | |
fi | |
if [[ $filesize -lt `stat -f %z "$1.bak"` ]]; then | |
echo "compression plus lourde" | |
rm "$1.bak" | |
else | |
echo "good!" | |
mv "$1.bak" "$1" | |
fi | |
} | |
find . -name '*.jpg' -type f -print0 |while read -d $'\0' i; do optimize "$i"; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You just forgot the ending quote on line 9
And thanks so much for the script