Skip to content

Commit

Permalink
Add support for EXIF data in .heic files
Browse files Browse the repository at this point in the history
  • Loading branch information
ususdei committed May 26, 2024
1 parent 2ae9886 commit 6210bf4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/sigal/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def exif(self):
datetime_format = self.settings["datetime_format"]
return (
get_exif_tags(self.raw_exif, datetime_format=datetime_format)
if self.raw_exif and self.src_ext in (".jpg", ".jpeg")
if self.raw_exif and self.src_ext in (".jpg", ".jpeg", ".heic")
else None
)

Expand All @@ -289,7 +289,7 @@ def _get_markdown_metadata(self):
@cached_property
def raw_exif(self):
"""If not `None`, contains the raw EXIF tags."""
if self.src_ext in (".jpg", ".jpeg"):
if self.src_ext in (".jpg", ".jpeg", ".heic"):
return self.file_metadata["exif"]

@cached_property
Expand Down
8 changes: 6 additions & 2 deletions src/sigal/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ def get_exif_data(filename):

try:
with warnings.catch_warnings(record=True) as caught_warnings:
exif = img._getexif() or {}
exif = {}
if hasattr(img, "_getexif") and callable(img._getexif):
exif = img._getexif()
elif "exif" in img.info:
exif = img.getexif()._get_merged_dict()
except ZeroDivisionError:
logger.warning("Failed to read EXIF data.")
return None
Expand Down Expand Up @@ -295,7 +299,7 @@ def get_image_metadata(filename):
logger.error("Could not open image %s metadata: %s", filename, e)
else:
try:
if os.path.splitext(filename)[1].lower() in (".jpg", ".jpeg"):
if os.path.splitext(filename)[1].lower() in (".jpg", ".jpeg", ".heic"):
exif = get_exif_data(img)
except Exception as e:
logger.warning("Could not read EXIF data from %s: %s", filename, e)
Expand Down

0 comments on commit 6210bf4

Please sign in to comment.