3

I have a folder containing many subfolders full of images. See attached image for example.

alt

Basically I want to loop through them all and downsize the images so none are wider than 1024 pixels. They're all jpegs.

I'm aware of the SIPS commands i.e.

sips -Z 1024 *.png

However, that only works if all images are in the current directory.

How do I set it up to traverse through all subdirectories?

8

You can run it with find: find images/path -type f -name '*.png' -exec sips -Z 1024 {} \;

Find will search for files (-type f), with png extension (-name '*.png') inside 'images/path' directory and exec the command in parameter, replacing "{}" with the filename, you need to end the command with "\;".

  • Thanks. I had some issue with that not actually resizing all but did the same with imagemagick: find /images/path -type f -iname "*.jpg" -execdir convert {} -resize 1024x1024\> -quality 70 {} \; – Quadrant6 Jul 21 '14 at 23:58
  • Thanks, I'm trying the sips command again, it runs through as if it's doing something but doesn't seem to actually save the new file..? find images/path -type f -name "*.jpg" -exec sips -Z 1024 -s format jpeg -s formatOptions 80 {} \; – Quadrant6 Jul 22 '14 at 1:51
  • @Quadrant6 check if it's not saving the file in current directory, also test the sips command alone in the same path but specifying the full pathname for a test image file. – denisvm Jul 22 '14 at 1:53

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.