I have an animated GIF of a fixed size (600x200):

I am trying to combine this GIF with a PNG frame:

The frame is larger than the GIF (640x260) but has a designated 600x200 space - the GIF just needs to be placed behind the PNG at a position of 20/20 pixels from the top left. The result should look like this, but preserve the GIF animation:

How can I achieve this using ImageMagick?
EDIT: The closest I got was using this command (ImageMagick 7 on Windows):
magick testgif.gif -repage 610x232+5+5 -transparent white -coalesce -draw "image over 0,0 0,0 frame3.png" -transparent white out.gif
The result (which is also 2.79 mb large, too large to upload here, while the original GIF is 213 kb) shows some artefacts. I added -dispose none following this question, but the artefacts are the same. They look like this:

You can do that in Imagemagick as follows:
convert \( loren_ipsum_foreground.gif -coalesce \) -draw 'image over -20,-20 0,0 "lorem_ipsum_frame.png"' -layers optimize lorem_ipsum_animation.gif

See https://imagemagick.org/Usage/anim_mods/#compose_draw
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With