From e7ab2fe99f11872e6ed2d5a08e7d0d4cc848629a Mon Sep 17 00:00:00 2001 From: Amras Date: Thu, 9 Nov 2023 16:42:43 +0100 Subject: [PATCH] Account for EXIF data during hashing/searching PIL provides built-in support for transposing images based on EXIF Orientation. This change adds that call. --- server/szurubooru/func/image_hash.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/szurubooru/func/image_hash.py b/server/szurubooru/func/image_hash.py index 76d5a846..aa1a0dd8 100644 --- a/server/szurubooru/func/image_hash.py +++ b/server/szurubooru/func/image_hash.py @@ -7,7 +7,7 @@ from typing import Any, Callable, List, Optional, Set, Tuple import HeifImagePlugin import numpy as np import pillow_avif -from PIL import Image +from PIL import Image, ImageOps from szurubooru import config, errors @@ -40,7 +40,7 @@ NpMatrix = np.ndarray def _preprocess_image(content: bytes) -> NpMatrix: try: - img = Image.open(BytesIO(content)) + img = ImageOps.exif_transpose(Image.open(BytesIO(content))) return np.asarray(img.convert("L"), dtype=np.uint8) except (IOError, ValueError): raise errors.ProcessingError(