4

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.

enter image description here

fmw42
  • 46,825
  • 10
  • 62
  • 80
Vipin Nagpal
  • 143
  • 1
  • 3
  • 12
  • The images are animated, in case you didn't notice. That makes it more complicated because one might run at 12 frames per second and the other may run at 20 frames per second. Also, the overlaid one may have transparency or may not. – Mark Setchell Mar 27 '18 at 12:56
  • You'd have to get the duration of each clip, work out the lowest common multiple of the frame rates, map frames onto a common timebase, overlay, pad the shorter clip to the length of the longer one and re-optimise... ugh, ugh, ugh. It is possible though. – Mark Setchell Mar 27 '18 at 13:04
  • It would help if you posted the separate input animations. – fmw42 Mar 27 '18 at 21:03

2 Answers2

4

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: enter image description here

Animation1: enter image description here

Animation:2 enter image description here

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

enter image description here

See https://www.imagemagick.org/Usage/anim_mods/#composite and subsequent sections.

fmw42
  • 46,825
  • 10
  • 62
  • 80
3

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:

enter image description here

Foreground:

enter image description here

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

enter image description here

fmw42
  • 46,825
  • 10
  • 62
  • 80