From 89eddd360806804eb89ea82f04e33487ff599a9e Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Tue, 16 Jul 2024 19:22:58 +0100 Subject: [PATCH] fix: rotate images on acquisition of source --- iiif/utils.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/iiif/utils.py b/iiif/utils.py index beb1b8f..080bd0f 100644 --- a/iiif/utils.py +++ b/iiif/utils.py @@ -14,7 +14,7 @@ import aiohttp import humanize -from PIL import Image +from PIL import Image, ImageOps from jpegtran import JPEGImage mimetypes.init() @@ -119,13 +119,8 @@ 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) + ImageOps.exif_transpose(image, in_place=True) image = image.convert(mode='RGB') image.save(target_path, format='jpeg', quality=quality, subsampling=subsampling)