Installing ImageMagick on Mac OSX
We have a need to quickly resize JPEGs. There are tons of programs for Mac OS X that can do this, freeware and payware. We tried a few of them. Most of them are either drag and drop or you browse for a folder. In general they work pretty well. But they never quite seems to do what you want. And some have bugs.
But we really wanted something that could be run from the unix command line so that we can run it from unix scripts. Automation is the key to productivity.
So we decided to try ImageMagick, which is an open source image processing program. You can download a ready-to-install Mac OS X binary distribution. But as far as I could tell, it was compiled only for Mac OS X Snow Leopard 10.6 (Intel). If you have Mac OS X 10.4 or 10.5 you have to do a custom build. The easiest way to get and build it is using MacPorts.
Install MacPorts First
First you have to install MacPorts. Got to MacPorts Homepage and then click on Installing MacPorts. The computer I was installing it on had MAC OS X 10.4.11 (Tiger) so I clicked on the Tiger .dmg download.
You must have Apple’s XCode Developer Tools installed on your computer. It is also useful to have the X11 windowing environment installed.
The Mac OS X Package Installer automatically installs the MacPorts and sets your shell environment. MacPorts is installed in /opt/local/bin and your .bash_profile in your home directory is updated. It saves your old .bash_profile. Look at the tail end of .bash_profile you will see /opt/local/bin added to the PATH environment variable. The installation does not take very long. maybe a couple of minutes.
Here is the MacPorts Guide
Then Install ImageMagick
Once you have MacPorts installed, you can use it to install ImageMagick. Here is the ImageMagick homepage. If you click on Binary Releases/Mac OS X you get to the page with instructions for installing on Mac OS X. Basically you type on the command line:
$> sudo port install ImageMagick
MacPorts first computes all the dependencies and then starts to fetch, extract, apply patches, configure, build, stage, install, activate and clean everything. I don’t know exactly what all that means, but that is the sequence of steps for each item.
There might be a lot of dependencies, so this could go on for a while. It observed bzip2, expat, zlib, freetype, gperf, libiconv, fontconfig, jpeg, libpng, libxml2, p7zip, pkgconfig, tiff, xorg-bigreqsproto, xorg-inputproto, xor-kbproto, xorg-libXau, xorg-libXdmcp, xorg-util-macros, xorg-libxtrans, xorg-libx11, xorg-libXext, ncursesw, ncurses, gettext, perl5.8, p5-locale-gettext, helpman2, m4, autoconf, xorg-libsm, xorg-libXt, and finally ImageMagick! (I may have missed a few. I am glad I didn’t have to install all this by hand!) MacPorts fetches tar.gz files from all over the internet. A lot of them seemed to take forever to build.
The installation took a long time, over two hours. I thought it would never finish. I don’t know why it takes so long to build each module.
Here is a guide to ImageMagick Command-Line Processing.
Test ImageMagick
Try resizing a jpeg:
convert -resize 1024x1024 -quality 75 a.jpg a_1024.jpg
How about a folder of jpegs? This shell script resizes a directory of .JPG files and writes them into a new directory, changing the JPG to jpg. Type it into a text file and execute it
mkdir 1024
for img in *.JPG
do
newname=`echo $img | sed -e 's/.JPG/.jpg/'`
echo $img
convert -resize 1024x1024 -quality 75 $img 1024/$newname
done
Faster Batch Processing
Using the unix command line for batch procesing images is infinitely faster than using interactive programs like Photoshop or Lightroom. Plus you can write shell scripts to automate everything. Hurray for the command line.
Here is another blog entry for Installing ImageMagick on Mac OS X
