Skip to content

Instantly share code, notes, and snippets.

@StephenPunwasi
Forked from rik/jpegtran-directory.sh
Created August 11, 2013 14:19
Show Gist options
  • Save StephenPunwasi/6205090 to your computer and use it in GitHub Desktop.
Save StephenPunwasi/6205090 to your computer and use it in GitHub Desktop.
#!/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