This post sprung out of a discussion between @Morgan_Hardwood and myself on IRC. I’m making notes here for posterity’s sake.

We were looking to annotate an image (using imagemagick) by including an extended area below the image that would print a logo, title, photographer across the area:

The only thing we knew for sure was that we wanted the added bar to be 40px high. This would be part of a bash script to cycle through all the images in a directory and add this information - so the width is highly variable.

We tried a couple of methods before settling on this rough working idea:

Open the image.

Clone the image.
a. fill the clone with a solid color
b. resize the clone to 40px tall (keeping the original image width, whatever it is)
c. add annotations and logos to the resized bar (so parameters like gravity are relative to the bar - we can vertically center things on the bar easily).

Making the Bar

magick convert mairi-mid-air.jpg
\( +clone

This loads the image in question, and creates a clone of it.

We are going to leverage the fact that the clone is the same dimensions (width) of the original image, resize it to our bar height, and do all operations against this bar. A the end we’ll append it to the bottom of the original before saving. (Notice all the subsequent operations take place inside the outer-most parenthesis - the final step -append will combine everything we do inside the parens to the original image at the bottom).

-fill gray
-draw 'color 0,0 reset'
-resize x40!

Set the intended bar fill color to be “gray”.
Fill the cloned image with the fill color.
Resize to 40px high (ignore aspect ratio to keep the same width).

Set Font Color + Size

-fill white
-pointsize 14

Set the font color to be “white”, and set the font size to be 14 points.

Set the Title (Center)

-gravity center
-annotate 0 'Mairi Mid-Air'

In the center of the bar, add the title text.

Set the Author (Right)

-gravity east
-annotate +10+0 'Pat David'

On the right side of the bar, set the name. The +10+0 on the -annotate parameter is to shift this text relative to the right side of the image (pushing it in 10px).

Add the Logo (Left)

On the left side of the bar,

-gravity west

load the logo (and resize it to 35px high),

\( PatDavid-League-Raleway-white.png -resize x35 \)

Add it to the bar and shift it 2.5px from the edge.

-geometry +2.5+0 -composite \)

Finally!

And finally, use the -append command to vertically append our result onto the original base image.

Just for fun, here is how to do something equivalent using the cli interface of G’MIC instead of ImageMagick. I’ve used the same constraints than those described in the first post.

How to make it work

First, you have to copy/paste the G’MIC command shown below into your file $HOME/.gmic (on Linux), or %APPDATA\user.gmic (on Windows). Create it if it doesn’t exist. This file is intended to contain user-defined commands for G’MIC, and it’s very convenient for storing custom G’MIC scripts.

I also assume you have the logo file PatDavid-League-Raleway-white.png in your current folder (otherwise, just put the full path in line 4 of the above script).
Now you are ready to use it, like this :

Explanation of the script

Here we go. I’ve replaced the short command names by the equivalent long names for the sake of clarity.

photomark : -skip "${1=Title},${2=John Doe}"

defines the function name, and gives default values to the two expected parameters.

-repeat $! -local[$>]

starts the loop over all the input images in the stack, and isolate each input image in each iteration of the loop in a local environment (so now, inside the loop, it’s like you have only a single image in the image stack).

-if {iM>255} -/ 257 is_16bits=1 -endif

takes care of 16bits per channel images. If it encounters one (detecting that the max value is >255), it divides all image values by `257` to go back in range [0,255]. You won’t loose precision at all, as G’MIC works with float-values images in any case.

-input 100%,40,1,1,'if(y>2,100,0)'

inputs a second image (denoted image [1]) in the image stack (the first image [0] being the image to annotate). This is a gray image, with height 40, and a 3-pixel wide black border on the top. This will contain the annotation we want to add to the image.

-input PatDavid-League-Raleway-white.png

inputs a third image [2] containing the logo to draw on the bottom left.

I don’t use watermarks to prevent image theft, because you can’t prevent it. I do it only so that people can find my name or website if they like the photo. Previously I would put my round watermark logo over the image, in the corner, large enough so that it would still be legible if someone downscaled and compressed the photo, for example by posting it in Facebook. However I found that this was not acceptable in some cases, as the some photos, particularly peaceful landscapes or macros, would lose much of their charm by the contrasty logo in the corner. So instead I decided to leave the whole image intact, add on a footer, and have the brief information in there. So far I’m far happier with that.

This can be easily incorporated into a bash script that can be used for batching. For example, a slideshow of award winners at a camera club can be generated using the annotated images produced by the output from such a script.

Sure. Just grab a *nix environment and use it there with a proper bash shell.
On a more serious note - we could probably adapt it to a windows batch script if someone were to brush me up on windows batch scripting again…