jpegtran optimize without changing filename jpegtran optimize without changing filename linux linux

jpegtran optimize without changing filename


how about:

jpegtran -copy none -optimize -outfile image.jpg image.jpg

I'm not a shell expert by any means, but I think that with your original command, as soon as it is executed, the redirect is set up which overwrites your image.jpg. Then when jpegtran tries to read it in it finds an empty file.


I use this script. Works flawlessly. I hope this helps.

https://gist.github.com/iimos/7424025

#! /bin/shEXTENSIONS="jpe?g"if [ -z "$1" ]; then    DIR="`pwd`"else    DIR="$1"fi# Optimize JPEG imagesfind "$DIR" -regextype posix-egrep -regex ".*\.($EXTENSIONS)\$" -type f | xargs -I{} jpegtran -optimize -progressive -outfile "{}.optimized" "{}"# Rename xxx.jpg.optimized -> xxx.jpgfind "$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/diroptimize-images.sh 


I did it in three lines:

jpegtran -optimize image.jpg > image.jpg-optcp image.jpg-opt image.jpgrm image.jpg-opt

Works well.

[edit:] This works only for one file at a time.