Last active
June 27, 2019 13:41
-
-
Save kevin-keraudren/c6fe8870a12ef300b238d8a5f1c3f071 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def to_pillow(img): | |
# https://github.com/imageio/imageio/blob/master/imageio/plugins/pillowmulti.py#L371 | |
# img = np.concatenate((img,255*np.ones(list(img.shape[:2])+[1],dtype='uint8')),axis=-1) | |
# img = Image.fromarray(img.astype('uint8'), 'RGBA') | |
img = Image.fromarray(img.astype('uint8'), 'RGB') | |
# a_channel = Image.new('L', img.size, 255) # 'L' 8-bit pixels, black and white | |
# img.putalpha(a_channel) | |
# p = img.getpalette() | |
# img = img.convert('P', dither=None,colors=1024) | |
# #img.putpalette | |
img = img.quantize(colors=256, method=1) | |
return img | |
frames = [to_pillow(img) for img in img_list] | |
frames[0].save(output_path, format='GIF', append_images=frames[1:], save_all=True, loop=0, # disposal=0, | |
# palette=frames[0].getpalette(), | |
include_color_table=True, optimize=False, interlace=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment