From 030c4ecb1bbbb9ec36e477aa408823d4d1ec9db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georg=20W=C3=B6lflein?= Date: Tue, 27 May 2025 18:11:23 +0200 Subject: [PATCH] Fix max text chunk error in PNG metadata --- src/stamp/preprocessing/tiling.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/stamp/preprocessing/tiling.py b/src/stamp/preprocessing/tiling.py index 8df3aaaa..6a7a326e 100644 --- a/src/stamp/preprocessing/tiling.py +++ b/src/stamp/preprocessing/tiling.py @@ -158,7 +158,16 @@ def tiles_with_cache( "w", ) as tile_zip_fp: tile.image.save( - tile_zip_fp, format=EXTENSION_TO_FORMAT[cache_tiles_ext] + tile_zip_fp, + format=EXTENSION_TO_FORMAT[cache_tiles_ext], + **( + # Remove ICC profile for PNG images because that sometimes produces >1MB metadata, + # causing "ValueError: Decompressed data too large for PngImagePlugin.MAX_TEXT_CHUNK". + # Importantly, this does NOT affect the contents of np.array(tile.image). + dict(icc_profile=None) + if cache_tiles_ext == "png" + else {} + ), ) yield tile