I need to optimize some images, but not change their name.
jpegtran -copy none -optimize image.jpg > image.jpg
However, this seems to crea
I use this script. Works flawlessly. I hope this helps.
https://gist.github.com/iimos/7424025
#! /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
find "$DIR" -name '*.optimized' -print0 | while read -d $'\0' file; do
chown $(stat -c "%U:%G" "${file%.optimized}") "$file"
chmod $(stat -c "%a" "${file%.optimized}") "$file"
mv -f "$file" "${file%.optimized}";
done
Usage 1:
optimize-images.sh /images/dir
Usage 2:
cd /images/dir
optimize-images.sh