Skip to content

Instantly share code, notes, and snippets.

@kevin-keraudren
Last active June 27, 2019 13:41
Show Gist options
  • Save kevin-keraudren/c6fe8870a12ef300b238d8a5f1c3f071 to your computer and use it in GitHub Desktop.
Save kevin-keraudren/c6fe8870a12ef300b238d8a5f1c3f071 to your computer and use it in GitHub Desktop.
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