Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Tests/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from PIL import Image

from .helper import assert_deep_equal, assert_image, hopper
from .helper import assert_deep_equal, assert_image, hopper, skip_unless_feature

numpy = pytest.importorskip("numpy", reason="NumPy not installed")

Expand Down Expand Up @@ -219,6 +219,13 @@ def test_zero_size():
assert im.size == (0, 0)


@skip_unless_feature("libtiff")
def test_load_first():
with Image.open("Tests/images/g4_orientation_5.tif") as im:
a = numpy.array(im)
assert a.shape == (88, 590)


def test_bool():
# https://github.com/python-pillow/Pillow/issues/2044
a = numpy.zeros((10, 2), dtype=bool)
Expand Down
7 changes: 2 additions & 5 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,11 +686,7 @@ def _repr_png_(self):
@property
def __array_interface__(self):
# numpy array interface support
new = {}
shape, typestr = _conv_type_shape(self)
new["shape"] = shape
new["typestr"] = typestr
new["version"] = 3
new = {"version": 3}
try:
if self.mode == "1":
# Binary images need to be extended from bits to bytes
Expand All @@ -709,6 +705,7 @@ def __array_interface__(self):
if parse_version(numpy.__version__) < parse_version("1.23"):
warnings.warn(e)
raise
new["shape"], new["typestr"] = _conv_type_shape(self)
return new

def __getstate__(self):
Expand Down