def readGif(filename, asNumpy=True):
""" readGif(filename, asNumpy=True)
Read images from an animated GIF file. Returns a list of numpy
arrays, or, if asNumpy is false, a list if PIL images.
"""
# Check PIL
if PIL is None:
raise RuntimeError("Need PIL to read animated gif files.")
# Check Numpy
if np is None:
raise RuntimeError("Need Numpy to read animated gif files.")
# Check whether it exists
if not os.path.isfile(filename):
raise IOError('File not found: '+str(filename))
# Load file using PIL
pilIm = PIL.Image.open(filename)
pilIm
# Read all images inside
images = []
try:
while True:
# Get image as numpy array
tmp = pilIm.convert() # Make without palette
a = np.asarray(tmp)
if len(a.shape)==0:
raise MemoryError("Too little memory to convert PIL image to array")
# Store, and next
images.append(a)
pilIm.seek(pilIm.tell()+1)
except EOFError:
pass
# Convert to normal PIL images if needed
if not asNumpy:
images2 = images
images = []
for im in images2:
images.append( PIL.Image.fromarray(im) )
# Done
return images
No ale leciałem też po samych seed i je zapisywałem czyli powiedzmy
im = Image.open('obrazek.gif')
frame = im.seed(0)
frame.save('obr1.gif')
frame im.seed(1)
frame.save('obr2.gif')
frame im.seed(2)
frame.save('obr3.gif')
pierwszy obrazek jest ok, reszta się krzaczy, nie wiem czy to jest wina zapisu i specyficzności danego pliku gif, czy jest coś z PIL nie tak, no ale chodzi o to żeby to zniwelować