-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
[WIP] Only resize large GIFs when neccessary to avoid breaking alpha #11379
Conversation
zerver/lib/upload.py
Outdated
@@ -35,6 +35,8 @@ | |||
DEFAULT_AVATAR_SIZE = 100 | |||
MEDIUM_AVATAR_SIZE = 500 | |||
DEFAULT_EMOJI_SIZE = 64 | |||
MAX_EMOJI_GIF_SIZE = 128 | |||
MAX_EMOJI_GIF_FILE_SIZE_BYTES = 16 * 1024 * 1024 # 16 kb |
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.
From looking https://slackmojis.com/ (a random website I found with lots of custom emoji), most custom emoji files folks might try to upload are probably bigger than 16KB. Based on that analysis, I think doing something like 128KB as the limit here would be reasonable. 128 seems right for max size.
@moagstar this looks reasonable, thanks for doing this! Can you clean up the linter errors and adjust the constants as suggested above? After those changes, I'm happy to merge this. |
Oh, also, you should clean up the commit message to line-wrap properly and otherwise follow our conventions (compare in |
929a27f
to
db3ac35
Compare
d4dd893
to
1c8fd47
Compare
1c8fd47
to
45a5a94
Compare
…ain circumstances. This additional logic to prevent resizing is certain circumstances (file size, dimensions) is necessary because the pillow gif handling code seems to be rather flaky with regards to handling gif color palletes, causing broken gifs after resizing. The workaround is to only resize when absolutely necessary reducing the chance that gifs get broken.
45a5a94
to
cc2e58c
Compare
@timabbott Thanks for your review and link re commit messages. I have fixed the linter errors and failing test now. |
@moagstar Is there a particular reason that you're resizing any non-square gif? Consider https://slackmojis.com/categories/7-party-parrot-emojis, in which many of the gifs are non-square, but otherwise meet the constraints fine. |
Added some logic to the custom emoji resizing code to prevent resizing in certain circumstances. This is because the pillow gif handling code seems to be rather flaky with regards to handling gif color palletes, causing broken gifs after resizing. The workaround is to only resize when absolutely necessary, which is basically whenever not resizing wouldn't cause bandwidth issues (size, file size). Non square images are always resiezd.
#10351
Testing Plan:
I added some tests to EmojiTest and tested manually.
I discussed this approach on chat.zulip.org and there seems to be consensus that this is a worthwhile approach. Now I am looking for feedback on the actual values chosen.