Skip to content

Instantly share code, notes, and snippets.

@andykillen
Created December 16, 2016 19:33
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 andykillen/df5e2a63323104e32ee07c2ec08ff459 to your computer and use it in GitHub Desktop.
Save andykillen/df5e2a63323104e32ee07c2ec08ff459 to your computer and use it in GitHub Desktop.
Run this script in the wp-content/uploads directory, first making sure you have installed jpegoptim and pngcrush. change 1920> to 3.840> if you worry about @2x retina images
#!/bin/bash
for f in $(find . -name '*.jpg' -or -name '*.JPG' -or -name '*.JPEG' -or -name '*.jpeg' -or -name '*.png'); do
convert "$f" -resize "1920>" "$f";
filename=$(basename "$f")
extension="${filename##*.}"
echo $extension;
if [ $extension = "png" ]; then
#echo "is a PNG";
pngcrush -ow -rem alla -reduce "$f";
else
convert "$f" -quality 70 "$f";
jpegoptim "$f";
fi
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment