From f67decf7e936434d50b5493f4cef22e07e018ef5 Mon Sep 17 00:00:00 2001 From: yashlamba Date: Thu, 4 Jul 2024 16:03:09 +0200 Subject: [PATCH] tiles: don't process images <= tile dimensions --- invenio_rdm_records/config.py | 7 ++++++- invenio_rdm_records/records/processors/tiles.py | 13 ++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/invenio_rdm_records/config.py b/invenio_rdm_records/config.py index 0a106063c..52a9cc67c 100644 --- a/invenio_rdm_records/config.py +++ b/invenio_rdm_records/config.py @@ -597,7 +597,12 @@ def lock_edit_published_files(service, identity, record=None, draft=None): Relative paths are resolved against the application instance path. """ -IIIF_TILES_CONVERTER_PARAMS = {} +IIIF_TILES_CONVERTER_PARAMS = { + "compression": "jpeg", + "Q": 90, + "tile_width": 256, + "tile_height": 256, +} """Parameters to be passed to the tiles converter.""" RDM_RECORDS_RESTRICTION_GRACE_PERIOD = timedelta(days=30) diff --git a/invenio_rdm_records/records/processors/tiles.py b/invenio_rdm_records/records/processors/tiles.py index 279f87615..20ee53aed 100644 --- a/invenio_rdm_records/records/processors/tiles.py +++ b/invenio_rdm_records/records/processors/tiles.py @@ -43,7 +43,18 @@ def _can_process(self, draft, record) -> bool: def _can_process_file(self, file_record, draft, record) -> bool: """Checks to determine if to process the record.""" - return file_record.file.ext in self.valid_exts + if file_record.file.ext not in self.valid_exts: + return False + + iiif_config = current_app.config.get("IIIF_TILES_CONVERTER_PARAMS") + metadata = file_record.metadata or {} + + if (metadata.get("height", 0) <= iiif_config.get("tile_width")) or ( + metadata.get("width", 0) <= iiif_config.get("tile_height") + ): + return False + + return True @contextmanager def unlocked_bucket(self, files):