From 8a36a15ebd8635e4d2be0ea4629d99c50628cb3b Mon Sep 17 00:00:00 2001 From: Riley Lahd Date: Thu, 14 Mar 2019 14:41:10 -0600 Subject: [PATCH] Force include colour table for disposal=2 gifs and pad colour table to be valid when flag is set --- src/PIL/GifImagePlugin.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index dafe6a3f9..13036b1b4 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -476,6 +476,9 @@ def _write_multiple_frames(im, fp, palette): if len(im_frames) > 1: for frame_data in im_frames: im_frame = frame_data['im'] + if("disposal" in frame_data["encoderinfo"] \ + and frame_data["encoderinfo"]["disposal"]==2): + frame_data['encoderinfo']['include_color_table'] = True if not frame_data['bbox']: # global header for s in _get_global_header(im_frame, @@ -585,6 +588,8 @@ def _write_local_header(fp, im, offset, flags): include_color_table = im.encoderinfo.get('include_color_table') if include_color_table: palette_bytes = _get_palette_bytes(im) + # If needed, expand palette to minimum size + while(len(palette_bytes)<9): palette_bytes = palette_bytes*2 color_table_size = _get_color_table_size(palette_bytes) if color_table_size: flags = flags | 128 # local color table flag