问题
I have two GIFs of different sizes. I want to be able to place one animated GIF onto a static background GIF at a specific location and at the same time add text to the result. I am new to ImageMagick world, please help.
I am trying to achieve the following result where dog sticker is in a separate GIF.
回答1:
If your two animations do not have the same delay and number of frames, see https://www.imagemagick.org/Usage/anim_mods/#merging.
If your animations have the same delay and number of frames, you can do (unix syntax):
Background:
Animation1:
Animation:2
convert skyblue.gif \
null: \
\( morph_anim_1pt.gif -coalesce \) \
-gravity northwest -geometry +20+20 -compose over -layers composite \
null: \
\( morph_anim_5pts.gif -coalesce \) \
-gravity southeast -geometry +20+20 -compose over -layers composite \
-layers optimize \
result.gif
See https://www.imagemagick.org/Usage/anim_mods/#composite and subsequent sections.
回答2:
Perhaps this is more what you want. Imagemagick command line code in unix syntax:
The background animation has 3 frames and foreground one has 11 frames. So I repeat the background 4 times and remove the last frame so there is a total of 11 frames for the background. I coalesce the animation and add text to each frame using -annotate. Then I use -layers composite to overlay the foreground animation onto the background.
Background:
Foreground:
convert -delay 20 \
\( glitter_blue_tiled.gif glitter_blue_tiled.gif \
glitter_blue_tiled.gif glitter_blue_tiled.gif \
-coalesce \
+delete \
-font arial -pointsize 28 -fill black -gravity north \
-annotate +0+20 "TESTING" \) \
null: \
\( coalesced_k.gif -coalesce \) \
-gravity south -geometry +0+20 \
-compose over \
-layers composite \
-layers optimize \
-loop 0 \
result2.gif
来源:https://stackoverflow.com/questions/49511083/how-to-place-a-gif-on-another-gif-with-imagemagick-where-both-gifs-are-of-diffe