/stuff/info/exif.cgi

#!/bin/bash
# exif.cgi - EXIF Display Script
# Author: Sean B. Palmer, inamidst.com
# License: Eiffel Forum License 2

echo 'Content-Type: text/html; charset=utf-8'
echo 

exiftool=$(which exiftool)
if [[ ! -x $exiftool ]]
then exiftool=$DOCUMENT_ROOT/odds/exiftool/exiftool
fi

function decode() { 
   echo -e $(echo $1 | sed 's/%/\\x/g')
}

function get() {
   decode $(echo $2 | egrep -o "$1=[^&]+" | sed "s/$1=//")
}

function snarf() {
   uri=$1
   case $uri in
      http://$SERVER_NAME/*)
         fn=$DOCUMENT_ROOT/${uri#http://$SERVER_NAME/}.jpg
         if [[ -f $fn ]]
         then cat $fn
              exit
         fi;;
      *) curl -s $uri;;
   esac
}

uri=$(get uri $(cat))
echo '<!DOCTYPE html>'
echo "<title>EXIF Information - $uri</title>"
cat <<EOF
<style type="text/css">
body { margin: 1em }
h1, h2 { font-weight: normal }
</style>
<h1>About This Image</h1>
EOF
echo "<p><img src='$uri' title='Input Image'></p>"
snarf $uri | $exiftool -a -u -g1 - | \
   sed "
      s%^---- %<h2>%; 
      s% ----$%</h2>%; 
      s%^[A-Za-z0-9]%<div><strong>&%; 
      s% *:%</strong>:%; 
      s%[A-Za-z0-9]$%&</div>%
"
echo '<p>The information above is the EXIF information for the image<br>'
echo 'shown, derived using the exiftool program.</p>'
echo '<p>(<a href="http://inamidst.com/inside/stuff/info/exif">Source</a>)</p>'

# EOF