From c74a855b12dc2cc4a3f6f29b4ffe4b43a8f242d6 Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Sun, 6 Oct 2024 23:22:31 +0300 Subject: [PATCH] reload `Image.core` the same way as in TiffImagePlugin(PIL 11+) (#294) * added reload `Image.core` the same way as in TiffImagePlugin(PIL 11+) * always reload "Image.core" between frames Signed-off-by: Alexander Piskun --------- Signed-off-by: Alexander Piskun --- pillow_heif/as_plugin.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pillow_heif/as_plugin.py b/pillow_heif/as_plugin.py index eb487d8b..fbe3786a 100644 --- a/pillow_heif/as_plugin.py +++ b/pillow_heif/as_plugin.py @@ -92,6 +92,14 @@ def seek(self, frame: int): return self.__frame = frame self._init_from_heif_file(frame) + + if pil_version[:3] != "10.": + # Pillow 11.0+ + # We need to create a new core image object on second and + # subsequent frames in the image. Image may be different size/mode. + # https://github.com/python-pillow/Pillow/issues/8439 + self.im = Image.core.new(self._mode, self._size) # pylint: disable=too-many-function-args + _exif = getattr(self, "_exif", None) # Pillow 9.2+ do no reload exif between frames. if _exif is not None and getattr(_exif, "_loaded", None): _exif._loaded = False # pylint: disable=protected-access