From 5cf02f816f102bcce0c76e0e57fd582bd113228e Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 15 Apr 2022 16:46:33 +1000 Subject: [PATCH] Moved Netscape extension after global color table when saving --- src/PIL/GifImagePlugin.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index c91c1fbff..1b317d233 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -716,18 +716,6 @@ def _write_local_header(fp, im, offset, flags): + o8(0) ) - if "loop" in im.encoderinfo: - number_of_loops = im.encoderinfo["loop"] - fp.write( - b"!" - + o8(255) # extension intro - + o8(11) - + b"NETSCAPE2.0" - + o8(3) - + o8(1) - + o16(number_of_loops) # number of loops - + o8(0) - ) include_color_table = im.encoderinfo.get("include_color_table") if include_color_table: palette_bytes = _get_palette_bytes(im) @@ -933,6 +921,17 @@ def _get_global_header(im, info): # Global Color Table _get_header_palette(palette_bytes), ] + if "loop" in info: + header.append( + b"!" + + o8(255) # extension intro + + o8(11) + + b"NETSCAPE2.0" + + o8(3) + + o8(1) + + o16(info["loop"]) # number of loops + + o8(0) + ) if info.get("comment"): comment_block = b"!" + o8(254) # extension intro