Skip to content

Instantly share code, notes, and snippets.

@drakemccabe
Created May 3, 2016 17:09
Show Gist options
  • Save drakemccabe/2ca9f51a9a39b9d2c4ac3c8efd5da3c0 to your computer and use it in GitHub Desktop.
Save drakemccabe/2ca9f51a9a39b9d2c4ac3c8efd5da3c0 to your computer and use it in GitHub Desktop.
Find all files under a certain size or dimension and then resize
# Find files over 300kb and resize to 300kb
identify -format '%b %h %i\n' ./*.png |
awk '$1 > 300000 {sub(/^[^ ]* [^ ]* /, ""); print}' |
tr '\n' '\0' |
xargs -0 mogrify -define png:extent=300KB
# Find files over 600px width and resize to 600px while keeping ratio
identify -format '%w %h %i\n' ./*.png |
awk '$1 > 600 {sub(/^[^ ]* [^ ]* /, ""); print}' |
tr '\n' '\0' |
xargs -0 mogrify -resize '600'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment