mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Load before getting size in __array_interface__
This commit is contained in:
parent
415455d01b
commit
6a931861fe
|
@ -4,7 +4,7 @@ import pytest
|
||||||
|
|
||||||
from PIL import Image
|
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")
|
numpy = pytest.importorskip("numpy", reason="NumPy not installed")
|
||||||
|
|
||||||
|
@ -219,6 +219,13 @@ def test_zero_size():
|
||||||
assert im.size == (0, 0)
|
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():
|
def test_bool():
|
||||||
# https://github.com/python-pillow/Pillow/issues/2044
|
# https://github.com/python-pillow/Pillow/issues/2044
|
||||||
a = numpy.zeros((10, 2), dtype=bool)
|
a = numpy.zeros((10, 2), dtype=bool)
|
||||||
|
|
|
@ -686,11 +686,7 @@ class Image:
|
||||||
@property
|
@property
|
||||||
def __array_interface__(self):
|
def __array_interface__(self):
|
||||||
# numpy array interface support
|
# numpy array interface support
|
||||||
new = {}
|
new = {"version": 3}
|
||||||
shape, typestr = _conv_type_shape(self)
|
|
||||||
new["shape"] = shape
|
|
||||||
new["typestr"] = typestr
|
|
||||||
new["version"] = 3
|
|
||||||
try:
|
try:
|
||||||
if self.mode == "1":
|
if self.mode == "1":
|
||||||
# Binary images need to be extended from bits to bytes
|
# Binary images need to be extended from bits to bytes
|
||||||
|
@ -709,6 +705,7 @@ class Image:
|
||||||
if parse_version(numpy.__version__) < parse_version("1.23"):
|
if parse_version(numpy.__version__) < parse_version("1.23"):
|
||||||
warnings.warn(e)
|
warnings.warn(e)
|
||||||
raise
|
raise
|
||||||
|
new["shape"], new["typestr"] = _conv_type_shape(self)
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user