0

I'm trying to resize all images in a directory and sub directories. I have this script which I got from here: Use mogrify to resize large files while ignoring small ones

and adjusted to:

identify -format '%w %h %i\n' ./*.jpg |
awk '$1 > 1200 || $2 > 1200 {sub(/^[^ ]* [^ ]* /, ""); print}' |
tr '\n' '\0' |
xargs -0 mogrify -resize '1200x1200'

but it only does the current directory and only .jpg extensions - ignores the upper case - .JPG

I've tried making adjustments but not making much progress.

3

You could combine identify with find, for example:

find . -type f -iname "*.jpg" -exec identify -format '%w %h %i\n' {} \;

which will run your identify command for every file recursively found with name ending in .jpg (case-insensitive).

Using your full example:

find . -type f -iname "*.jpg" -exec identify -format '%w %h %i\n' {} \; |
awk '$1 > 1200 || $2 > 1200 {sub(/^[^ ]* [^ ]* /, ""); print}' |
tr '\n' '\0' |
xargs -0 mogrify -resize '1200x1200'
  • Awesome - works perfectly! In second code block just update the file extension to .jpg – mmc501 Aug 15 '17 at 8:29
  • I have just tried this same script on another server but just get the error: find: `identify': No such file or directory – mmc501 Aug 15 '17 at 10:53
  • Is imagemagick installed? – sebasth Aug 15 '17 at 11:01
  • Yes it is installed Trying again and get loads of the above error message and this at the bottom: xargs: mogrify: No such file or directory – mmc501 Aug 15 '17 at 11:14
  • How do I do that? – mmc501 Aug 15 '17 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.