Skip to content

Instantly share code, notes, and snippets.

@christopher-baek
Created July 19, 2015 00:17
Show Gist options
  • Save christopher-baek/e39980419e97fc690b27 to your computer and use it in GitHub Desktop.
Save christopher-baek/e39980419e97fc690b27 to your computer and use it in GitHub Desktop.
generate a new filename based on a JPEG file's EXIF data (in YYYYMMDDHHMMSS format)
import exifread
def new_filename_from_exif(filename):
new_filename = None
with open(filename, 'rb') as f:
tags = exifread.process_file(f)
if 'EXIF DateTimeOriginal' in tags:
exif_date_time_original = tags['EXIF DateTimeOriginal']
(datestamp, timestamp) = str(exif_date_time_original).split()
(year, month, day) = datestamp.split(':')
(hour, minute, second) = timestamp.split(':')
new_filename = ''.join([year, month, day, hour, minute, second])
return new_filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment