Batch process images using OS X SIPS (scriptable image processing system) to downsize images only?

StackOverflow https://stackoverflow.com/questions/14784358

Question

I'd like to batch process several folders of 1000's of images to downsize any images with a long side greater than 1440 pixels down to 1440 while ignoring any files that are already smaller than that.

I was looking at sips and can't tell if it skips upsizing by default or if there is a way to filter it using getProperty perhaps? (I'm not the best at deciphering CLI options from man pages).

I was thinking maybe I could use a find or sips query first and then pipe it into another sips to resize, I'm not sure exactly how though and don't think find can search by image size.

(also open to something other than sips to handle this, just seemed the quickest way)

Was it helpful?

Solution

Using spotlight to filter results to to images larger than a particular size works perfectly:

mdfind -0 -onlyin . "kMDItemPixelHeight > 1440 || kMDItemPixelWidth > 1440" | xargs -0 sips -Z 1440

This find images recursively from the current directory with width OR height greater than 1440 pixels and resizes them down to 1440. Files under 1440 get left alone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top