Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect the exif orientation value stored with each image in the mss index #58

Open
wants to merge 1 commit into
base: josh/preps
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions iiif/profiles/mss.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ def __init__(self, source: 'MSSSourceFile', cause: Exception):
super().__init__(f'Failed to convert source image',
log=f'Failed to convert {source.file} ({source.emu_irn}) due to {cause}')

# a set of EXIF orientation values (both raw numbers and textual representations) which,
# if applied to an image, would cause the width and height to swap.
EXIF_ORIENTATION_SWAP_VALUES = {
"5", "Mirror horizontal and rotate 270 CW",
"6", "Rotate 90 CW",
"7", "Mirror horizontal and rotate 90 CW",
"8", "Rotate 270 CW",
}


class MSSImageInfo(ImageInfo):
"""
Expand All @@ -103,6 +112,13 @@ def __init__(self, profile_name: str, name: str, doc: dict):
# a list of the EMu generated derivatives of the original file. The list should already be
# in the ascending (width, height) order because the import process sorts it
self.derivatives = doc.get('derivatives', [])
# exif orientation tag value
self.orientation = doc.get("orientation", None)
if self.orientation in EXIF_ORIENTATION_SWAP_VALUES:
# swap all widths and heights
self.width, self.height = self.height, self.width
for der in self.derivatives:
der["width"], der["height"] = der["height"], der["width"]

def choose_file(self, target_size: Optional[Tuple[int, int]] = None) -> str:
"""
Expand Down
Loading