From fa50ccf0d1deb2d84e810d19409962847a4e241b Mon Sep 17 00:00:00 2001 From: Valentin Rigal <rigal@teklia.com> Date: Wed, 15 Nov 2023 08:55:43 +0000 Subject: [PATCH] Always convert images to RGB mode on Transkribus imports --- arkindex_tasks/import_files/transkribus.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/arkindex_tasks/import_files/transkribus.py b/arkindex_tasks/import_files/transkribus.py index a519d3b1..52e47318 100644 --- a/arkindex_tasks/import_files/transkribus.py +++ b/arkindex_tasks/import_files/transkribus.py @@ -23,10 +23,6 @@ from arkindex_tasks.utils import default_client, retried_request logging.basicConfig(format="[%(levelname)s] %(message)s", level=logging.INFO) logger = logging.getLogger(__name__) -# Image formats that should not be converted before uploading -# see https://pillow.readthedocs.io/en/5.1.x/handbook/image-file-formats.html -VALID_IMAGE_FORMATS = ["JPEG", "JPEG2000", "PNG"] - def hash_file(path) -> str: md5 = hashlib.md5() @@ -70,10 +66,9 @@ class TranskribusElement(object): shutil.copyfileobj(source, destination) with Image.open(img_path) as img: - if img.format not in VALID_IMAGE_FORMATS: - # Convert to RGB if needed - if img.mode != "RGB": - img = img.convert("RGB") + # Convert to RGB if needed + if img.mode != "RGB": + img = img.convert("RGB") # Apply the rotation/transposition from the EXIF orientation tag if it is used img = ImageOps.exif_transpose(img) -- GitLab