3
Vote

Sorting Photos by EXIF TAG

description

Hi, first off let me say that this is an AWESOME plugin that you have created. I'm using it through Windows Home Server and I love it.

One suggestion, though. It appears as though you are using the EXIF_DATETIME tag to sort the photos. It has been my experience that this doesn't always work. Photo editing software sometimes modifies this tag when you save an image after editing. I would suggest using the EXIF_DATETIME_DIGITIZED tag instead.

I've been having some trouble getting the photos to display in the correct order and I'm going to give this a try when I get home. Thanks...

comments

gbordier wrote Dec 31, 2007 at 11:45 AM

Same here.

What I did is change the Sort method to sort using digitized time (you'll have to iisreset I guess) :
    internal static DateTime GetImageDate(FileInfo pictureFileInfo) {
        string cacheKey = "date(" + pictureFileInfo.FullName + ")";
        Cache cache = HttpContext.Current.Cache;
        DateTime result = DateTime.MinValue;
        object cached = cache[cacheKey];
        if (cached == null) {
            Metadata data = GetImageData(pictureFileInfo);
            ExifDirectory directory = (ExifDirectory)data.GetDirectory(typeof(ExifDirectory));
            if (directory.ContainsTag(ExifDirectory.TAG_DATETIME_DIGITIZED)) {
                try {
                    result = directory.GetDate(ExifDirectory.TAG_DATETIME_DIGITIZED);
                }
                catch { }
            }
            else {
                IptcDirectory iptcDir = (IptcDirectory)data.GetDirectory(typeof(IptcDirectory));
                if (iptcDir.ContainsTag(IptcDirectory.TAG_DATE_CREATED)) {
                    try {
                        result = iptcDir.GetDate(IptcDirectory.TAG_DATE_CREATED);
                    }
                    catch { }
                }
                else {
                    result = pictureFileInfo.CreationTime;
                }
            }
            cache.Insert(cacheKey, result, new CacheDependency(pictureFileInfo.FullName));
        }
        else {
            result = (DateTime)cached;
        }
        return result;
    }
}