mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-16 18:24:45 +03:00
Restored __array__ for libraries that do not support __array_interface__
This commit is contained in:
parent
92b0f2c919
commit
d871ef51df
|
@ -94,3 +94,10 @@ def test_fromarray_palette():
|
||||||
|
|
||||||
# Assert that the Python and C palettes match
|
# Assert that the Python and C palettes match
|
||||||
assert len(out.palette.colors) == len(out.im.getpalette()) / 3
|
assert len(out.palette.colors) == len(out.im.getpalette()) / 3
|
||||||
|
|
||||||
|
|
||||||
|
def test_array():
|
||||||
|
i = im.convert("L")
|
||||||
|
a = numpy.array(i)
|
||||||
|
|
||||||
|
assert (a == i.__array__()).all()
|
||||||
|
|
|
@ -671,6 +671,11 @@ class Image:
|
||||||
raise ValueError("Could not save to PNG for display") from e
|
raise ValueError("Could not save to PNG for display") from e
|
||||||
return b.getvalue()
|
return b.getvalue()
|
||||||
|
|
||||||
|
def __array__(self, dtype=None):
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
return np.array(self, dtype)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def __array_interface__(self):
|
def __array_interface__(self):
|
||||||
# numpy array interface support
|
# numpy array interface support
|
||||||
|
|
Loading…
Reference in New Issue
Block a user