Skip to content

Commit 21dd02a

Browse files
committed
[Fixes #13831] Supported additional EXIF metadata extraction from image Documents and refactor of DOCUMENT_TYPE_MAP
1 parent bde9c9d commit 21dd02a

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

geonode/documents/enumerations.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,14 @@
3232
"xls": "text",
3333
"xlsx": "text",
3434
"xml": "text",
35-
"bm": "image",
36-
"bmp": "image",
3735
"dwg": "archive",
3836
"dxf": "archive",
39-
"fif": "image",
4037
"gif": "image",
4138
"jpg": "image",
42-
"jpe": "image",
4339
"jpeg": "image",
4440
"png": "image",
45-
"tif": "archive",
46-
"tiff": "archive",
41+
"tif": "image",
42+
"tiff": "image",
4743
"pbm": "archive",
4844
"odp": "presentation",
4945
"ppt": "presentation",

geonode/documents/exif/utils.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#
1818
#########################################################################
1919

20-
import os
2120
import logging
2221

2322
from slugify import slugify
@@ -70,13 +69,14 @@ def exif_extract_metadata_doc(doc):
7069
return None
7170

7271
file_path = doc.files[0]
73-
_, ext = os.path.splitext(os.path.basename(file_path))
7472

75-
if ext[1:] in {"jpg", "jpeg", "png"}:
73+
if doc.is_image:
7674
from PIL import Image, ExifTags
7775

7876
img = Image.open(file_path)
79-
exif_data = {ExifTags.TAGS[k]: v for k, v in img._getexif().items() if k in ExifTags.TAGS}
77+
exif = img.getexif()
78+
# Main EXIF tags
79+
exif_data = {ExifTags.TAGS[k]: v for k, v in exif.items() if k in ExifTags.TAGS}
8080

8181
model = None
8282
date = None
@@ -86,6 +86,12 @@ def exif_extract_metadata_doc(doc):
8686
lon = None
8787
abstract = None
8888

89+
# Get Exif IFD for DateTimeOriginal etc.
90+
exif_ifd = exif.get_ifd(ExifTags.IFD.Exif)
91+
if exif_ifd:
92+
exif_ifd_data = {ExifTags.TAGS.get(k, k): v for k, v in exif_ifd.items()}
93+
exif_data.update(exif_ifd_data)
94+
8995
if "DateTime" in exif_data:
9096
date = exif_data["DateTime"]
9197
elif "DateTimeOriginal" in exif_data:
@@ -107,11 +113,13 @@ def exif_extract_metadata_doc(doc):
107113
model = exif_data.get("Model", None)
108114
keywords.append(slugify(model))
109115

110-
if "GPSInfo" in exif_data:
116+
# Get GPS IFD for GPS data
117+
gps_ifd = exif.get_ifd(ExifTags.IFD.GPSInfo)
118+
if gps_ifd:
111119
gpsinfo = {}
112-
for key in exif_data["GPSInfo"].keys():
120+
for key in gps_ifd.keys():
113121
decode = ExifTags.GPSTAGS.get(key, key)
114-
gpsinfo[decode] = exif_data["GPSInfo"][key]
122+
gpsinfo[decode] = gps_ifd[key]
115123
if "GPSLatitude" in gpsinfo and "GPSLongitude" in gpsinfo:
116124
lat = convertExifLocationToDecimalDegrees(gpsinfo["GPSLatitude"], gpsinfo.get("GPSLatitudeRef", "N"))
117125
lon = convertExifLocationToDecimalDegrees(gpsinfo["GPSLongitude"], gpsinfo.get("GPSLongitudeRef", "E"))

0 commit comments

Comments
 (0)