RPhotoz Home

Outdoor Photography Home

Outdoor Photography Articles

A few years back I purchase a Polaroid SprintScan film scanner, Epson 1270 printer, and all the necessary computer equipment and software to work with my photographs in Digital form. I really like the control that having this setup has afforded me. I can alter the picture to more closely match what I felt and saw when I took the photo as well as create photographs that otherwise could not be created (like digitally combining two shots to get the full tonal range of bright sky and shadowed canyons). The one draw back to this is that I also have a full time job and not all the time in the world to scan in every slide I create (not to mention the time spent dropping off and picking up film). I found myself with a huge backlog of slides to scan and process (I'd rather be shooting pictures than processing them).

The recent advancements and subsequent price drops in Digital SLRs finally made the purchase within fiscal reach for me. I purchased a Nikon D100 and it seems that my profession (IT Consultant) and passion have once again come closer together. I was very interested in the feature that keeps all of the shot data embedded in the digital file. I instantly started thinking of ways to extract this data into a database where it could be used for many different web page features.This data, called Exchangeable Image File Format (EXIF), can be extracted and displayed using many different development programs. Before I get into examples of doing so, let's go over the EXIF specification a bit.

The General Format Structure of a JPG (or other raw file format) consists of EXIF image file Specification, EXIF audio file Specification, and the Recording Medium Specification. Without getting to technical, the image files that you digital camera creates uses a portion of the file to store this data. This data is organized in properties with values associated with it. These properties are actually "Tags" that can be pulled out of the file and the associated value displayed. To display these values you need to do some Data Type conversion. For example, the Data for Focal Length is contained in a Rational Data Type. This data is actually 2 numbers (Long Data Type) used typically to display fractions. The first long is the numerator and the second is the denominator. So to get the value displayed correctly you would need to do a bit of processing (as shown below).

(Property Value 1 / Property Value 2) & " mm"

The example I have written to show my shot data in my web page (dynamically from the file) was written using Microsoft's .net development environment. While I could have used many different development environments to pull the EXIF data from my files, the .net framework has a native "Image" object that is very easy to use and understand. Other programming options would require reading the image into memory and specifically reading memory block to get at the data. While this is not impossible to do, I wanted to use the easiest example I could find so that this article could benefit the widest audience possible. To see the practical use of this data, click on this link  to view one of my digital pictures. At the bottom of the page is a table that displays a few pieces of information. This data is dynamically pulled out of the picture at display time.

Now let's look at some of the Example Code.

First, we need to declare a few objects/variables.

Dim objImage As System.Drawing.Image
Dim arrProps As PropertyItem()
Dim objProp As PropertyItem
Dim strTemp As String
Dim strDate As String

Now we can load the image into the Image object and show an example of looping through the properties and converting the values (This example will only show the Shot Date Property).

objImage = System.Drawing.Image.FromFile(MapPath("FileName.jpg")) ' Make sure to put your file name in place of FileName.jpg
arrProps = objImage.PropertyItems

For Each objProp In arrProps

Select Case objProp.Id

Case 306 'Shot Date

strTemp = System.Text.Encoding.ASCII.GetString(objProp.Value)
'Reformat the Date From yyyy:mm:dd hh:mm:ss to MM/DD/YYYY
strDate = Mid(strTemp, 6, 2) & "/"
strDate &= Mid(strTemp, 9, 2) & "/"
strDate &= Mid(strTemp, 1, 4)

'Case "Next Tag ID Goes here" ...

End Select


Then we just display the date variable in the html.



The Date this shot was taken was <%=strDate%>.



Now create a file with that text in it and name it mypage.aspx. Put the file out on the web server along with the image file and that's all there is to it. You do not need the Microsoft development environment to create these pages; you could type this in using notepad if you wish. All that is required is a web server that supports the aspx extension (supports the .net framework). Call you ISP if you are unsure.

Here are a few links to help you get started:

Downloadable Sample Code (zip)

2.1 EXIF Specification (pdf)  (This spec contains info about every property, its tag value, and data type)



Outdoor Photography Home

Outdoor Photography Articles

All of the photographs and text on these pages are Copyright 2000-2005 by Mike Rogers, unless otherwise noted. All rights reserved. They may not be reproduced, published, copied or transmitted in any form, including electronically on the Internet or World Wide Web, without written permission of the author. Thank you for respecting the intellectual property rights protected by the Copyright laws of the United States and new International Copyright treaty.