Sunday, March 14, 2010

Adding image borders and EXIF tagging

I found a web blog from Frederico Maggi who posted a nice tutorial for batch editing image files to add a border with some Exif data.

The work by Frederico was a great start and I took his work and made a few treaks. The major change I made was to the ~/bin/lr_borderscript. I felt that the border size was too small and that the text was too small. I also adapted the script to perform a rename using the convert utility

#!/bin/sh
#File: ~/bin/lr_border
 
year=$($HOME/bin/exiv_year $1)
data=$($HOME/bin/exiv_data $1)
 
name="Carl Wainwright © "
 
if [ -n "$year" ]
then
name=$name" "$year
fi

inname=`convert $1 -format "%t" info:` 
echo "Processing $inname"

outname=${inname}_mod.jpg
#convert $1 -resize 50% $outname
convert $1 $outname

echo "Writing to $outname"
 
mogrify -gravity North -border 5x5 -bordercolor black $outname
mogrify -gravity North -border 1x1 -bordercolor grey $outname
mogrify -gravity North -border 60x60 -bordercolor black $outname
 
if [ -n "$data" ]
then
mogrify -pointsize 30 -fill white -gravity SouthEast -annotate +25+6 "$name" -gravity SouthWest -annotate +25+6 "$data" $outname
else
mogrify -pointsize 30 -fill white -gravity SouthEast -annotate +25+6 "$name" $outname
fi

I also modified the exiv_data script to match the Exif data for my Konica Minolta 7D.


#!/bin/sh
#File: $HOME/bin/exiv_data
time=$(exiv2 -PEkt pr $1 2>/dev/null | tr -s " " " " | grep -E "\.Photo\.ExposureTime" | awk '{print $2}')
focal=$(exiv2 -PEkt pr $1 2>/dev/null | tr -s " " " " | grep -E "\.FocalLength " | awk '{print $2}')
aperture=$(exiv2 -PEkt pr $1 2>/dev/null | tr -s " " " " | grep -E "\.Photo\.FNumber" | awk '{print $2}')
iso=$(exiv2 -PEkt pr $1 2>/dev/null | tr -s " " " " | grep -E "\.ISOSpeedRatings" | awk '{print $2}')
 
if [ -n "$time" -a -n "$focal" -a -n "$aperture" -a -n "$iso" ]
then
echo $focal"mm, "$time" @ "$aperture" (ISO "$iso")"
fi

Executing the above script can be done as follows 

ls *.JPG | while read file; do ~/bin/lr_borderscript_new $file; done

1 comment:

  1. Thanks a lot for posting this. I am trying to implement a similar workflow using Federico Maggi's and your own scripts, but I am having trouble getting the scripts to work on my Ubuntu server (and Federico Maggi's tutorial is sadly no longer available).

    I export the images as TIFF files to a folder on the Ubuntu box, after which I run a resize script to perform step-sharpening to the images, resulting in jpg files. I was then planning to run your border script on these jpg files, but I am getting "bad interpreter" errors.

    ReplyDelete