Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageMagick: Combine animated GIF with PNG frame

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

like image 514
Daerst Avatar asked Nov 15 '25 08:11

Daerst


1 Answers

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

like image 119
fmw42 Avatar answered Nov 18 '25 20:11

fmw42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!