From fc2629ed9de92ea4fae4ce91119af6fe9f8eae54 Mon Sep 17 00:00:00 2001 From: bunburya Date: Mon, 6 Feb 2023 23:48:16 +0000 Subject: [PATCH] fix handling of large images --- bother_utils/heightmap.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bother_utils/heightmap.py b/bother_utils/heightmap.py index f339f82..d1354a1 100644 --- a/bother_utils/heightmap.py +++ b/bother_utils/heightmap.py @@ -315,6 +315,12 @@ def crop_image(im: Image, width: int, height: int, mode: str) -> Image: box[0] = (im.width - width) // 2 box[2] = box[0] + width + + # Image.crop chokes on large images unless we increase the max size + size = width * height + if size > Image.MAX_IMAGE_PIXELS: + Image.MAX_IMAGE_PIXELS = size + return im.crop(box) def scale_image(im: Image, width: int, height: int) -> Image: