-
Notifications
You must be signed in to change notification settings - Fork 321
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
Support for animated formats (gif/webp/apng) #628
Conversation
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? |
...also, will remove _call_pil_method soon. |
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? |
...remaining to add: docs. Also, I would add |
...also, docs: how to make them work again? |
@SmileyChris feedback welcome :) or maybe shall I reach out to @jrief ? |
@benzkji Hi Ben, you're changing code and code-styling in the same pull request. This makes a review extremly difficult to understand. Can this be split into separate PRs? And btw., I prefer single quotes for strings which are not read by humans, but this is my personal opinion. |
@jrief Hi Jacob. Sorry, that slipped in, I probably had black active on save. Will try to revert these changes. |
things remaining (code style is reverted):
|
real world feedback with django-filer:
|
Thinking about it, it would be nice if one could define if animations should be preserved, when using easy-thumbnails...not an "always on/off" solution, but rather some kind of |
if anyone interested:
|
but, without "save_all" enabled for everyone automatically, I guess this could be released as a beta, if no issues arise. People could check manually, with preserve extensions and save_all, if it works. hopefully no existing features would be broken, aka we have a testsuite - I don't know how extensive it is?! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this improvement.
Would be great if you could add a few lines of documentation and mention this feature in the ChangeLog.
easy_thumbnails/processors.py
Outdated
@@ -108,7 +149,8 @@ def autocrop(im, autocrop=False, **kwargs): | |||
bg = Image.new('L', im.size, 255) | |||
bbox = ImageChops.difference(bw, bg).getbbox() | |||
if bbox: | |||
im = im.crop(bbox) | |||
# im = im.crop(bbox) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove commented code
easy_thumbnails/processors.py
Outdated
@@ -274,7 +318,9 @@ def scale_and_crop(im, size, crop=False, upscale=False, zoom=None, target=None, | |||
diff_y = diff_y - add - remove | |||
box = (left, top, right, bottom) | |||
# Finally, crop the image! | |||
im = im.crop(box) | |||
# im = im.crop(box) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
detto
@jrief done so (docs & changelog). BTW, do you know what must be done to get readthedocs up and running again? https://easy-thumbnails.readthedocs.io/en/latest/ is for 2.7, no word of SVG et al? |
ah, shall I merge master into my branch? My current local tests are passing (without python3.7 ;), but that's not up to date at all. |
thx. will check the testsuite. |
@benzkji I assume that the local behavior of colorspace is different from what the tests on GitHub-Actions tell us. Any idea what could be the problem? |
not yet. After the merge it fails localy on my machine as well. |
test pass now. it is strange, though, it seems PIL eliminates empty frames. but also, my test PNG and WEBPs seem empty (when saving them out), but when using filer it works, and in tests it works as well, now. Looks like a "writing the tests is the hardest part" problem. I must say that I'm not really familiar with creating images from within PIL, so this could be the issue. |
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
And animated GIFs work (on my machine), hopefully animated WEBP would as well. A first feedback for the approach is very welcome.