Shell – add filename as text in the corner of an image file

image manipulationimagemagickshell-scripttext;

I have a bunch of jpeg images.
Say 001abcd.jpg,
002abcd.jpg,
and so on.

I want to capture the filename and add it as a text in the image itself in one corner.
So the result would be, for example, the file 003abcd.jpg will have "003abcd" imprinted in one corner of that image. (The extension need not be there.)

I want a terminal command that can batch process hundreds of images and add its own filenames in its respective images.

I am using Linux Mint 17.

Something tells me that imagemagick can be useful, but I don't know scripting.

It is easy to put a single common text in all images. but I don't know how to put unique filenames as the text in the respective images in one go.

Best Answer

mogrify does batch processing so you could use something like this (change the font, size, color, position etc as per your taste):

mogrify -font Liberation-Sans -fill white -undercolor '#00000080' \
-pointsize 26 -gravity NorthEast -annotate +10+10 %t *.jpg

to add the file name without extension (%t) to all jpgs in the current dir, e.g. orca-lm-1.jpg:

enter image description here

This will overwrite your files so make sure you have backup copies.
If you use a different format (e.g. png) for the output files then the original files will remain unchanged:

mogrify -format 'png' -font Liberation-Sans -fill white -undercolor \
'#00000080' -pointsize 26 -gravity NorthEast -annotate +10+10 %t *.jpg
Related Question