Add borders to images automatically
Using your Mac, Linux or windows box, you can automatically manipulate images from the command line using ImageMagick. Most often, I use it to easily add borders to my images. I know I could use a plugin for Aperture, but I often use the “out of camera” JPEG files produced by shooting RAW+JPEG. The best part of the script that I am going to show you is that you can even run it on a web server where your website is hosted to batch adjust images, all in a matter of seconds.
I don’t use windows, so I will attempt to provide the best instructions that I can for Linux and MAC OSX based systems.
On linux systems, specificly Ubuntu Linux, you can install ImageMagick by issuing the following from the command line:
sudo apt-get install imagemagick
Thats it. Imagemagick is installed. You can skip down to the post-installation steps.
On the Mac, you need to make sure that you have Xcode installed, which will allow your Mac to compile the ImageMagick source code into an executable file that you can call from a script. XCode can be installed from the Leopard or Snow Leopard DVD that came with your Mac.
After XCode has been installed, you will need to download and install “Port“. After Port is successfully installed, you can use it to update ImageMagick:
Update port tree:
sudo port selfupdate
(if you are like me, and you installed MacPorts under 10.5, but didn’t update it when you moved to snow leopard, you can update your installed ports with: sudo port upgrade –force installed ). I had to follow the steps at: http://trac.macports.org/wiki/Migration to get my ports install back on track.
Once you have MacPort sorted out, its time to install ImageMagick:
sudo port install ImageMagick
After ImageMagick is installed, you can use a simple script such as the following to automatically add borders to your images:
put the following text into a text file:
#!/bin/bash
mkdir ./output
for i in $( ls ./*.JPG ); do
convert $i -bordercolor black -border 25×25 output/$i
done
Save the file as addborder.sh and place it in a folder that’s convienient for you. I have a scripts folder under my home, so I can reference the script via: ~/scripts/addborder.sh
In order to run the script, you will need to make it executable, from a terminal issue the following command:
chmod a+x ~/scripts/addborder.sh
The code in the script will create a folder called output where it will put the new files with the boder. The script does not alter the origional files. To use the script, simple open up a terminal window, change to the directory with your images and run:
~/scripts/addborder.sh
Voila, you should now have a folder called output within your image folder containing the modified files.
ImageMagick is a very powerful set of tools for modifying images, and the example above is only scratching the surface. Other uses of ImageMagick could be resizing images for posting to the web, adding a watermark, or all three combined.

Recent Comments