Skip to content

Instantly share code, notes, and snippets.

@rik
Created July 14, 2011 22:28
Show Gist options
  • Save rik/1083622 to your computer and use it in GitHub Desktop.
Save rik/1083622 to your computer and use it in GitHub Desktop.
Run jpegtran on every image in a directory (and subdirectories)
#!/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
@caiogondim
Copy link

You just forgot the ending quote on line 9
And thanks so much for the script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment