ImageMagick: Combine animated GIF with PNG frame

116 Views Asked by At

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

I am trying to combine this GIF with a PNG frame: 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:

Non-animated result

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:

GIF artefacts

1

There are 1 best solutions below

7
fmw42 On

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

enter image description here

See https://imagemagick.org/Usage/anim_mods/#compose_draw