Skip to content

Instantly share code, notes, and snippets.

@mkormendy
Forked from julianxhokaxhiu/pagespeed_optimize_images.sh
Last active September 22, 2020 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkormendy/bec8c87471df0d1a2eb9e95fd986d171 to your computer and use it in GitHub Desktop.
Save mkormendy/bec8c87471df0d1a2eb9e95fd986d171 to your computer and use it in GitHub Desktop.
Recursively optimize all PNG and JPG files from the location of the script.
#!/bin/bash
find /uploads/sites/*/20* -type f -iname "*.png" -exec pngquant --speed 1 --skip-if-larger --strip {} \;
find /uploads/sites/*/20* -type f -iname "*.png" -exec advpng -z4 {} \;
find /uploads/sites/*/20* -type f -iregex .*\.jpe?g$ -exec jpegoptim -f -s -v -m 50 {} \;
touch optimg.flag
# find's -newer command option compares the timestamps of files found against a defined file, in our case optimg.flag
# when we finish optimizing all of the images we touch the optimg.flag file to update its timestamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment