Bash script to create EXIF information caption
My bash shell scripting has gotten very rusty lately (and ugly), but it’s still good enough to have some fun. For my photo site I need a short program which creates a description string like "Shot with Canon PowerShot S3 IS at 63.9 mm (383.4 mm), 1/320 s, 100, Matrix, F3.5, Auto" from an image. Some shell scripting later I was done.
#!/bin/bash
DIR=$1
rm -rf $DIR/exif
mkdir $DIR/exif
for file in $DIR/*.JPG
do
file=`basename ${file}`
filename=${file/.JPG/}
output=${filename}_EXIF.txt
exiv2 $DIR/$file | awk '
BEGIN{FS=":"}
/model/{ model=$2}
/Focal length/{focal=$2}
/Exposure time/{exposure=$2}
/ISO/{iso=$2}
/Metering/{metering=$2}
/^Aperture/{aperture=$2}
/White/{wb=$2}
END{
printf (
"%s;%s;%s;%s;%s;%s;%s",
model,focal,exposure,iso,metering,aperture,wb
);
}'
| sed -e"s/\s\s*/ /g"
| sed -e "s/^\s//g"
| sed -e "s/;\s/;/g" > $DIR/exif/$output
IFS=";"
read model focal exposure iso metering aperture wb <<END
$(cat $DIR/exif/$output)
END
multiplier=1
if [ $model == "Canon PowerShot S3 IS" ]; then
multiplier=6
fi
focal_value=$(echo $focal | awk '{print $1}')
focal_equiv=$(echo "$focal_value * $multiplier" | bc -l)
echo "Shot with $model at $focal ($focal_equiv mm), $exposure, $iso, $metering, $aperture, $wb" > $DIR/exif/$output
done
You can leave a Reply here. Of course, you should follow me on twitter here.




