You can use ImageMagick to add text to photos, either overlaid on the photo or on a border. See the annotation section of the documentation for a number of examples. Because ImageMagick is a set of command line tools, you can easily incorporate it into batch processes using shell scripts and other scripting tools.
Example: I've got a photo of some flowers, and I want to add the file name in white text in the lower left corner of the image. Here's the photo:
I can use ImageMagick's
convert command to generate a new file that shows the file name. (The command takes a number of parameters, so I'm going to break the line with backslashes, but you can enter it all on one line if you want.)
$ convert flowers.jpg -font CourierNewB -pointsize 14 \
-draw "gravity southwest fill white text 12,12 'flowers.jpg'" \
The result is a new file names