EXIF fun with CarrierWave uploader
To play with the CarrierWave uploader gem I created a new Rails project just for the purpose of experimentation. I had thought about doing this as part of the Hartl Rails Tutorial sample app but ultimately decided to keep things as bare-bones as I can.
When trying to understand a new system, a debugger is a developer's best friend. Part of this exercise is to get my feet wet using a debugger to poke around a running Rails app. The Hartl Rails Tutorial text introduced the byebug gem but only minimally covered usage. The official Rails Guides had more information which helped me get going, in addition to various users writing up their own cheat sheets.
I decided to dig into image metadata. Basic information such as width and height were made available as img[:width] and img[:height] but where are the others? With the help of byebug I found that they were available in the img.data hash. Most of the photography-specific EXIF metadata are in there as well, though somebody interested only in that subset can access it via the img.exif hash.
As an exercise I decided to try to pull out the original date. Time stamp on digital photography files have always been a headache. Most computer OS track "Created Date" and "Modified Date" but they are relative to the computer and not reliable for photo organization purposes. Photo editing introduces another twist: if an image is created from a photograph, the time stamp would be the day the edit operation was made and not when the original photo was taken.
Which is how I ended up looking at EXIF "DateTime", "DateTimeOriginal", and "DateTimeDigitized" to take the earliest date of the three (when present). Then I ran into another can of worms: time zones. The EXIF time stamp have no time zone information, but the Ruby DateTime object type does. Now my time stamps are interpreted as UTC when it isn't. Since EXIF doesn't carry time zone data (that I can find) I decided to leave that problem to be tackled another day.