Skip to content

Instantly share code, notes, and snippets.

@monnoval
Last active March 5, 2020 08:08
Show Gist options
  • Save monnoval/b149a7fa1ca603bf9a95d428dbbae98a to your computer and use it in GitHub Desktop.
Save monnoval/b149a7fa1ca603bf9a95d428dbbae98a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
find . -type f \( -name "*.jpg" -o -name "*.jpeg" \) -print0 | xargs -0 mogrify -density 72 -set colorspace Gray -separate -average -strip -interlace Plane -gaussian-blur 10 -quality 1%
find . -name "*.png" -print0 | xargs -0 mogrify -density 72 -colors 4
@monnoval
Copy link
Author

monnoval commented Mar 5, 2020

Setup

  1. Install via brew install imagemagick
  2. Create a file reduce-image-file-size.sh inside the folder where images reside (e.g. wordpress/wp-content/uploads)
  3. Run chmod +x reduce-image-file-size.sh
  4. Run ./reduce-image-file-size.sh

Notes

This script does use 100% of your CPU so be aware and careful when running this command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment