Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for animated formats (gif/webp/apng) #628

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

benzkji
Copy link

@benzkji benzkji commented Feb 5, 2024

A first draft. Test still passing, no new tests for the moment.

I don't think that a wrapper (processors leaving as is, abstract things away for processors) would be a good solution, as some processors could still not operate like this. For example, the autocrop would autocrop each frame individually, and if a processor creates a new Image(), and pastes the original into it, frames would still be lost - as the background processor does it.

With my proposal, animated GIF support would need to be supported by each processor individually. Most of the times, this would mean a simple usage of the new helper function instead of directly calling im.whatever().

Using

THUMBNAIL_IMAGE_SAVE_OPTIONS = {
    "GIF": {"save_all": True}, 
}
THUMBNAIL_PRESERVE_EXTENSIONS = ("gif", )

And animated GIFs work (on my machine), hopefully animated WEBP would as well. A first feedback for the approach is very welcome.

@benzkji
Copy link
Author

benzkji commented Feb 19, 2024

I've had to add a BytesIO use, did not work otherwise. I've tried many things to treat the file in place, but it's not working till now...even asked on SO: https://stackoverflow.com/questions/78020254/python-pillow-treat-an-animated-gif-or-webp-in-place

Feedback welcome, I'm not so sure about not leaving open file pointers around?

@benzkji
Copy link
Author

benzkji commented Feb 19, 2024

...also, will remove _call_pil_method soon.

@benzkji
Copy link
Author

benzkji commented Feb 19, 2024

It has tests now, for all builtin processors. Though, it only tests if frames are preserved, and some of the basic functionalities (as resize/crop) - I'm afraid I don't fully understand all of the processors, and especially not all of the edge cases involved.

If the used BytesIO workaround is ok for @SmileyChris I think it could be merged?

@benzkji
Copy link
Author

benzkji commented Feb 19, 2024

...remaining to add: docs. Also, I would add save_all=True for all images with more than one frame, it would be better to support them without having to set/use THUMBNAIL_IMAGE_SAVE_OPTIONS.

@benzkji
Copy link
Author

benzkji commented Feb 20, 2024

...also, docs: how to make them work again?

@benzkji benzkji changed the title anigif (and probably webp) support WIP Support for animated formats (gif/webp/apng) Feb 27, 2024
@benzkji
Copy link
Author

benzkji commented Mar 8, 2024

@SmileyChris feedback welcome :) or maybe shall I reach out to @jrief ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants