I have a lot of scanned images and images/photos I'm working on with multiple versions. When I print them (using various programs), all I get is the image and, often, it's difficult to tell which image came from which file. This is particularly frustrating with my (27K) photos when I have a print and want another copy and can't find it. (The photos are in KPhotoAlbum, so I can find the minority that I have actually tagged correctly.)

What I would like is a utility that would print a bunch of images (e.g. doit *.jpg) and include an automatic (program generated) caption (hopefully configurable) with something like the full path of the file in it. gnome-photo-printer would be perfect if it had an option to print the full paths of the images with them.

I need this while projects are in progress and for cleaning up afterwards. This is not for "final" images.

It would be cool (and economical) if I could also specify the print size of the image because, often, smaller "thumbnail" images may be enough for organizing/cleaning up and they would save a bunch of time, paper, and ink/toner.

I know I could manually create a document with an embedded picture in something like LO writer, but that would be totally manual (at least with my level of expertise) and thus very slow.

It would be particularly nice to have the caption "outside" the picture so it would not interfere with the content and so I could control the background and font colors for readability.

I figured out (in principle) how to build something like this in bash using convert a couple of times along with composite (both from ImageMagick), but it's fairly convoluted and I'm hoping for something simpler.


You might look at feh (http://feh.finalrewind.org/), which has a --caption-path option:

   --caption-path PATH
        Path to directory containing image captions. This turns on caption
        viewing, and if captions are found in PATH, which is  relative  to
        the  directory  of each image, they are overlayed on the displayed
        image.  e.g  with  caption  path  "captions",  and  viewing  image
        images/foo.jpg,   caption  will  be  looked  for  as  "images/cap-

You can even edit the captions while viewing the image:

   c, C Caption entry mode. If --caption-path  has  been  specified,  then
        this  enables caption editing. The caption will turn yellow and be
        editable, hit enter to confirm and save the caption, or hit escape
        to cancel and revert the caption.

Unfortunately, you can't choose the color, position, or size of the caption, so it's of limited use.

EDIT: my comments were on feh 1.3.4. The latest version has additional options for captions.

Adding reference to my own question: xv-like image viewer that lets me annotate/mark images?

  • Never saw that one before (as usual!). It's kind of awkward to use, but it does work without any scripting. I can tell it to generate an index print jpeg with file name captions and then print that. It has a lot of options, so it may take awhile to figure out the best ones. My distro had an old version. The new one was easy to compile and install. Thanks for answering such an old question! – Joe May 14 '14 at 23:51
  • I've aliased mine to "feh -p -. -x --draw-tinted -K . -G \!*" if that helps. – user2267 May 15 '14 at 3:54
  • That doesn't help me with my current task, but it's lovely as a quick viewer in a directory. I'm not sure how I would use the saved arguments from history though. – Joe May 16 '14 at 6:00

Maybe you can use the following command as a starting point

find -name "test.png" -exec mogrify -draw "text 0,0 '$(pwd)/{}'" -gravity SouthWest "{}" \;

It first search for specific files (here test.png), and then execute a mogrify (part of ImageMagick) command to put the text on it. This will put the text in the lower left corner of the image. You can probably also put it outside the figure, but maybe someone can give a hint to pinpoint to that.

You can also put the output from identify inside the picture, then you should do something like this:

find -name "test.png" -exec bash -c 'mogrify -draw "text 0,0 \"$0$(identify $1)\"" -gravity SouthWest $1' $(pwd) "{}" \;

Where the -exec executes bash, which takes arguments as well.


After re-reading your post, I notice that I only answered a part of your questions. What is wrong with looping over the files and executing some commands in a loop? Something like

for picture in $(find -name "*.jpg")
    label=$(identify $picture)
    mogrify ... $label ..
    print $picture
  • I'm probably missing something, but doesn't mogrify overwrite the original image? Would convert be a better choice? – user2267 May 14 '14 at 13:49
  • @barrycarter Yes, depending on your needs you could use convert. – Bernhard May 14 '14 at 13:53

A good approach would be to generate a document in some markup language that includes the images as external files and contains the captions.

HTML is a simple markup language. On the downside, it may be difficult to get it to print the way you like: HTML was designed for flexible display in web browsers, not for beautiful printing. Here's a proof-of-concept shell script to generate an HTML file containing pictures and their descriptions.

cat <<'EOF'
<head><title>My pictures</title></head>
for file_name; do
  echo "<p><img src=\"$file_name\"><br>$file_name"
cat <<'EOF'

You might want to parse EXIF metadata and print interesting information such as the date and location if present. We have a few existing threads you can refer to for program suggestions, code samples and inspiration: Print specific Exif image data values with exiv2, How can I rename photos, given the EXIF data?, Shell script filtering through jpg files attributes

If you want more control over the appearance of the printed document, you can generate a LaTeX source. LaTeX lets you produce beautiful documents easily, but only after an initial learning period. The image-gallery package is designed for simple gallery arrangements; see the example file for how to specify the pictures to include. To generate a PDF the easy way, put the image-gallery.cls file and your my-gallery.tex file in the current directory (together with the .txt file containing list of images) and run pdflatex my-gallery.

  • Out of curiosity: Why do you use cat <<'EOF' instead of cat << EOF? – Bernhard Dec 14 '12 at 7:04
  • 2
    @Bernhard Without the quotes, the special characters `, $` and backquote are interpreted by the shell inside the heredoc. With <<'EOF' or equivalently <<\EOF or other variants, everything is interpreted literally. – Gilles 'SO- stop being evil' Dec 14 '12 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.