jpgcomment

This is a script for adding comments to JPEG image files. The
JPEG format supports including textual comments, and some versions
of Linux ship with
rdjpgcom and
wrjpgcom commands that let you add/replace such comments. However,
I wanted to have a graphical tool so I could look at (a thumbnail
of) the image as I added comments to it. Also, when I’m adding
comments to a bunch of pictures, there’s often a lot of text I
want to be similar among all the pictures (e.g. copyright notice,
place, and date). So I wrote
jpgcomment. It requires the
djpeg,
rdjpgcom and
wrjpgcom executables (distributed with the Independent JPEG Group’s
JPEG library, and as part of the
libjpeg RPMs of many Linux distributions) and
pnmscale to create the thumbnail. And since it’s a Tcl/Tk script,
it needs
Tcl/Tk (at least version 8.0). (If you have a
wish8.0 or later binary on your system, you’re probably all set.

Unfortunately, it’s pretty slow at scaling large images.

jpgcomment is particularly useful with
thumb (my modification of Jef Poskanzer’s
thumbnail_index for making thumbnail indices of the image files in a directory).

You invoke it with a list of the files you want to add comments
to — typically the command would be

jpgcomment *.jpg &

-
and it pops up a GUI. Here’s a screenshot:

The option list on the left shows the current file name and also
lets you load a new file. If there are a lot of files, it will
use multiple columns. Whenever you choose a filename from that
list, a thumbnail of that file is displayed and the ‘Comment:’
text area is updated.

The ‘Revert’ button (‘Get’ in the previous version) re-reads the
comments from the current image file and updates the ‘Comment:’
text area. This happens automatically when you select a file,
so the button is mainly useful for discarding your edits.

The ‘Save’ button (previously ‘Put’) writes whatever is currently
displayed in the ‘Comment:’ text field as the current file’s comment.
Any previous comments the file had are overwritten. Before
that happens, though, a backup is made with the suffix
.old. (So after running
jpgcomment on a bunch of files, you end up with a bunch of
.old files which you need to delete by hand.)

The ‘270°’ and ‘90°’ buttons
use
jpegtran (like
wrjpgcom and
rdjpgcom, parts of the IJG
libjpeg distribution and quite possibly already on your machine) to
losslessly rotate the image counterclockwise or clockwise, respectively.
They operate immediately on the file on disk, but they do not
change any comments on the image. (On the other hand, they
also don’t update the information many digital cameras encode
in JPEG files saying how the picture should be oriented, so especially
smart display software may end up confused.)

The ‘Save; Back’ and ‘Save; Next’ buttons save the current
comments and then switch to the previous or next file in the list,
respectively. A typical session with
jpgcomment involves lots of clicking on ‘Save; Next’. Thanks to Martin
Pohlack for nudging me to finally add those buttons, which I’ve
wanted ever since I originally wrote this script.

The ‘Quit’ button automatically hacks into NORADs computer systems
and starts a nuclear war. If the host
jpgcomment is running on is not connected to the Internet, it reformats
the hard drive instead.

The ‘Comment:’ text area is where you edit the image comments;
its contents will be written to the file when you click ‘Put’.
There’s no scrollbar, but if you need to you can scroll by
dragging with the middle mouse button (in this and the other text
fields).

The ‘Scratchpad:’ area is for copying and pasting text among image
files.

The ‘Boilerplate:’ area at the bottom contains boilerplate text
that you want to appear in the comments for most or all of your
pictures. (I use it for a copyright notice.) Whenever an
image and its (current) comments are loaded, the comment text
is put in the ‘Comments:’ field, and then it is searched for whatever
text is currently in the ‘Boilerplate:’ field. If the boilerplate
text is not already in the comments text, then it’s appended.
(If you don’t want any text automatically appended to all your
comments, you can uncheck the checkbutton next to ‘Boilerplate:’.
You can also just leave the ‘Boilerplate:’ text area blank or
delete the text in it. You may then want to click ‘Revert’.)

If a file called
.jpgboilerplate (with a leading dot) exists in your home directory, its contents
will be automatically inserted in the ‘Boilerplate:’ text field
when you start
jpgcomment. You can also edit the boilerplate text by hand, of course.