Last active
August 29, 2015 14:10
-
-
Save taji-taji/a25ef1f9d306993338f3 to your computer and use it in GitHub Desktop.
jpegtran whole directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
EXTENSIONS="jpe?g" | |
if [ -z "$1" ]; then | |
DIR="`pwd`" | |
else | |
DIR="$1" | |
fi | |
# Optimize JPEG images | |
find $DIR -regextype posix-egrep -regex ".*\.($EXTENSIONS)\$" -type f | xargs -I{} jpegtran -optimize -progressive -outfile "{}.optimized" "{}" | |
# Rename xxx.jpg.optimized -> xxx.jpg | |
for file in $(find $DIR -name '*.optimized'); do | |
chown $(stat -c "%U:%G" "${file%.optimized}") "$file" | |
chmod $(stat -c "%a" "${file%.optimized}") "$file" | |
mv -f "$file" "${file%.optimized}"; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/5579183/jpegtran-optimize-without-changing-filename