Page 1 of 2

Two animated gif - Composite one over another

Posted: 2016-09-06T19:02:29-07:00
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.

Re: Two animated gif - Composite one over another

Posted: 2016-09-06T20:07:00-07:00
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

Re: Two animated gif - Composite one over another

Posted: 2016-09-06T20:12:23-07:00
by GeeMack
EDITED: Deleted because fmw42 got in first with almost exactly the same answer as mine.

Re: Two animated gif - Composite one over another

Posted: 2016-09-07T01:28:12-07:00
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.

Re: Two animated gif - Composite one over another

Posted: 2016-09-07T02:08:13-07:00
by agriz
Image
Image


There are the two images i were trying. The moon has black background after uploading.

Re: Two animated gif - Composite one over another

Posted: 2016-09-07T06:43:39-07:00
by snibgo
What do you want the result to look like?

Re: Two animated gif - Composite one over another

Posted: 2016-09-07T07:00:39-07:00
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.

Re: Two animated gif - Composite one over another

Posted: 2016-09-07T07:05:09-07:00
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?

Re: Two animated gif - Composite one over another

Posted: 2016-09-07T07:07:16-07:00
by agriz
Yes sir. The black should be transparent and moon should be resized and centered.

Re: Two animated gif - Composite one over another

Posted: 2016-09-07T07:38:04-07:00
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.

Re: Two animated gif - Composite one over another

Posted: 2016-09-07T07:52:47-07:00
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.

Re: Two animated gif - Composite one over another

Posted: 2016-09-07T08:17:18-07:00
by snibgo
I meant "-layers optimize", not "-layers compress". Sorry.

Re: Two animated gif - Composite one over another

Posted: 2016-09-07T08:23:10-07:00
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.

Re: Two animated gif - Composite one over another

Posted: 2016-09-07T08:48:12-07:00
by agriz
Oh. Okay. It is better to keep the same number of frames. Otherwise the the size will become bigger :)

Re: Two animated gif - Composite one over another

Posted: 2016-09-07T08:59:52-07:00
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.