mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Merge pull request #225 from wiredfool/pr224
Fix Image.fromarray with NumPy arrays: Supersedes PR #224
This commit is contained in:
commit
a9fd1f4a94
|
@ -1932,7 +1932,10 @@ def fromarray(obj, mode=None):
|
|||
|
||||
size = shape[1], shape[0]
|
||||
if strides is not None:
|
||||
obj = obj.tobytes()
|
||||
if hasattr(obj, 'tobytes'):
|
||||
obj = obj.tobytes()
|
||||
else:
|
||||
obj = obj.tostring()
|
||||
|
||||
return frombuffer(mode, size, obj, "raw", rawmode, 0, 1)
|
||||
|
||||
|
|
|
@ -54,3 +54,11 @@ def test_numpy_to_image():
|
|||
|
||||
assert_image(to_image(numpy.uint8, 3), "RGB", (10, 10))
|
||||
assert_image(to_image(numpy.uint8, 4), "RGBA", (10, 10))
|
||||
|
||||
|
||||
# based on an erring example at http://is.gd/6F0esS
|
||||
def test_3d_array():
|
||||
a = numpy.ones((10, 10, 10), dtype=numpy.uint8)
|
||||
assert_image(Image.fromarray(a[1, :, :]), "L", (10, 10))
|
||||
assert_image(Image.fromarray(a[:, 1, :]), "L", (10, 10))
|
||||
assert_image(Image.fromarray(a[:, :, 1]), "L", (10, 10))
|
||||
|
|
Loading…
Reference in New Issue
Block a user