Skip to main content

Automated web image optimization (via Cron)

Category: Linux
linux-logo

Instead of implementing image optimizing routines into your application, this could be achieved quite easily by using a cron.

By using find we can search for newly uploaded or generated images and apply an optimizer to the results.

0 2 * * 0 find /path/to/my/images/ -mtime -1 -iname *.jpg -exec jpegoptim --strip-all -p {} \; > /dev/null
0 3 * * 0 find /path/to/my/images/ -mtime -1 -iname *.png -exec optipng -o7 -preserve {} \; > /dev/null