How to Convert and Compress Images in the Mac Terminal

My Mac takes crisp, detailed screenshots. These pngs can be >5 MB — much larger than the recommended image size <500 KB for the web. Ever since Adobe limited the options on their online image resizer, I’ve been looking for a new way to compress images for my websites. I don’t want to fuss with image editing software, and I’m wary of the online image compression tools with wait times and ads that look like phony submit buttons.

Then I remembered my old boot camp adage: do everything possible in the terminal. With a little googling, I learned about the sips library. sips is an image processing library that can convert, rotate, and scale images in the terminal. This library is preinstalled and has been included with MacOS since 2003.

The original image, a 6.6MB png

To preform a simple conversion, the script is simple:

Copy and paste this in xTerm for a basic reformat

Please note that the “ — out" flag begins with a double dash as such and is currently autoformatted by Medium as one character.

The -s flag sets the options for format and formatOptions . Since the goal is to get the image under 500KB while preserving visual quality, I am converting this image to a jpeg because it is a lossy compression format.

With this command, the image was reduced to 203 KB, but the quality isn’t up to par. The call to action button looks fuzzy around the edges.

A low quality jpeg, 203KB

Instead of using the low, medium, high formatOptions, I tried a percentage to resize the image next.

Copy and paste this in xTerm to reformat at 55% quality

The image is 333 KB, and the image is visibly more crisp.

A jpeg at 55% quality, 333KB

Edit: When this story was first published, it displayed the scripts above as plain text, which auto-formatted the double dash to the double dash character. This has been fixed in the embedded gists.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rachel Reilly

Software Engineer specializing in React but passionate about the future of digital interaction beyond visual user interfaces