4

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?

2 Answers 2

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 "\;".

5
  • 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, 2014 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, 2014 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, 2014 at 1:53
  • 1
    perfect to remove files: find "FOLDER_NAME" -type f -name '*_16.png' -exec rm {} \; Thanks!!!!!
    – Guilherme
    Feb 2, 2020 at 13:07
  • @Guilherme You can use -delete instead of -exec rm {} \; if you want just to remove files: find "FOLDER_NAME" -type f -name '*_16.png' -delete
    – denisvm
    Apr 17, 2020 at 13:37
2

I managed to change a small bash script which worked for me

#!/bin/bash

find "foldername" -type f | \
while read file ; do
    echo "processing ${file}"
    sips -Z 2000 ${file}
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .