Repository navigation
Is there a way to save a coalesced gif? #7145
|
Hi All, I'm working on a project that requires fully coalesced gifs. Based on this gist, I'm able to confirm that I'm saving a non-coalesced gif. Is there a current way to achieve this? If not, any ideas on what would need modification to allow this? My code: from PIL import Image as PilImage
first = PilImage.open(image_files[0])
sequence = []
for i in range(1, len(image_files)):
sequence.append(PilImage.open(image_files[i]))
first.save('pillow-out.gif',
save_all=True,
append_images=sequence,
optimize=False,
compress_level=0) |
Replies: 2 comments 4 replies
|
The gist you linked to is 11 years old. We've significantly improved our reading of GIFs since then, so if you want to extract all of the frames from a GIF, you should no longer have to be concerned about pasting and palettes. You should just be able to from PIL import Image, ImageSequence
with Image.open("pillow-out.gif") as im:
for i, frame in enumerate(ImageSequence.Iterator(im)):
frame.save(str(i)+".png")But your actual question is about saving. Sorry, I don't know exactly what you mean when you say 'coalesced'. Could you describe that in more detail for me? At the moment, I see 25 frames of the number 72 shrinking and then expanding again. What are you hoping to see? Ideally, if you could attach your input images ( |
|
I think you're talking about the disposal method used. You can set this when saving. I think you probably want method 0. https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#gif-saving |


Ah, ok. It's not possible to do this using Pillow's public API. However, you can workaround that by adding in the following code when generating your image.