Skip to content

Commit

Permalink
fixed Image.mode for Pillow 10.1+ (#122)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
  • Loading branch information
bigcat88 committed Aug 3, 2023
1 parent 466a7b9 commit d6e38b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
- `Python 3.12`, `PyPy 3.10` wheels.
- `Depth Image` read support, they are available as a list in `im.info["depth_images"]` #116
- `options.SAVE_NCLX_PROFILE` - default `False` to be full compatible with previous versions, but in next versions may be changed to `True`. #118 Thanks to @wiggin15
- Support for `Pillow 10.1.0`

### Changed

Expand Down
7 changes: 6 additions & 1 deletion pillow_heif/as_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class _LibHeifImageFile(ImageFile.ImageFile):

_heif_file: Union[HeifFile, None] = None
_close_exclusive_fp_after_loading = True
_mode: str # only for Pillow 10.1+

def __init__(self, *args, **kwargs):
self.__frame = 0
Expand Down Expand Up @@ -127,7 +128,11 @@ def _seek_check(self, frame):
def _init_from_heif_file(self, img_index: int) -> None:
if self._heif_file:
self._size = self._heif_file[img_index].size
self.mode = self._heif_file[img_index].mode
if pil_version[:4] not in ("9.1.", "9.2.", "9.3.", "9.4.", "9.5.", "10.0"):
# starting from Pillow 10.1, `mode` is a readonly property.
self._mode = self._heif_file[img_index].mode
else:
self.mode = self._heif_file[img_index].mode
self.info = self._heif_file[img_index].info
self.info["original_orientation"] = set_orientation(self.info)

Expand Down

0 comments on commit d6e38b6

Please sign in to comment.