Skip to content

Instantly share code, notes, and snippets.

@actuallymentor
Created October 18, 2015 12:07
Show Gist options
  • Save actuallymentor/89b643f03df4776112c4 to your computer and use it in GitHub Desktop.
Save actuallymentor/89b643f03df4776112c4 to your computer and use it in GitHub Desktop.
Optimize images in a WordPress installation using Bash
# You need a recent version of jpegoptim and pngquant for this
yes | apt-get install jpegoptim
yes | apt-get install pngquant;
# Navigate to your wp-content/uploads
#optimize JPEG
optimizelossy() { jpegoptim -v *.jpg --max=80; for i in *; do if test -d $i; then cd $i; echo $i; optimizelossy; cd .. ; fi; done; echo; }
optimizelossy
# Optimize PNG
find . -name '*.png' -exec pngquant --quality=70-80 -f --force 256 {} \;
# Fix permissions
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment