@@ -163,6 +163,8 @@ def _seek(self, frame, update_image=True):
163
163
self .__frame = - 1
164
164
self ._fp .seek (self .__rewind )
165
165
self .disposal_method = 0
166
+ if "comment" in self .info :
167
+ del self .info ["comment" ]
166
168
else :
167
169
# ensure that the previous frame was loaded
168
170
if self .tile and update_image :
@@ -230,7 +232,7 @@ def _seek(self, frame, update_image=True):
230
232
#
231
233
comment = b""
232
234
233
- # Collect one comment block
235
+ # Read this comment block
234
236
while block :
235
237
comment += block
236
238
block = self .data ()
@@ -395,7 +397,9 @@ def _rgb(color):
395
397
)
396
398
]
397
399
398
- for k in ["duration" , "comment" , "extension" , "loop" ]:
400
+ if info .get ("comment" ):
401
+ self .info ["comment" ] = info ["comment" ]
402
+ for k in ["duration" , "extension" , "loop" ]:
399
403
if k in info :
400
404
self .info [k ] = info [k ]
401
405
elif k in self .info :
@@ -712,15 +716,6 @@ def _write_local_header(fp, im, offset, flags):
712
716
+ o8 (0 )
713
717
)
714
718
715
- if "comment" in im .encoderinfo and 1 <= len (im .encoderinfo ["comment" ]):
716
- fp .write (b"!" + o8 (254 )) # extension intro
717
- comment = im .encoderinfo ["comment" ]
718
- if isinstance (comment , str ):
719
- comment = comment .encode ()
720
- for i in range (0 , len (comment ), 255 ):
721
- subblock = comment [i : i + 255 ]
722
- fp .write (o8 (len (subblock )) + subblock )
723
- fp .write (o8 (0 ))
724
719
if "loop" in im .encoderinfo :
725
720
number_of_loops = im .encoderinfo ["loop" ]
726
721
fp .write (
@@ -925,7 +920,7 @@ def _get_global_header(im, info):
925
920
palette_bytes = _get_palette_bytes (im )
926
921
color_table_size = _get_color_table_size (palette_bytes )
927
922
928
- return [
923
+ header = [
929
924
b"GIF" # signature
930
925
+ version # version
931
926
+ o16 (im .size [0 ]) # canvas width
@@ -938,6 +933,19 @@ def _get_global_header(im, info):
938
933
# Global Color Table
939
934
_get_header_palette (palette_bytes ),
940
935
]
936
+ if info .get ("comment" ):
937
+ comment_block = b"!" + o8 (254 ) # extension intro
938
+
939
+ comment = info ["comment" ]
940
+ if isinstance (comment , str ):
941
+ comment = comment .encode ()
942
+ for i in range (0 , len (comment ), 255 ):
943
+ subblock = comment [i : i + 255 ]
944
+ comment_block += o8 (len (subblock )) + subblock
945
+
946
+ comment_block += o8 (0 )
947
+ header .append (comment_block )
948
+ return header
941
949
942
950
943
951
def _write_frame_data (fp , im_frame , offset , params ):
0 commit comments