#!/usr/bin/python # Creates a PNG histogram of the focal lengths of the images on the command # line, called "fl-hist.png", in the current directory. import os import os.path import subprocess import sys import matplotlib matplotlib.use("cairo") import matplotlib.pyplot as plt OUTFILE = "fl-hist.png" #if (os.path.exists(OUTFILE)): # print "%s exists, aborting" % (OUTFILE) # sys.exit(1) focals = list() for f in sys.argv[1:]: focal = os.popen("exiftool -FocalLength -b %s" % (f)).read() focal = int(round(float(focal))) print f, focal focals.append(focal) if (len(focals) == 0): print "no files given, aborting" sys.exit(1) #focals.sort() bins = range(min(focals), max(focals) + 1) #for focal in focals: # if (focal not in bins): # bins.append(focal) #print bins plt.figure(figsize=(6,4.5)) plt.hist(focals, bins=bins, align="left", edgecolor="blue") plt.xlabel("Focal length (mm)") plt.ylabel("Number of photos") plt.axis(xmin=10, xmax=(max(focals) + 5)) plt.savefig("fl-hist.png", format="png")