Skip to content

Instantly share code, notes, and snippets.

@kstefanini
Created February 20, 2018 15:24
Show Gist options
  • Save kstefanini/4aa6bdf6540152522996dc5611cc877c to your computer and use it in GitHub Desktop.
Save kstefanini/4aa6bdf6540152522996dc5611cc877c to your computer and use it in GitHub Desktop.
Crawl folders and resize images
width=1600
height=1200
for FILE in $(
find . -type f -exec file {} \; |
awk -F: '{if ($2 ~/image/) print $1}'
);
do
identify -format '%w %h %i\n' "$FILE" |
awk '$1 > $width || $2 > $height {sub(/^[^ ]* [^ ]* /, ""); print}' |
tr '\n' '\0' |
xargs -0 mogrify -resize "$width"x"$height" -quality 72
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment