@@ -715,15 +715,6 @@ def _write_local_header(fp, im, offset, flags):
715715 + o8 (0 )
716716 )
717717
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 ))
727718 if "loop" in im .encoderinfo :
728719 number_of_loops = im .encoderinfo ["loop" ]
729720 fp .write (
@@ -929,7 +920,7 @@ def _get_global_header(im, info):
929920 palette_bytes = _get_palette_bytes (im )
930921 color_table_size = _get_color_table_size (palette_bytes )
931922
932- return [
923+ header = [
933924 b"GIF" # signature
934925 + version # version
935926 + o16 (im .size [0 ]) # canvas width
@@ -943,6 +934,18 @@ def _get_global_header(im, info):
943934 _get_header_palette (palette_bytes ),
944935 ]
945936
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+
946949
947950def _write_frame_data (fp , im_frame , offset , params ):
948951 try :
0 commit comments