-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_photos.py
32 lines (29 loc) · 1.06 KB
/
import_photos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from PIL import Image
from PIL.ExifTags import TAGS
def return_timestamp(imgs):
'''
:param imgs: a list of full paths to images
:return: two dictonaries: first a dictonary of image name: timestamp of photo taken.
Secondly a dictonary of images which Failed
'''
dict_timestamps = dict()
errors_images = dict()
for index, img in enumerate(imgs):
try:
image = Image.open(img)
# extract EXIF data
exifdata = image.getexif()
# iterating over all EXIF data fields
for tag_id in exifdata:
# get the tag name, instead of human unreadable tag id
tag = TAGS.get(tag_id, tag_id)
if tag == "DateTime":
# print(tag)
tstamp = exifdata.get(tag_id)
# print(tstamp)
to_add = {img : tstamp}
dict_timestamps.update(to_add)
except:
to_add = {img: False}
errors_images.update(to_add)
return(dict_timestamps, errors_images)