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

fix: rotate images on source acquisition #51

Merged
merged 2 commits into from
Jul 22, 2024
Merged
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
11 changes: 4 additions & 7 deletions iiif/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import aiohttp
import humanize
from PIL import Image
from PIL import Image, ImageOps
from jpegtran import JPEGImage

mimetypes.init()
Expand Down Expand Up @@ -119,14 +119,11 @@ def convert_image(image_path: Path, target_path: Path, quality: int = 80,
# given this is usually run in a separate process, make sure we have disabled bomb errors
disable_bomb_errors()
with Image.open(image_path) as image:
if image.format.lower() == 'jpeg':
exif = image.getexif()
# this is the orientation tag, remove it if it's there
exif.pop(0x0112, None)
image.info['exif'] = exif.tobytes()

target_path.parent.mkdir(parents=True, exist_ok=True)
# do this before exif_transpose to ensure tiffs get loaded and oriented before
# we auto-orient based on exif
image = image.convert(mode='RGB')
image = ImageOps.exif_transpose(image)
image.save(target_path, format='jpeg', quality=quality, subsampling=subsampling)


Expand Down
Loading