Fix resampling attributeerror when Pillow < 9.1.0

This commit is contained in:
James R. Barlow
2023-04-25 15:17:45 -07:00
parent cb251a8d03
commit fcbdeb8dbe
+9 -1
View File
@@ -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.