I want to use the images stored in a dictionary, to convert it to a GIF. The images in the dictionary is like this type:
people={
1: <PIL.Image.Image image mode=RGBA size=16x16 at 0x10962C510>,
2: <PIL.Image.Image image mode=RGBA size=16x16 at 0x1098D7F90>,
3: <PIL.Image.Image image mode=RGBA size=16x16 at 0x1098D7F50>}
I think is a Pillow image. But why do I always get this error:
'Image' object has no attribute 'read'
What does it mean?
The full error:
File "/***view.py", line 266, in convert_gif
new_frame = Image.open(imgs[count])
File "/***/python3.7/site-packages/PIL/Image.py", line 2775, in open
prefix = fp.read(16)
AttributeError: 'Image' object has no attribute 'read' –
The code:
self._images = {
people: {
1: <PIL.Image.Image image mode=RGBA size=16x16 at 0x10962C510>,
2: <PIL.Image.Image image mode=RGBA size=16x16 at 0x1098D7F90>,
3: <PIL.Image.Image image mode=RGBA size=16x16 at 0x1098D7F50>
}
}
def convert_gif(self):
imgs = self._images["people"]
number = len(imgs)
count=1
while count <= number:
new_frame = Image.open(imgs[count])
self._frames.append(new_frame)
count += 1
self._frames[0].save('png_to_gif.gif', format='GIF', append_images=self._frames[1:], save_all=True, duration=300, loop=0)