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

emoji: Add support for animated GIF images. #9968

Merged
merged 1 commit into from
Aug 4, 2018

Conversation

HarshitOnGitHub
Copy link
Member

This commit adds 'resize_gif()' function which extracts each frame,
resize it and coalesces them again to form the resized GIF while
preserving the duration of the GIF. I read some stackoverflow
answers all of which were referring to BiggleZX's script
(https://gist.github.com/BigglesZX/4016539) for working with animated
GIF. I modified the script to fit to our usecase and did some manual
testing but the function was failing for some specific GIFs and was not
preserving the duration of animation. So I went ahead and read about
GIF format itself as well as PIL's GifImagePlugin code and came up
with this simple function which gets the worked done in a much cleaner
way. It tested this function on a number of GIF images from giphy.com
and it resized all of them correctly.

Fixes: #9945.

@zulipbot zulipbot added size: M area: emoji Emoji in markup, emoji reactions, emoji picker, etc. labels Jul 18, 2018
@zulipbot
Copy link
Member

Hello @zulip/server-emoji members, this pull request was labeled with the "area: emoji" label, so you may want to check it out!

@HarshitOnGitHub
Copy link
Member Author

@timabbott FYI. Mypy is complaining because there are no stub files available for GifImagePlugin.

@HarshitOnGitHub
Copy link
Member Author

@timabbott Gentle ping on this. What can I do to fix the mypy issue?

@timabbott
Copy link
Sponsor Member

For the mypy error, there are two options. Either edit mypy.ini to add an ignore_missing_imports block, or add stubs like what we have in the stubs/ directory, for the PIL function we're using.

This commit adds 'resize_gif()' function which extracts each frame,
resize it and coalesces them again to form the resized GIF while
preserving the duration of the GIF. I read some stackoverflow
answers all of which were referring to BiggleZX's script
(https://gist.github.com/BigglesZX/4016539) for working with animated
GIF. I modified the script to fit to our usecase and did some manual
testing but the function was failing for some specific GIFs and was not
preserving the duration of animation. So I went ahead and read about
GIF format itself as well as PIL's `GifImagePlugin` code and came up
with this simple function which gets the worked done in a much cleaner
way. I tested this function on a number of GIF images from giphy.com
and it resized all of them correctly.

Fixes: zulip#9945.
@timabbott
Copy link
Sponsor Member

Nice, merged, thanks @HarshitOnGitHub!

@julievalet
Copy link

Nice job on the resizing !
One question: it was working fine for a while and now, every time I upload a new custom GIF emoji, the background, which should be transparent, is now black.
Do you think it would come from the resizing which doesn't keep the alpha ?

@timabbott
Copy link
Sponsor Member

That seems quite likely. @julievalet can you open a new issue for that and mention @HarshitOnGitHub on the thread?

@julievalet
Copy link

julievalet commented Aug 17, 2018

Here is the created issue : #10351

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: emoji Emoji in markup, emoji reactions, emoji picker, etc. size: L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants