Skip to content

Commit

Permalink
Support HEIF image file (#1042)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandede committed Oct 31, 2023
1 parent 01a9bff commit 6cd3e2d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions imageio/config/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,9 @@ def reset(self):
extension=".btf",
priority=["tifffile"],
),
FileExtension(
name="High Efficiency Image File Format", extension=".heic", priority=["pillow"]
),
]
extension_list.sort(key=lambda x: x.extension)

Expand Down
8 changes: 8 additions & 0 deletions imageio/plugins/pillow.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ def __init__(self, request: Request) -> None:

super().__init__(request)

# Register HEIF opener for Pillow
try:
from pillow_heif import register_heif_opener
except ImportError:
pass
else:
register_heif_opener()

self._image: Image = None
self.images_to_write = []

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"swf": [],
"tifffile": ["tifffile"],
"pyav": ["av"],
"heif": ["pillow-heif"],
}

cpython_only_plugins = {
Expand Down
7 changes: 7 additions & 0 deletions tests/test_pillow.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,3 +705,10 @@ def test_writable_output():

frame = iio.imread(buffer, writeable_output=False, plugin="pillow")
assert not frame.flags["WRITEABLE"]


@pytest.mark.needs_internet
def test_heif_remote():
url = "http://github.com/tigranbs/test-heic-images/raw/master/image4.heic"
im = iio.imread(url, plugin="pillow")
assert im.shape == (476, 700, 4)

0 comments on commit 6cd3e2d

Please sign in to comment.