I am using Python 3.6 and Pillow 4.0.0
I am trying to make a PIL Image from an array of values, see the simplified code below and I am getting the following error: AttributeError: 'array.array' object has no attribute '__array_interface__' when calling the Image.fromarray() function.
Why does this happen? When PIL documentation says: Creates an image memory from an object exporting the array interface (using the buffer protocol). and array.array documentations says: Array objects also implement the buffer interface, and may be used wherever bytes-like objects are supported...
from PIL import Image
from array import array
arr = array('B', [100, 150, 200, 250])
im = Image.fromarray(arr)
im.show()
The array interface is a NumPy concept: ref. Said differently, Image.fromarray can only operate on numpy arrays and not on Standard Python Library array.array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With