From d0c0c8fb2514585861603f4d28f8107e0b664a29 Mon Sep 17 00:00:00 2001 From: Isotr0py <2037008807@qq.com> Date: Sun, 28 Jan 2024 11:56:50 +0800 Subject: [PATCH] support pillow>10.1 --- pillow_jxl/JpegXLImagePlugin.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pillow_jxl/JpegXLImagePlugin.py b/pillow_jxl/JpegXLImagePlugin.py index 1c69079..2e5b192 100644 --- a/pillow_jxl/JpegXLImagePlugin.py +++ b/pillow_jxl/JpegXLImagePlugin.py @@ -1,5 +1,9 @@ from io import BytesIO + +import PIL from PIL import Image, ImageFile +from pkg_resources import parse_version + from pillow_jxl import Decoder, Encoder _VALID_JXL_MODES = {"RGB", "RGBA", "L", "LA"} @@ -24,10 +28,14 @@ def _open(self): self._decoder = Decoder() self._jxlinfo, self._data = self._decoder(self.fc) - # self._size = (self._jxlinfo['width'], self._jxlinfo['height']) - # self.mode = self.rawmode = self._jxlinfo["mode"] self._size = (self._jxlinfo.width, self._jxlinfo.height) - self.mode = self.rawmode = self._jxlinfo.mode + self.rawmode = self._jxlinfo.mode + # NOTE (Isotr0py): PIL 10.1.0 changed the mode to property, use _mode instead + if parse_version(PIL.__version__) >= parse_version("10.1.0"): + self._mode = self.rawmode + else: + self.mode = self.rawmode + self.tile = [] def seek(self, frame):