Page 2 of 2

Re: Merging 2 gifs, one is animated and transparent

Posted: 2015-07-31T00:34:15-07:00
by av01d
Reviving an old thread... I have a question similar to what was asked above.
I have a JPEG image of say 400x300px. I have a small animated GIF of say 100x50px.
I want to overlay the animated GIF over the JPG, which should result in an animated GIF. The GIF should have the same width/height as the JPEG image (400x300px in this particular example).

I tried:

Code: Select all

convert smallAnim.gif -coalesce -draw "image DstOver 0,0 0,0 background.jpg" -layers Optimize output.gif
Which is close to what I want: output.gif shows the animation (smallAnim.gif) over the background image (background.jpg), and it animates correctly, but the resulting image has the width/height of smallAnim.gif. It's too small.

When I want to position the animation to a certain x,y coordinate:

Code: Select all

convert smallAnim.gif -coalesce -draw "image DstOver 150,125 0,0 background.jpg" -layers Optimize output.gif
It gets worse; output.gif only shows the animation, the background image is not visible.

How can I make this work properly, without reverting to merging the images frame-by-frame (which works, but is cumbersome).

Re: Merging 2 gifs, one is animated and transparent

Posted: 2015-07-31T00:46:41-07:00
by snibgo
Testing and suggesting a solution is far easier if you supply sample input files. You should also say what version IM you use, on what platform.

The problem is that IM uses the first input as metadata (including dimensions) for the output. You might use a dummy first input:

Code: Select all

convert background.jpg smallAnim.gif -delete 0 -coalesce -draw \"image DstOver 0,0 0,0 background.jpg\" -layers Optimize output.gif

Re: Merging 2 gifs, one is animated and transparent

Posted: 2015-07-31T00:48:04-07:00
by anthony
This is covered by IM Examples!

Re: Merging 2 gifs, one is animated and transparent

Posted: 2015-07-31T01:08:33-07:00
by av01d
I managed to figure it out myself:

Code: Select all

convert background.jpg null: \( smallAnim.gif -coalesce \) -geometry +150+125 -layers Composite -layers Optimize output.gif
Works like a charm. Is this indeed what I should be using?

The suggestion made by snibgo (thanks!) does not seem to work for me...

Re: Merging 2 gifs, one is animated and transparent

Posted: 2015-08-02T16:51:04-07:00
by anthony