diff --git a/geonode/documents/enumerations.py b/geonode/documents/enumerations.py index 8b270b75558..d462770f5ab 100644 --- a/geonode/documents/enumerations.py +++ b/geonode/documents/enumerations.py @@ -32,18 +32,14 @@ "xls": "text", "xlsx": "text", "xml": "text", - "bm": "image", - "bmp": "image", "dwg": "archive", "dxf": "archive", - "fif": "image", "gif": "image", "jpg": "image", - "jpe": "image", "jpeg": "image", "png": "image", - "tif": "archive", - "tiff": "archive", + "tif": "image", + "tiff": "image", "pbm": "archive", "odp": "presentation", "ppt": "presentation", @@ -89,13 +85,9 @@ "xls": "application/excel", "xlsx": "application/vnd.ms-excel", "xml": "application/xml", - "bm": "image/bmp", - "bmp": "image/bmp", "dwg": "image/vnd.dwg", "dxf": "image/vnd.dwg", - "fif": "image/fif", "gif": "image/gif", - "jpe": "image/jpeg", "jpg": "image/jpeg", "jpeg": "image/jpeg", "png": "image/png", diff --git a/geonode/documents/exif/utils.py b/geonode/documents/exif/utils.py index 684c9908883..50bb2188e40 100644 --- a/geonode/documents/exif/utils.py +++ b/geonode/documents/exif/utils.py @@ -17,7 +17,6 @@ # ######################################################################### -import os import logging from slugify import slugify @@ -70,13 +69,14 @@ def exif_extract_metadata_doc(doc): return None file_path = doc.files[0] - _, ext = os.path.splitext(os.path.basename(file_path)) - if ext[1:] in {"jpg", "jpeg", "png"}: + if doc.is_image: from PIL import Image, ExifTags img = Image.open(file_path) - exif_data = {ExifTags.TAGS[k]: v for k, v in img._getexif().items() if k in ExifTags.TAGS} + exif = img.getexif() + # Main EXIF tags + exif_data = {ExifTags.TAGS[k]: v for k, v in exif.items() if k in ExifTags.TAGS} model = None date = None @@ -86,6 +86,12 @@ def exif_extract_metadata_doc(doc): lon = None abstract = None + # Get Exif IFD for DateTimeOriginal etc. + exif_ifd = exif.get_ifd(ExifTags.IFD.Exif) + if exif_ifd: + exif_ifd_data = {ExifTags.TAGS.get(k, k): v for k, v in exif_ifd.items()} + exif_data.update(exif_ifd_data) + if "DateTime" in exif_data: date = exif_data["DateTime"] elif "DateTimeOriginal" in exif_data: @@ -107,11 +113,13 @@ def exif_extract_metadata_doc(doc): model = exif_data.get("Model", None) keywords.append(slugify(model)) - if "GPSInfo" in exif_data: + # Get GPS IFD for GPS data + gps_ifd = exif.get_ifd(ExifTags.IFD.GPSInfo) + if gps_ifd: gpsinfo = {} - for key in exif_data["GPSInfo"].keys(): + for key in gps_ifd.keys(): decode = ExifTags.GPSTAGS.get(key, key) - gpsinfo[decode] = exif_data["GPSInfo"][key] + gpsinfo[decode] = gps_ifd[key] if "GPSLatitude" in gpsinfo and "GPSLongitude" in gpsinfo: lat = convertExifLocationToDecimalDegrees(gpsinfo["GPSLatitude"], gpsinfo.get("GPSLatitudeRef", "N")) lon = convertExifLocationToDecimalDegrees(gpsinfo["GPSLongitude"], gpsinfo.get("GPSLongitudeRef", "E")) diff --git a/geonode/documents/tests.py b/geonode/documents/tests.py index 32c5743a9bd..2b16c146fd8 100644 --- a/geonode/documents/tests.py +++ b/geonode/documents/tests.py @@ -106,8 +106,8 @@ def test_document_mimetypes_rendering(self): # Make sure we won't have template rendering issues self.assertTrue("dwg" in ARCHIVETYPES) self.assertTrue("dxf" in ARCHIVETYPES) - self.assertTrue("tif" in ARCHIVETYPES) - self.assertTrue("tiff" in ARCHIVETYPES) + self.assertTrue("tif" in IMGTYPES) + self.assertTrue("tiff" in IMGTYPES) self.assertTrue("pbm" in ARCHIVETYPES) @patch("geonode.documents.tasks.create_document_thumbnail")