-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexifview.py
More file actions
39 lines (31 loc) · 948 Bytes
/
exifview.py
File metadata and controls
39 lines (31 loc) · 948 Bytes
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
33
34
35
36
37
38
39
import sys
from PIL import Image
from PIL.ExifTags import TAGS
"""
Get exif metadata of an image.
function that takes an image path as a str and returns a dictionary containing the image's exif metadata
Args:
filepath: Get metadata from this file.
Returns:
Extracted exif metadata
Raises:
IOError: File could not be read.
"""
def exif_meta(image):
try:
image = Image.open(image)
except (AttributeError,IOError) as e:
print(e)
# if image.endswith('.png'):
# image.load() # Needed only for .png EXIF data (see citation above)
# elif image.endswith('.jpg'):
exif = image.getexif()
meta = {}
for tagID in exif:
tag = TAGS.get(tagID, tagID)
data = exif.get(tagID)
if isinstance(data, bytes):
# data = data.decode()
data = str(data)
meta[tag] = data
return meta