Preview, sips, and more: OS X image processing tools
On a recent trip, I found I had failed to add copies of my auto-resizing drop tools to my travel MacBook Air. My droplets allow me to convert images to TUAW-standard sizes, namely 225 pixels for small images and 456 pixels for banner images. (See? Information you never thought you'd need to know.)
What a lot of people don't realize is that OS X offers solutions for these kinds of basic image tasks.
First and foremost is Preview. This app is simply terrific. Yes, I know, Apple took some really helpful utilities like Link Annotation out of the app on its road to Mountain Lion. (Time? Feature trimming? It's hard to say.) Even so, Preview is the best app on your computer that nobody uses enough.
Preview offers a surprising tool suite that combines a little bit of Photoshop and a little bit of Acrobat into one app. In addition to annotating PDFs, you can rotate and crop images using Preview's Tools menu. You have access to lasso selection, color correction, and image fitting, among many other features.
At one point Steve Sande and I threw around the idea of writing an entire book on Preview (there's plenty of interesting material in there!) but ended up deciding against it. Unfortunately, demand leads sales and too few people know how powerful Preview can be.
To resize an image, choose Tools > Adjust Size or click the resizing icon you see at the top-right of this post's main image. The icon looks like an arrowed line in a square box. An Image Dimensions panel slides into view, as you see here.
Select the new width you want to use, making sure the small icon next to the two text fields remains in the locked position. This ensures that the height and width scale proportionately, so the resulting image is sized just right.
Preview isn't the only resizing solution on your Mac, however. The "sips" command line tool offers another take on image processing, one that's especially convenient for scripting and batch processing.
For example, if you want to resize an image to fit a given width, you can ask it to resample to the pixel count you supply. Here's how you might do that.
% sips --resampleWidth 225 input.png --o output.png
You can also perform many of the same tasks as preview. For example, you might rotate an image clockwise by 90 degrees:
% sips -r 90 input.png -o output.png
or convert a file from PNG to JPG format:
% sips -s format jpeg input.png -o output.jpg
OS X also supports related based on "folder actions". These refer to AppleScripts that you attach to folders, so when you drop items into the folders, they run those scripts. It's easy to take a peek at some of the system-supplied actions.
Create a new folder on your desktop. Control-click or Right-click it and choose Services > Folder Action Setup from the contextual pop-up menu. Select a pre-built script like "Duplicate as JPEG" or "Rotate Left" and click Attach. Finish by checking "Enable Folder Actions". Your new folder applies the attached script to any file you drop into it.
If you're an intrepid system-modding type, you can expand these script choices by adding items to ~/Library/Scripts/Folder Action Scripts. (The system supplied versions all appear in /Library/Scripts/Folder Action Scripts).
Scripts are built around a standalone Image Events application, found in /System/Library/CoreServices. This app provides a "faceless background application" that wraps sips for AppleScript scripting. Apple has documented Image Events as part of its developer library, and its docs point to this external website that details how you integrate scripting with image manipulation requests.
I'll leave the rest as an exercise for the reader, but a bit of Googling will turn up already-built image solutions ready for testing.
Here at TUAW, we regularly use these for image resizing -- and they're exactly the bits I forgot to pack on my trip.
So did I get my work done while gone? You bet I did. And a big part of that reason is how sips and Preview enable you to step up to image challenges without any third party software needed.
Got some OS X image processing tips? Share them in the comments.
Subscribe to Newsletter
Software Updatesmore updates
- NFL Mobile updated for 2014 Season with new Fantasy Football features, NFL Now integration
- Yahoo Mail improves email inbox searching with new filtering options
- Ember for Mac gains 'hugely-requested' screen recording feature
- Spotify update adds equalizer, refreshed Artist page and more
- Fantastical 2.1 for iOS adds new snooze, search and notification features
- ExpanDrive 4, more services and faster sync