Resizing Multiple Images from the Terminal in OS X

Until I decide to spend the time hacking together a Folder Action to accomplish the same thing, here’s a one-line solution for quickly resizing a bunch of images.

Prerequisites

  • ImageMagick – I think there are a number of OS X ImageMagick binaries floating around out there, but probably the easiest way to get it is to install the Fink imagemagick package. (If you don’t have Fink, you should get it!) This solution makes use of the convert utility, and assumes it is somewhere in your path.
  • Terminal – You should have a passing familiarity with the Terminal application, which you’ll find under Applications/Utilities. See this Apple PDF for a gentle introduction.

Resizing the Images

Open up a terminal window, and cd to the directory your images are in; for instance, if they’re in a folder on your desktop called resizethese you would type:

cd ~/Desktop/resizethese

IMPORTANT: Make sure you’re doing this with copies of your original images, as this next step will affect the files permanently; it does not make new, resized copies in another folder somewhere, it operates on the files directly. If you run this on your original, 3 megapixel photos they will be irrevocably downsized. There is no undo in the Terminal!

Say you want to resize these images for use on the web, with a maximum 475 pixels for both width and height. Use the find command with the -exec option to invoke convert on all of the JPEGs in the current directory (If you have a directory full of some other file type, substitute its extension for *.jpg; ImageMagick can handle most common formats:

find . -iname "*.jpg" -exec convert -resize 475x475 {} {} ;

Depending on how many images you’re resizing and how large they are, your computer may chug away for a few seconds. When it returns you to the prompt, your images have been resized. To go straight to the current directory in a Finder window, type:

open .

If you’re a bit squeamish about the whole instantaneous, irrevocable resizing of the images in the current directory thing, you can use the -ok option instead:

find . -iname "*.jpg" -ok convert -resize 475x475 {} {} ;

This will prompt you to respond y or n before executing convert on each image.

Room for improvement

Is this the best way to resize a bunch of images in one fell swoop? People who live, breathe and eat Photoshop/ImageReady probably wouldn’t say so, and people who know AppleScript and Panther’s Image Events are probably snickering at my use of a third-party tool like ImageMagick, but OS X is an interesting beast; I often find that although there may be a native, “out of the box” solution to a problem like this, learning how to do it and understanding the hows and whys (as opposed to just copy/pasting somebody else’s scripts) would often take longer than it would for me to use a tool I already know from Linux. That flexibility is one of the best things about OS X.

Also

Syndicate content

Twitter

Older

Contact

Andy Chase
(978) 297-6402
andychase [at] gmail.com
GPG/PGP Public Key