Terminal 101: Resize Images in the Terminal
Posted 11/19/2012 at 11:24am
| by Cory Bohon
Every Monday, we'll show you how to do something new and simple with Apple's built-in command line application. You don't need any fancy software, or a knowledge of coding to do any of these. All you need is a keyboard to type 'em out!
Sure, you could resize or otherwise manipulate your images using any number of image editing apps on the Mac, but did you know that you can do the same thing in the Terminal on your Mac? The sips (or scriptable image processing system) command makes this possible, and the best part is that it’s built into every Mac. Continue reading, and we’ll show you how to quickly resize through the command line.
Before we begin, it is important to note that sips will destructively alter your images. This means that once the image is altered, you cannot reverse its effects. Before resizing images, it is important to make a copy of important images.
1. Resize an Image (Ignoring Aspect Ratio)

Resizing an image by ignoring the aspect ratio lets you easily resize an image to fit a specific number of pixels in both the width and height directions. To do this, use the following command:
sips -z 768 1024 image.png
Replace “768” with the desired height of your image, “1024” with the desired width of your image, and “image.png” with the filename and extension of the image you’re resizing. Once run, the command will replace the original image specified with the resized image, sized to those pixel dimensions.
2. Resize an Image (Retaining Aspect Ratio)

Resizing by retaining the aspect ratio will keep the ratio of your image so that the end result doesn’t look “smushed” in one direction or the other. To do this, we’ll use the following the command:
sips -Z 480 image.png
Here, replace the lower-case “z” with an upper-case one to retain the aspect ratio, and only enter one pixel dimension in place of the “480.” You’ll want to enter the largest dimension that you wish the resulting image to be. So, if you had an image that was 1024x768, and wanted to crop it down to 500px wide, then you’d enter:
sips -Z 500 image.png
This would resize the largest dimension of the resulting image to 500 pixels (in this case) wide.
3. Batch Resizing Images in a Directory

If you have a folder of images to resize to one particular size, there’s no need to enter each one manually. Let the sips command work for you. Use the following command:
sips -Z 300 *.png
Using the “*.extension” wildcard, the command will automatically resize any images in the working folder with the provided extension. All of the images in the folder with that extension will get automatically resized to the dimensions provided (note that you can use either the aspect ignoring or retaining versions of the sips command here).
Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article's author on Twitter.