Resizing images from the command line

February 18, 2019

One of the most common tasks we need to do is resize images for non-photographic, non-critical usage.

i.e. when working with high-quality photographs to be printed or viewed at full resolution in a portfolio or sent to a client of course we’re going to be spending a significant amount of energy tweaking crops in Lightroom, unsharp masking in photoshop (or even breaking out Sharpnr Pro etc.) and sweating every detail that goes into producing carefully considered resized images.

I’d say that this probaby comprises no more than 2% of all the images we ever need to resize.

The other 98% of the time? Quick and dirty resizing of a bunch of random photos that have been dragged to the desktop in order to stick in a blog, toss into an iMessage or jam into a presentation deck 5 minutes before walking on stage.

It goes without saying that it sucks to have to endure firing up the terribly slow and bloated Photoshop (or really any image editing program) just to do that.1

Usually this is so painful that we just don’t and instead drag and drop the full-sized images directly into the presentation or iMessage or whatever - and in this day and age of unneccessarily-high megapixel count smartphones and cameras the end result is predictably sad - needlessly and massively bloated presentations file, 10GB iMessage archives decimating your Phone storage and 4GB Day One archives that take ages to sync.

It’s the little frictions that cause us so much pain down the road…

Well, no longer - turns out you can resize directly from the command line. In whatever directory your images are in:

$ sips -Z 1000 *.jpg

-Z preserves the aspect ratio and substitute 1000 for whatever the max dimension is you’d like to keep (so vertical for portrait, and horizontal for landscapes)

To change the image quality of the output file:

sips -s format jpeg -s formatOptions 80 *.jpg

I can’t believe we’ve lived so many years without knowing about this.2

  1. If you want to resize a bunch of images in Photoshop whilst preserving aspect ratio, don’t go through the hassle of creating a custom action, just use the built in image processor: File » Scripts » Image Processor. If you click Resize to Fit and enter the same dimension for both fields, it will preserve the aspect ratio, resizing whichever dimension is the longest to fit the specified values. This gives you a lot more options for naming/image quality etc. so is more appropriate when many details need to be specified but for the 99% of the time you just need to squish down a bunch of things ASAP, the terminal is a far better choice. 

  2. Tip of the hat to (where else) Stack Overflow 

Keep Reading

Related Posts

⤒ Back to top

Permalink