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

image/gif: decoding then encoding an animated GIF likely to increase its size #22137

jeddenlea opened this issue Oct 4, 2017 · 2 comments


Copy link

@jeddenlea jeddenlea commented Oct 4, 2017

image/gif decodes a GIF, which contains an []*image.Paletted that holds each frame. When decoded, if a frame has a transparent color and uses the global palette, a copy of the global []color.Color is made, and the transparency color index is replaced with color.RGBA{}.

When encoding a GIF, each frame's palette is encoded to the form it might exist in a GIF, up to 768 bytes "RGBRGBRGBRGB...". If a frame's encoded palette is equal to the encoded global color table, the frame will be encoded with the flag set to use the global color table, otherwise the frame's palette will be included.

So, if the color in the global color table that matches the transparent index of one frame wasn't black (and it frequently is not), reencoding a GIF will likely result in a larger file because each frame's palette will have to be encoded inline.

A working CL will be posted shortly.

Copy link

@gopherbot gopherbot commented Oct 4, 2017

Change mentions this issue: image/gif: try harder to use global color table


Copy link

@dsnet dsnet commented Oct 5, 2017

\cc @nigeltao


@gopherbot gopherbot closed this in 31cd20a Oct 13, 2017
@golang golang locked and limited conversation to collaborators Oct 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants