I have a list of 3-item tuples that is the result of list(PIL.Image.getdata()).
How do I do the opposite: build a PIL.Image object from this list?
I have a list of 3-item tuples that is the result of list(PIL.Image.getdata()).
How do I do the opposite: build a PIL.Image object from this list?
The output of getdata()
does not include the image format or the size, so you'll need to preserve those (or get the information some other way). Then do this, using the putdata()
method:
# get data from old image (as you already did)
data = list(oldimg.getdata())
# create empty new image of appropriate format
newimg = Image.new(format, size) # e.g. ('RGB', (640, 480))
# insert saved data into the image
newimg.putdata(data)