Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@jameskraus jameskraus commented Mar 16, 2014

Thanks for the fixed script!

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