Advanced usage of jpegoptim

507 Views Asked by At

I am currently running the below jpegoptim command via cron to have jpegoptim look for jpg files to compress.

find /home/public_html/public/uploads -name '*.jpg' -type f -print0 | xargs -0 jpegoptim -o -p --size=300k --strip-all

This works, but is there a way to include .jpeg, .JPG, and .JPEG without having to run the same command multiple times? Also, is it okay to run every hour, or would this keep compressing the same files eventually reducing the quality?

1

There are 1 best solutions below

1
On BEST ANSWER

You can match all of *.jpg, *.JPG, *.jpeg, *.JPEG by using two case-insensitive name matches.

find /home/public_html/public/uploads \
    '(' -iname '*.jpg' -o -iname '*.jpeg' ')' -type f -print0 \
| xargs -0 jpegoptim -o -p --size=300k --strip-all

You can keep a separate timestamp to avoid reprocessing the same files, for example

find /home/public_html/public/uploads \
    -newer .STAMP '(' -iname '*.jpg' -o -iname '*.jpeg' ')' -type f -print0 \
| xargs -0 jpegoptim -o -p --size=300k --strip-all
touch .STAMP