Two animated gif - Composite one over another

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Two animated gif - Composite one over another

Post by agriz »

I can make them work one by one.
But i want those two images animated together. They are different sizes.

First image(background) is bigger than the second.

Code: Select all

convert anim_1.gif anim_2.gif -gravity center -compose over -composite output.gif
it is not working.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Two animated gif - Composite one over another

Post by fmw42 »

Are they both animated or is the first one a single frame? If they are both animated, do they have the same number of frames.

Can you post both images to some free hosting service such as dropbox.gif and put the urls here.

Please read viewtopic.php?f=1&t=9620, so you can ask questions more intelligently.

You never supply your IM version and platform! Please always do so.

See http://www.imagemagick.org/Usage/anim_mods/

If they have the same number of frames, then try

Code: Select all

convert \( image1.gif -coalesce \) null: \( image2.gif -coalesce \) -gravity center -layers composite result.gif
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Two animated gif - Composite one over another

Post by GeeMack »

EDITED: Deleted because fmw42 got in first with almost exactly the same answer as mine.
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Two animated gif - Composite one over another

Post by agriz »

Both are animated gif.
Both are different sizes.
Both are having different number of frames.
IM 7.0.2
I will post the gifs now.
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Two animated gif - Composite one over another

Post by agriz »

Image
Image


There are the two images i were trying. The moon has black background after uploading.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Two animated gif - Composite one over another

Post by snibgo »

What do you want the result to look like?
snibgo's IM pages: im.snibgo.com
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Two animated gif - Composite one over another

Post by agriz »

The animated moon over the animated stars. As a single image.
Is that possible? Both are different frames. I was thinking it is not possible if they are different in frame numbers.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Two animated gif - Composite one over another

Post by snibgo »

The moon GIF is taller than the stars GIF, but not as wide. If you simply composite the moon over the stars, the only visible stars with be at the right and left edges. Is that what you want?

You could make the black pixels of the moon GIF transparent. Then you would see stars through the moon. Is that what you want?
snibgo's IM pages: im.snibgo.com
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Two animated gif - Composite one over another

Post by agriz »

Yes sir. The black should be transparent and moon should be resized and centered.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Two animated gif - Composite one over another

Post by snibgo »

Windows BAT syntax:

Code: Select all

convert ^
  ( stars.gif -layers coalesce ) ^
  ( -clone 0--1 ) ^
  ( -clone 0--1 ) ^
  NULL: ^
  ( moon.gif -layers coalesce -transparent Black ) ^
  -gravity Center ^
  -layers composite ^
  -layers compress ^
  moonStars.gif
I haven't resized the moon. Put that in, as you want.
snibgo's IM pages: im.snibgo.com
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Two animated gif - Composite one over another

Post by agriz »

-layers compress is not working for me. If i remove it, it is working. If i use another background with few more frames, moon.gif is not displayed on all the frames of background. it goes and comes.

It was great effort and really thanks for helping.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Two animated gif - Composite one over another

Post by snibgo »

I meant "-layers optimize", not "-layers compress". Sorry.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Two animated gif - Composite one over another

Post by snibgo »

agriz wrote:If i use another background with few more frames, moon.gif is not displayed on all the frames of background. it goes and comes.
You should use the same number of frames in both sets of images. I duplicated your stars to make them roughly the same number.

You could do this by duplicating individual frames. Or duplicate both sets to get the least common multiple (LCM). Eg if you have 27 moon and 6 stars, the LCM is 54, so you would have 54 frames of each.
snibgo's IM pages: im.snibgo.com
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Two animated gif - Composite one over another

Post by agriz »

Oh. Okay. It is better to keep the same number of frames. Otherwise the the size will become bigger :)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Two animated gif - Composite one over another

Post by snibgo »

agriz wrote:Otherwise the the size will become bigger
No, you get the number of frames in the first set of images.

In my command above, there were 6 frames of stars. I duplicated to make 12, and duplicated again to make 24. There were 27 frames of the moon, but my command dropped 3 of them.

To get the full cycle of stars, and the full cycle of moon, we need 54 frames in total. That would give 9 full cycles of stars and 2 full cycles of moon.
snibgo's IM pages: im.snibgo.com
Post Reply