Green Crab Spider without any Photo Border

Creating Photo Borders Using ImageMagick

Completed Photo Border with Watermark
Completed Photo Border with Watermark

Many of our readers have made several polite inquires concerning the border utilized on my photographs.

If you enlarge any of the images used on my blog, you will notice a dainty white bordering to them, further accentuated by a drop shadow.

This bordering was created using a very handy open source tool called ImageMagick, which can be downloaded absolutely free at: The website also hosts a great resource on using this very versatile tool.

ImageMagick works primarily as a command line tool. Though it was developed primarily for use on Linux/Unix operating systems, it works like a charm on all operating systems, it’s functionality almost rivaling some of the best image processing softwares out there. It can be used to edit and compose bit- map images and can read, convert and write images in a variety of formats (around one hundred) including GIF, JPEG, JPEG-2000, PNG, PDF, PhotoCD, TIFF, and DPX. One can also use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bezier curves.

ImageMagick is also delivered as a ready-to-run binary distribution or as a source code which can be can freely used, copied, modified and distributed.

The functionality of ImageMagick is typically utilized either via the command line interface or from programs written in your favourite programming language. Using a language interface, you can use ImageMagick to modify or create images automagically and dynamically.

My ImageMagick usage is mainly via the command line interface which is extremely useful if the same operation has to be carried out repeatedly (and automatically). I run mageMagick script on the exported JPEG file from Adobe Photoshop Lightroom where I post processed it. This JPEG file approximately 1000 pixel width.

Given below are the steps used in order to achieve the photo border utilized on all my images, including the watermark.

Green Crab Spider without any Photo Border
Green Crab Spider without any Photo Border

I will be using my Green Crab Spider photograph, previously used in a feature article this blog, as an example for this tutorial. The operating system used to demonstrate the steps is Windows , but the commands used are similar for all other operating systems.

Let us start first by adding a stroke of 1-pixel width black color all round the image.

convert spider.jpg -bordercolor black -border 1 spider1.jpg

1 pixel black border applied
1 pixel black border applied

Next, we add another stroke of 1-pixel width white color, around the image.

convert spider1.jpg -bordercolor white -border 1 spider2.jpg

1 pixel white border applied
1 pixel white border applied

Now, we need create a new white layer to add a ‘shadow’ of sorts, to the spider image and move that new layer below the photo.

convert spider2.jpg ( +clone -background black -shadow 70x9+10+10 ) ^
+swap -background white -layers merge spider3.jpg

Drop shadow and white border applied
Drop shadow and white border applied

This is a complicated step. ImageMagick creates a temporary layer, retaining one operation in memory. When commanded to merge, it proceeds to join two layers into a single image. What I have done is essentially split the command furnished above, into two lines. In a windows/Dos environment we use ^ to get multiline batch statements. In Linux \is used to get a multiline command. The only thing one needs to ascertain is that there’s no space after ^.

The shadow created here is of 70% intensity with a 9 pixels spread and is shifted towards 10 pixel right and 10 pixel bottom of the image. That is what -shadow 70×9+10+10 represents.

Next we need to add some extra padding to the white border so that it is a good 50 pixel on each side and 60 pixel at the bottom (for my watermark). Border command allows for bordering, all around whereas the splice command allows us to specify how much to add on each side.

convert spider3.jpg -gravity northwest -splice 40x40 -gravity southeast -splice 20x30 +repage spider4.jpg

White border width adjusted
White border width adjusted

Once the framing is complete, it’s time to reset the canvas so we can add the watermark on this border. To achieve this, we’ll to use the “+repage” command, to completely reset the virtual canvas from the images.

In order to insert the watermark on to the lower border, two text strings are used, one stating the name of my blog and the other displaying the URL.

I prefer the ‘Chalkduster’ font for stating the blog name and Calibri, for the url. Both are at 20 point size and use 50% grey colour. After adding text the image size becomes slightly larger and I end up with a reduced quality image of 80% the capacity of the original, which is still good enough for a blog post.

convert spider4.jpg -font Chalkduster -pointsize 20 -fill grey50 -gravity southwest -annotate +50+12 "Krishna Mohan Photography" ^
-font Calibri -pointsize 20 -fill grey50 -gravity southeast -annotate +48+12 "" ^
-quality 80 spider5.jpg

Completed border with watermark
Completed border with watermark

Last, but not the least, we can combine all the above commands into a single file so as to minimize the running of multiple commands, one after another.

convert spider.jpg ^
-bordercolor black -border 1 ^
-bordercolor white -border 1 ^
( +clone -background black -shadow 70x9+10+10 ) ^
+swap -background white -layers merge ^
-gravity northwest -splice 40x40 -gravity southeast -splice 20x30 ^
+repage ^
-font Chalkduster -pointsize 20 -fill grey50 -gravity southwest -annotate +50+12 "Krishna Mohan Photography" ^
-font Calibri -pointsize 20 -fill grey50 -gravity southeast -annotate +48+12 "" ^
-quality 80 ^

You can also alternatively make a single line code (even though the page setting of my blog is breaking it into multiple lines)as follows.

convert spider.jpg -bordercolor black -border 1 -bordercolor white -border 1 ( +clone -background black -shadow 70x9+10+10 ) +swap -background white -layers merge -gravity northwest -splice 40x40 -gravity southeast -splice 20x30 +repage -font Chalkduster -pointsize 20 -fill grey50 -gravity southwest -annotate +50+12 "Krishna Mohan Photography" -font Calibri -pointsize 20 -fill grey50 -gravity southeast -annotate +48+12 "" -quality 80 spider_new.jpg

And we’re done.

ImageMagick is a great way to automate routine processes like borders and watermarks used on images. If one can overcome the initial hurdle of getting acquainted with the command line interface, miracles could be worked with this gem of a program.EXIF info – Aperture : ƒ/13 | Camera : Canon EOS 5D Mark III | Taken : 11 July, 2014 | Flash fired : yes | Focal length : 100mm | ISO : 400 | Location : 13° 4.0311′ 0″ N 74° 59.7279′ 0″ E | Shutter speed : 1/125s | Images and content Copyright © Krishna Mohan. Please contact me to purchase prints or for image publication license.

4 thoughts on “Creating Photo Borders Using ImageMagick”

  1. Just a note, on windows 10 though, you have to use “magick” in place of “convert” in your commands everywhere. Convert function gets conflicted with windows reserved keywords. Found out hard-way!
    Thank you for this useful post though.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.