I have this image with size 128 x 128 pixels and RGBA stored as byte values in my memory. But
from PIL import Image
image_data = ... # byte values of the image
image = Image.frombytes('RGBA', (128,128), image_data)
image.show()
throws the exception
ValueError: not enough image data
Why? What am I doing wrong?
.pngfile has headers and compression and stuff, so I don't think you can feed it intofrombytesand get a coherent result. - KevinImage.open("homer.jpg"), and then calltobyteson it to get a buffer suitable for passing tofrombytes... But there's not much point in doingimage = Image.frombytes(Image.open("homer.jpg").tobytes())when you can just doimage = Image.open("homer.jpg"). I'm assuming your actual use case is more complicated and you can't do the latter for some reason. - Kevin