Added support for 1-D NumPy arrays

This commit is contained in:
Andrew Murray 2020-05-04 20:07:23 +10:00
parent d23df7227c
commit 59957fb8d8
2 changed files with 6 additions and 1 deletions

View File

@ -89,6 +89,11 @@ def test_3d_array():
assert_image(Image.fromarray(a[:, :, 1]), "L", TEST_IMAGE_SIZE)
def test_1d_array():
a = numpy.ones(5, dtype=numpy.uint8)
assert_image(Image.fromarray(a), "L", (1, 5))
def _test_img_equals_nparray(img, np):
assert len(np.shape) >= 2
np_size = np.shape[1], np.shape[0]

View File

@ -2727,7 +2727,7 @@ def fromarray(obj, mode=None):
if ndim > ndmax:
raise ValueError("Too many dimensions: %d > %d." % (ndim, ndmax))
size = shape[1], shape[0]
size = 1 if ndim == 1 else shape[1], shape[0]
if strides is not None:
if hasattr(obj, "tobytes"):
obj = obj.tobytes()