Skip to content

Instantly share code, notes, and snippets.

@MogulChris
Created October 19, 2020 22:40
Show Gist options
  • Save MogulChris/831df3327552d2af7499b6979209bf72 to your computer and use it in GitHub Desktop.
Save MogulChris/831df3327552d2af7499b6979209bf72 to your computer and use it in GitHub Desktop.
Recursively resize images in a directory tree with imagemagick / mogrify
#1. find files matching a pattern
#2. use mogrify to resize them.
# -quality 94 = jpeg quality.
# -verbose so you can tell where it's at in the directory tree
# -resize 2000x\> = resize to a maximum of 2000px wide, automatic height (2000x). Only resize larger images, no upscaling (>). Because > is a special character it is escaped with \
# Aspect ratio is automatically maintained.
#3. write new image in place
#TEST THIS THOROUGHLY AND KEEP A BACKUP OF YOUR ORIGINAL DIRECTORY TREE
find . -name "*.jpg" -exec mogrify -quality 94 -verbose -resize 2000x\> {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment