I'd like to get the color palette of each frame of an animated GIF (I'm using ColorThief to generate color palette from an image). I'm using PIL to save each frame as an image, my problem is that the images of most of the frames have strange colors, different from the one you see if you open the GIF on a browser. I guess this is because of the way animated GIF are compressed. I tried to convert every image in RGB but this doesn't solve the problem. How can I render each frame with its intended colors?
To get every frame I'm using the following code:
from PIL import Image, ImageSequence
im = Image.open("phicons/icontech-3-2019-1.gif")
index = 1
for frame in ImageSequence.Iterator(im):
frame.save("phicons/frame%d.gif" % index)
print(frame)
index += 1
This is the image I'm using for test
This is an example of frame with strange colors


This looks like a bug in PIL. It appears not to notice/realise each frame can potentially have a different palette, and indeed, does so in this image.
If you look at the image with ImageMagick you can see it has 54 frames, some with 8, some with 16, some with 32 and some with 64 colours.
Output
And, if you extract all the frames and montage them together with ImageMagick:
If you want to see the palettes of each frame, use:
As an alternative, you may like to have a look at
wandwhich is a Python binding to ImageMagick. You can extract your frames correctly like this: