@@ -715,15 +715,6 @@ def _write_local_header(fp, im, offset, flags):
715
715
+ o8 (0 )
716
716
)
717
717
718
- if "comment" in im .encoderinfo and 1 <= len (im .encoderinfo ["comment" ]):
719
- fp .write (b"!" + o8 (254 )) # extension intro
720
- comment = im .encoderinfo ["comment" ]
721
- if isinstance (comment , str ):
722
- comment = comment .encode ()
723
- for i in range (0 , len (comment ), 255 ):
724
- subblock = comment [i : i + 255 ]
725
- fp .write (o8 (len (subblock )) + subblock )
726
- fp .write (o8 (0 ))
727
718
if "loop" in im .encoderinfo :
728
719
number_of_loops = im .encoderinfo ["loop" ]
729
720
fp .write (
@@ -929,7 +920,7 @@ def _get_global_header(im, info):
929
920
palette_bytes = _get_palette_bytes (im )
930
921
color_table_size = _get_color_table_size (palette_bytes )
931
922
932
- return [
923
+ header = [
933
924
b"GIF" # signature
934
925
+ version # version
935
926
+ o16 (im .size [0 ]) # canvas width
@@ -943,6 +934,18 @@ def _get_global_header(im, info):
943
934
_get_header_palette (palette_bytes ),
944
935
]
945
936
937
+ if "comment" in info and len (info ["comment" ]):
938
+ comment = info ["comment" ]
939
+ if isinstance (comment , str ):
940
+ comment = comment .encode ()
941
+ header .append (b"!" + o8 (254 )) # extension intro
942
+ for i in range (0 , len (comment ), 255 ):
943
+ subblock = comment [i : i + 255 ]
944
+ header .append (o8 (len (subblock )) + subblock )
945
+ header .append (o8 (0 ))
946
+
947
+ return header
948
+
946
949
947
950
def _write_frame_data (fp , im_frame , offset , params ):
948
951
try :
0 commit comments