Skip to content

Instantly share code, notes, and snippets.

@stalmok
Forked from rik/jpegtran-directory.sh
Last active December 11, 2015 04:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stalmok/4546776 to your computer and use it in GitHub Desktop.
Save stalmok/4546776 to your computer and use it in GitHub Desktop.
Bash: Optimize .jpg images
#!/usr/bin/env bash
function optimize
{
echo $1
filesize=`stat --format=%s "$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 --format=%s "$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
@jameskraus
Copy link

Thanks for the fixed script!

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