Skip to content

Instantly share code, notes, and snippets.

@jeyemwey
Created June 12, 2018 14:40
Show Gist options
  • Save jeyemwey/78ebe025a67e2b8a272f15bc75901b91 to your computer and use it in GitHub Desktop.
Save jeyemwey/78ebe025a67e2b8a272f15bc75901b91 to your computer and use it in GitHub Desktop.
'''
This is heavily inspired by http://www.leancrew.com/all-this/2013/10/photo-management-via-the-finder/ .
I had to modify the script for some college work at th-koeln.de
'''
import os
import exifread
import subprocess
def slug(str):
return str.replace(".", "_").replace("/", "_")
def fnumber(str):
if len(str.printable.split("/")) == 2:
zaehler, nenner = str.printable.split("/")
return slug("{:.1f}".format(float(zaehler) / float(nenner)))
else:
return str.printable
photos = os.listdir(".") # here
photos = [ x for x in photos if x[-4:] == '.jpg' or x[-4:] == '.JPG' ]
for photo in photos:
f = open(photo, 'rb')
tags = exifread.process_file(f)
exptime = slug(tags["EXIF ExposureTime"].printable)
fn = fnumber(tags["EXIF FNumber"])
print photo
print "ExposureTime: %s" % slug(tags["EXIF ExposureTime"].printable)
print "FNumber: %s" % fnumber(tags["EXIF FNumber"])
subprocess.check_output(["convert", photo, "-resize", "400x400", "out/t%s_f%s.jpg" % (exptime, fn)])
print "Converted"
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment