Better Programming

Advice for programmers.

Follow publication

Member-only story

Giving Text an Inner Shadow with ImageMagick and Perl

William Shunn
Better Programming
Published in
8 min readJun 19, 2019

Image licensed from Bigstock

My memoir, The Accidental Terrorist, is about my youthful misadventures as a Mormon missionary. Missionaries always wear black name tags, so to promote my book I thought it would be nice to give fans a way to create and share their own customized name tag images.

To accomplish this, I figured a simple CGI script written in Perl would be best. I had a vague sense that I could use the Perl interface to ImageMagick to overlay a name in bold white text onto a blank name tag image like this one:

Blank name tag graphic (image-magick-step-1.jpg)

What’s more, I wanted the name to look like it had actually been stamped or drilled into the name tag, with maybe a slightly pebbled white surface to give things a nice feeling of texture.

I had used ImageMagick before for some simple applications, and I knew it was a very powerful graphics-processing package. However, it’s also very arcane, without much in the way of user-friendly documentation. (Oh, there’s plenty of documentation. It just helps to be fluent already in graphics-processing-ese to understand it.) Stack Overflow, to name just one forum, overflows with questions about how to do this or that with ImageMagick.

I scoured the web for an answer to what I thought was my very simple question about how to make an inner shadow, but I came up empty. Finally, all I could do was start playing around until I figured it out for myself.

I did figure it out, and I’ll lay out my method below in case there’s anyone else out there looking for an answer to the same question. I’m not claiming this is the best solution, in fact, I’m sure there’s probably some fiendishly clever way to do this in ImageMagick with a single convoluted command. Me, though, I like to take things step-by-step so I can easily see what’s happening at every point and why.

Having said that, my method is pretty straightforward, though a few of the details are a little tricky. We’ll…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

William Shunn
William Shunn

Written by William Shunn

Writer, poet and puzzle maker. Hugo and Nebula Award finalist. Author of The Accidental Terrorist: Confessions of a Reluctant Missionary. He/him/Bill.

No responses yet

Write a response