Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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.

share|improve this answer
Out of curiosity: Why do you use cat <<'EOF' instead of cat << EOF? –  Bernhard Dec 14 '12 at 7:04
@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 Dec 14 '12 at 19:17
add comment

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
share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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