This commit is contained in:
Matt Davis 2013-05-22 09:29:46 -07:00
commit 6f3f916514
2 changed files with 9 additions and 1 deletions

View File

@ -1944,7 +1944,7 @@ def fromarray(obj, mode=None):
size = shape[1], shape[0] size = shape[1], shape[0]
if strides is not None: if strides is not None:
obj = obj.tobytes() obj = obj.tostring()
return frombuffer(mode, size, obj, "raw", rawmode, 0, 1) return frombuffer(mode, size, obj, "raw", rawmode, 0, 1)

View File

@ -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, 3), "RGB", (10, 10))
assert_image(to_image(numpy.uint8, 4), "RGBA", (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))