Serious geek post alert! Avert your eyes if you are easily frightened!
I've been wasting time at work the last few days. We're really close to a code release to customers, so making changes is a bad thing. Instead, you wait around for someone to say "something broke!" then rush to fix it. Nothing for me to fix recently, so I've been playing.
I'm still working on web stuff for my image gallery / home page with the thought of having as little work needed as possible in the publishing phase. Right now, all I need to do is throw a jpg in the right directory with the right filename format, and the rest is handled by the JavaScript in the index.html page. I like it that way.
But, I was thining, it would be cool to have some of the EXIF data available (shutter speed, aperture, focal length). "Hmmm", I think, "that info is in the jpg, and the browser has the jpg, so in theory the browser already has the information... how to get at it?" Well, an image loaded by an img tag is a black hole... no cool JavaScript methods to get anywhere with that. But, I've been playing with XMLHTTPRequest objects recently, which allow you to grab any web accesible file you want, like the jpg. Sounded good. I found the EXIF spec and some sample code on how to pull info out of the file, and started away.
Here's the problem... the closest I can get to the binary information in the jpg is a String representation. UTF8 should save me... but, it doesn't. I've found all kinds of wierdness depending on the browser and platform. I simplified things and threw away the EXIF code for now, and instead focused on just generating a hex dump of the jpg file (or the first kb or so of it). No good news. On the PC / firefox, all the bytes are there, but a bunch only contain the UTF8 "unavailable" character FE (or FFFE, or 65533 - yes, that's not a byte, more confusion). On the Mac / safari, I think almost all (or even all) the "bytes" I found came back as the right values, but there were some bytes missing! I think all the missing bytes were 00, but, when you're dealing with offsets to find the right byte of information, a missing byte is a problem.
IE just keeps yelling "undefined" at me.
current test code / hex dump is here
http://homepage.mac.com/jtross/exif.html
the jpg it's trying to dump is here
http://homepage.mac.com/jtross/photoblog/1.17.2005.jpg
if you want to play / compare for yourselves. Unix hexdump is the standard. "--" in the center part of the dump represents an "unknown" byte. "-" in the right part of the dump represents a byte that's not in the normal ASCII printable range.
So, I guess having the browser use JavaScript to extract the EXIF info isn't going to work.
Next idea, which will have to wait until I get home, is to use an AppleScript folder action to do the EXIF extraction for me and create an XML file with the data for each jpg I add. Then, use an XMLHTTPRequest to get the contents of the XML file, and JavaScript to display it.