When working on a site, I often find myself needing to resize and crop a bunch of images at once to consistent dimensions. If I have the luxury of working with uploaded images in Drupal, then image styles (née ImageCache) comes to the rescue. But if I'm just preparing static images for some other purpose, I've historically had to work through them with Photoshop, which is a slow process.
Recently I've been experimenting with Automator for these kinds of tasks. Apple introduced Automator back in Tiger, and it doesn't really seem to have caught the minds of the public as they hoped. However, it is quite a competent little tool for tasks like this one. Automator takes the idea of scripting repetitive tasks, and transforms it from something requiring a programming language into a simple GUI.
When Automator is launched, it prompts us for what kind of project we are making:
Since we are going to create and run a disposable workflow, our choice here doesn't really matter. The default "Workflow" choice is fine for us; other choices would allow our completed workflow to run as an application or when images are dropped into a folder, which is nice if the workflow is applicable to many projects.
Workflow Actions
Next, we build the workflow. Automator ships with a bunch of actions in the left column, which we can drag and drop onto the right panel. When working with simple images, all of the relevant actions are in the "Files & Folders" and "Photos" categories. We need to load in the images, save copies in a new folder, and then scale them to fit our needs.
The steps in our workflow are as follows:
Get Selected Finder Items
This action will take whatever is currently selected in the Finder, and allow us to act on it in Automator.
Input: Nothing
Output: The image files
New Folder
This action creates a new folder for our finished product, so the scaled images aren't just dropped in a heap somewhere. Whatever is passed as an input to this action is copied into the newly-created folder, so after this runs we have a brand-new copy of our images.
Input: The image files
Output: The new output folder
Get Folder Contents
We need to work with the images, but the folder is now the active item. We could use Automator variables to handle this, but it's easier in this instance to run the Get Folder Contents action, which will look inside our new folder and grab the files within to work with.
Input: The output folder
Output: The copied image files
Crop Images
Finally, it's time to actually manipulate the images. Automator offers a few options for different situations. The Crop Images action is similar to Drupal's "scale and crop" image style action. We specify the width and height of the final image, and automator will first scale the image, then crop it to these dimensions. Note that Automator is not as smart as Drupal with respect to scaling, and we need to tell it which side of the image to scale to. If we make the incorrect choice here, then our resulting images will have black bars along the sides and we have to try again.
Input: The copied image files
Output: The same files, after they have been transformed
Activating the Workflow
That's all it takes to create the workflow! To actually run it, we just select the original images in the Finder, then click the Run button in Automator. It chugs for a few seconds, then produces a folder filled with the resulting images. Done!
Need a fresh perspective on a tough project?
Let’s talk about how RDG can help.