From fcbdeb8dbe722c6802e3f51f3d66c2554f63d7d3 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Tue, 25 Apr 2023 15:17:45 -0700 Subject: [PATCH] Fix resampling attributeerror when Pillow < 9.1.0 --- src/ocrmypdf/imageops.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ocrmypdf/imageops.py b/src/ocrmypdf/imageops.py index f15c7517..4f260ca2 100644 --- a/src/ocrmypdf/imageops.py +++ b/src/ocrmypdf/imageops.py @@ -11,6 +11,14 @@ from math import floor, sqrt from PIL import Image +# Remove this workaround when we require Pillow >= 9.1.0 +try: + Resampling = Image.Resampling # type: ignore +except AttributeError: + # Pillow 9 shim + Resampling = Image # type: ignore + + log = logging.getLogger(__name__) @@ -116,7 +124,7 @@ def downsample_image( image: Image.Image, new_size: tuple[int, int], *, - resample_mode: Image.Resampling = Image.Resampling.BICUBIC, + resample_mode: Image.Resampling = Resampling.BICUBIC, reducing_gap: int = 3, ) -> Image.Image: """Downsample an image to fit within the given limits.