Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
jpegtran -copy none -progressive "$1" > "$1.bak"
echo "grand"
if [[ $filesize -lt `stat -f %z "$1.bak"` ]]; then
echo "compression plus lourde"
rm "$1.bak"
echo "good!"
mv "$1.bak" "$1"
find . -name '*.jpg' -type f -print0 |while read -d $'\0' i; do optimize "$i"; done

This comment has been minimized.

Copy link

@caiogondim caiogondim commented Nov 19, 2012

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