Skip to content

Instantly share code, notes, and snippets.

@egocarib
egocarib / gist:ea022799cca8a102d14c54a22c45efe0
Created October 22, 2020 01:50
pillow transparent gif creation workaround
# This code adapted from https://github.com/python-pillow/Pillow/issues/4644 to resolve an issue
# described in https://github.com/python-pillow/Pillow/issues/4640
#
# There is a known issue with the Pillow library that messes up GIF transparency by replacing the
# transparent pixels with black pixels (among other issues) when the GIF is saved using PIL.Image.save().
# This code works around the issue and allows us to properly generate transparent GIFs.
from typing import Tuple, List, Union
from collections import defaultdict
from random import randrange