Imagemagick is hard to use and the documentation/tutorials available are not intuitive. Here is a concise explanation of what needs to be done to edit a gif to add labels.
convert foo.gif \ # Specify the original gif
-gravity center -pointsize 30 -font ComicSans \ # Set font position and styling
-duplicate 1,0-20 \ # Clone frames and append to the end (clone frame once)
'(' -clone 21-40 -fill white -annotate -0-150 'Hello' -set delay 6 ')' \ # Clone frames, add 'Hello', and slow down gif delay for only these frames
-duplicate 1,41-89 \ # Clone frames and append to the end (clone frame once)
'(' -clone 90-120 -fill white -annotate -60-50 'World' -set delay 4 ')' \ # Clone frames, add 'World', and set delay
-delete 0-120 \ # Delete the original frames
foo_output.gif # Output file
convert
is the imagemagick command that is used to modify gifs-gravity
is used to set the position of the text. This is what x y offsets are relative to- frames are either duplicated or cloned+modified, appending them to the existing gif and control ordering.
-delete
is used to remove the original frames -duplicate
will copy the frame range and append to the end. This is memory-efficient way to clone frames (imagemagick only copies reference frame upon write) but doesn't allow modification-clone
requires imagemagick's parenthesis scope. Modified frames are appended to the end