Skip to content

Instantly share code, notes, and snippets.

@fongreecss
Created August 4, 2017 10:03
Show Gist options
  • Save fongreecss/10e551c5f25c18023e6c159882203904 to your computer and use it in GitHub Desktop.
Save fongreecss/10e551c5f25c18023e6c159882203904 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# sudo apt-get install jpegoptim
# sudo apt-get install optipng
#
IMGFOLDER=/path/to/image/folder
JPGLOG=/path/to/image/folder/jpegoptim.log
PNGLOG=/path/to/image/folder/pngoptim.log
JPGCOMPRESSION=75
echo `date` >> $PNGLOG
find $IMGFOLDER -mtime -2 -iname '*.png' -print0 | \
xargs -0 optipng -o7 -log $PNGLOG -preserve
echo `date` >> $JPGLOG
find $IMGFOLDER -mtime -2 -iname '*.jpg' -print0 | \
xargs -0 jpegoptim --max=$JPGCOMPRESSION --preserve --totals >> $JPGLOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment