Create an animated "contact sheet" of gifs

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?".
Post Reply
trig.vee
Posts: 5
Joined: 2019-10-13T00:39:43-07:00
Authentication code: 1152

Create an animated "contact sheet" of gifs

Post by trig.vee »

Using montage and append seem intended for stills and will unpack animated gifs into individual frames. I would like to combine many gifs into a "contact sheet" of animations. Is this possible without knowing the size of each source gif beforehand? I imagine the source gifs may need to be trimmed or forced into the same speed and duration, which is okay.
Thanks :)

Version: ImageMagick 7.0.8-59 Q16 x86_64 2019-08-05
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create an animated "contact sheet" of gifs

Post by snibgo »

I'm not sure what you want. Perhaps you have a number of animated GIFs, and you want to create a single GIF that is made from the input GIFs placed side-by-side or below each other, or in a grid.

This is easily done by keeping the GIFs separate, and showing them on an HTML page.

Combining them into a single GIF (which will be limited to 256 colours, and may need re-sizing and re-timing of each input) can be done. See http://www.imagemagick.org/Usage/anim_mods/#append and other sections of that page.
snibgo's IM pages: im.snibgo.com
trig.vee
Posts: 5
Joined: 2019-10-13T00:39:43-07:00
Authentication code: 1152

Re: Create an animated "contact sheet" of gifs

Post by trig.vee »

Thanks, and sorry for my unclear wording. I wanted to combine many GIFs into a single GIF.

It seemed like the 'anim_mod' examples were geared towards when you know the exact size and how many source gifs need to be appended. I was wondering if there was a technique more similar in flexibility to montage, which I can be given any number images, all at different sizes, and it automatically creates a nice "contact sheet". The potential re-sizing and re-timing compromises are not an issue for me.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create an animated "contact sheet" of gifs

Post by snibgo »

I think you would need to write a script for that.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create an animated "contact sheet" of gifs

Post by fmw42 »

Are you asking to take one animated gif and extract all the frames and make a contact sheet of those? Or are you asking to make an animated contact sheet from many animated gifs?
trig.vee
Posts: 5
Joined: 2019-10-13T00:39:43-07:00
Authentication code: 1152

Re: Create an animated "contact sheet" of gifs

Post by trig.vee »

The latter. I want to make an animated contact sheet from many animated gifs.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create an animated "contact sheet" of gifs

Post by fmw42 »

trig.vee wrote: 2019-10-13T10:48:41-07:00 The latter. I want to make an animated contact sheet from many animated gifs.
The problem with that is that you need to sync the animations. That generally only works well if you have the same number of frames and the same delays in all the animations. See https://imagemagick.org/Usage/anim_mods/#merging
trig.vee
Posts: 5
Joined: 2019-10-13T00:39:43-07:00
Authentication code: 1152

Re: Create an animated "contact sheet" of gifs

Post by trig.vee »

I wouldn't mind if the frame counts and delays are adjusted in order to make it work; similar to how montage will resize images to match the largest/smallest image in the grid.

It sounds like there isn't currently a magical way to do this, so I will try this process:

1. Separate each source animation into coalesced static frames.
2. Find the GIF with the most frames (X), and add frames to all other GIFs until they also have X frames.
3. Loop over X frames, grabbing a frame from each source GIF then generating a static contact sheet using the montage command.
4. Finally, take all those static contact sheet images and compile into a single animated contact sheet GIF.

Let me know if a simpler way comes to mind, otherwise thanks for helping me think through it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create an animated "contact sheet" of gifs

Post by fmw42 »

I can create a montage of animations and it will animate using the latest beta (IM 6.9.10.69 or IM 7.0.8.69). If they have different numbers of frames, an empty spot will appear. So it should be easy for you to create your contact sheet of animations. Just make the tiling correspond to the number of animations you provide and include your new desired delay.

Code: Select all

convert -delay 20 lena.jpg mandril3.jpg zelda1.jpg anim1.gif
convert -delay 20 lena.jpg mandril3.jpg anim2.gif
magick montage -delay 50 anim1.gif anim1.gif anim1.gif anim1.gif -tile 2x2 anim_montage1.gif
magick montage -delay 50 anim1.gif anim1.gif anim1.gif anim2.gif -tile 2x2 anim_montage2.gif
Image

Image
trig.vee
Posts: 5
Joined: 2019-10-13T00:39:43-07:00
Authentication code: 1152

Re: Create an animated "contact sheet" of gifs

Post by trig.vee »

Starting from your example, it seems like ImageMagick jumbles up the frames between different GIFs. In your example, it's hard to tell since the source gifs don't have any linear continuity.

Here's my result using 4 copies the same source gif:

Code: Select all

montage 1a.gif 1b.gif 1c.gif 1d.gif -tile 2x2 montage_same.gif
Source gif: https://tni-art-eater.s3.us-east-2.amaz ... ums/1a.gif
Result:
Image

And 4 completely different source gifs:

Code: Select all

montage 1.gif 2.gif 3.gif 4.gif -tile 2x2 montage_different.gif
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create an animated "contact sheet" of gifs

Post by fmw42 »

You need to add the -delay so we can see better. Perhaps it syncs when a delay is properly set. You need to use the beta version or wait for it to be released in order to use -delay in montage.
Post Reply