Created
July 19, 2015 00:17
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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