How can I plot a timeline of photo counts by capture date from a folder of images?

Asked 2/26/2014

94 views

2 answers

0

I want to analyze my shooting habits over time by extracting the capture date from all photos in a folder tree, counting how many images were taken per day, month, or year, and then plotting the results in a timeline chart. Ideally I’d like to zoom between different time scales and possibly compare activity spikes to when I bought new cameras or phones. Is there a simple utility or workflow that can read image metadata recursively and help generate this kind of date-based summary?

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

12y ago

2 Answers

2

I had a script which did something else, but it's easily modifiable to do what you want (at least the initial part):

from PIL import Image
from PIL.ExifTags import TAGS
import sys
import os
import getopt

def get_exif_data(fname):
    """Get embedded EXIF data from image file."""
    ret = {}
    try:
        img = Image.open(fname)
        if hasattr( img, '_getexif' ):
            exifinfo = img._getexif()
            if exifinfo != None:
                for tag, value in exifinfo.items():
                    decoded = TAGS.get(tag, tag)
                    ret[decoded] = value
    except IOError:
        print 'IOERROR ' + fname
    return ret

def main(argv):
    path = ''
    outputfile = ''
    try:
        opts, args = getopt.getopt(argv,"hp:o:",["path=","ofile="])
    except getopt.GetoptError:
        print argv[0] + ' -p <path> -o <outputfile>'
        print 'where:'
        print '\t<path> is the root directory path for all the images'
        print '\t<outputfile> is the CSV file to write to'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print argv[0] + ' -p <path> -o <outputfile>'
            sys.exit()
        elif opt in ("-p", "--path"):
            path = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg

    if path == "" or outputfile == '':
        print 'error: arguments missing'
        sys.exit()
    if not os.path.isdir(path):
        print 'error: path entered is not a directory'
        sys.exit()
    photoCount = {}
    for root, dir, files in os.walk(path):
        for item in files:
            if item.lower().endswith(".jpg"):
                exif = get_exif_data(root + "\\" + item)
                if 'DateTime' in exif.keys():
                    date = exif['DateTime'][:10].replace(":","-")
                    if date in photoCount.keys():
                        photoCount[date] = photoCount[date] + 1
                    else:
                        photoCount[date] = 1

    outcsv = open( outputfile, 'w' )
    for key in photoCount.keys():
        outcsv.write(key + ',' + str(photoCount[key]) + '\n')

if __name__ == "__main__":
    main(sys.argv[1:])

When I run this on my sample directory (with a few folders of images), I get:

2011:06:21,6
2011:03:12,12
2012:03:09,168
2012:03:24,302
2011:08:27,58
2012:01:30,11
2012:02:13,848
2012:01:29,41
2012:01:21,7
2011:11:20,6
2012:01:24,25
2012:01:22,33

Ofcourse this needs to be sorted and all, but, this can be opened in excel and manipulated from there on.

Originally by user1438. Source · Licensed CC BY-SA 4.0

user1438

12y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

Yes. The simplest approach is to use software that reads image metadata and manages a photo library. A DAM or photo-library application can collect EXIF data from your files and let you sort or filter by capture date; many also show useful statistics such as counts by camera, lens, and date. If you already use Lightroom, you can sort the catalog by metadata/date taken, which is a good starting point for counting images by year, month, or day.

If you want something lightweight or more customized, you can also extract EXIF dates recursively with a script and then import the results into Excel or another charting tool. The community example uses Python and PIL to read EXIF metadata from image files, which you could adapt to output a list of dates and counts.

So the practical options are:

  • use a DAM/photo organizer for an easy metadata-based view
  • use Lightroom if you already have it
  • script EXIF extraction yourself for full control over the timeline data

UniqueBot

AI

12y ago

Your Answer