While importing my photo library, I noticed that some photos were getting the current date instead of the date that they were taken. It turns out that a bunch of my photos only have DateTime set, and not DateTimeOriginal. The following patch tries to get the date from exif data like so: DateTimeOriginal DateTime DateTimeDigitized It may not be perfect. This is the first C#/Mono code i have ever written. diff -u -r1.9 Exif.cs --- src/Exif.cs 25 Mar 2005 04:45:59 -0000 1.9 +++ src/Exif.cs 26 Apr 2005 07:18:06 -0000 @@ -480,13 +480,6 @@ } exif_entry_initialize (handle, tag); - - //FIXME the month string in time fields in libexif ix currently broken so we do our own. - if (tag == ExifTag.DateTime - || tag == ExifTag.DateTimeOriginal - || tag == ExifTag.DateTimeDigitized) - this.SetData (System.DateTime.Now); - } diff -u -r1.59 PhotoStore.cs --- src/PhotoStore.cs 30 Mar 2005 04:25:27 -0000 1.59 +++ src/PhotoStore.cs 26 Apr 2005 07:18:09 -0000 @@ -517,8 +517,12 @@ try { using (Exif.ExifData ed = new Exif.ExifData (path)) { Exif.ExifContent content = ed.GetContents (Exif.ExifIfd.Exif); - Exif.ExifEntry entry = content.GetEntry (Exif.ExifTag.DateTimeOriginal); - time = Exif.ExifUtil.DateTimeFromString (entry.Value); + Exif.ExifEntry entry = content.Lookup (Exif.ExifTag.DateTimeOriginal); + if (entry.Value==null) + entry = content.GetEntry (Exif.ExifTag.DateTime); + if (entry.Value==null) + entry = content.GetEntry (Exif.ExifTag.DateTimeDigitized); + time = Exif.ExifUtil.DateTimeFromString (entry.Value); time = time.ToUniversalTime (); } } catch (System.Exception e) { -- Stewart Smith (stewart flamingspork com) http://www.flamingspork.com/
Attachment:
signature.asc
Description: This is a digitally signed message part