2 years ago
#38184

moolenschot
TypeError: 'PngImageFile' object is not subscriptable
I'm trying to make a looping GIF out of multiple images from a folder called 'images'. But I'm getting the following error:
Traceback (most recent call last):
File "/Users/sem/Desktop/gif/main.py", line 16, in <module>
frame[0].save('result.gif', format='GIF', append_images=frames[1:], save_all=True, duration=230, loop=0)
TypeError: 'PngImageFile' object is not subscriptable
Does anyone know how to solve this problem? Here is the code I used:
import requests, random, urllib, os
from PIL import Image
import glob
frames = []
images = []
glob = glob.glob('*.png')
for x in os.listdir('images'):
images.append(os.path.dirname(os.path.abspath(__file__)) + '/images/' + x)
for x in images:
frame = Image.open(x)
frames.append(frame)
frame[0].save('result.gif', format='GIF', append_images=frames[1:], save_all=True, duration=230, loop=0)
python
image
gif
0 Answers
Your Answer