Skip to content

Commit

Permalink
Moved Netscape extension after global color table when saving
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Apr 15, 2022
1 parent 0329b8f commit 01753ac
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/PIL/GifImagePlugin.py
Expand Up @@ -722,18 +722,6 @@ def _write_local_header(fp, im, offset, flags):
subblock = comment[i : i + 255]
fp.write(o8(len(subblock)) + subblock)
fp.write(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)
Expand Down Expand Up @@ -927,7 +915,7 @@ def _get_global_header(im, info):
palette_bytes = _get_palette_bytes(im)
color_table_size = _get_color_table_size(palette_bytes)

return [
header = [
b"GIF" # signature
+ version # version
+ o16(im.size[0]) # canvas width
Expand All @@ -940,6 +928,18 @@ 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)
)
return header


def _write_frame_data(fp, im_frame, offset, params):
Expand Down

0 comments on commit 01753ac

Please sign in to comment.