ImageMagick - 使用IM转换将2个GIF并排成GIF [英] ImageMagick - Making 2 GIFs into side by side GIFs using IM convert

查看:255
本文介绍了ImageMagick - 使用IM转换将2个GIF并排成GIF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个长度相同的GIF。

I have 2 GIFs that are the same length.

我想把GIF放在一边,让1个GIF同时播放。我曾尝试使用 convert 工具:

I want to put the GIFs beside each other to have 1 GIF with both playing at the same time. I have tried to use the convert tool with:

convert +append 1.gif1 2.gif output.gif

然而,这似乎将所有图像混合在一起并发生变化大小非常小。

However, this seems to blend all the images together and changes the size to be extremely small.

我在想我可以将每个图像附加在一起,然后用已经合成的图像创建一个GIF。但是当我尝试时它不起作用:

I was thinking that I could append each image together and then create a GIF out of those already combined images. However it did not work when I tried:

convert -delay 15 -loop 0 1*.png 2*.png +append output.gif

我有很多长名字的图片,我不想去通过单独的方式,并为每个数字添加新的命名约定。

I have a lot of images with long names and I do not want to have to go through individually and append each figure with new naming conventions.

推荐答案

我没有2个相同长度的动画GIF,所以我只使用这个的两个副本:

I don't have 2 animated GIFs of the same length, so I'll just use two copies of this one:

让我们看看那里的帧,其中:

Let's look at the frames in there, with this:

identify 1.gif
1.gif[0] GIF 500x339 500x339+0+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[1] GIF 449x339 500x339+51+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[2] GIF 449x339 500x339+51+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[3] GIF 449x339 500x339+51+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[4] GIF 448x339 500x339+52+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[5] GIF 449x339 500x339+51+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[6] GIF 448x339 500x339+52+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[7] GIF 448x339 500x339+52+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[8] GIF 448x339 500x339+52+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[9] GIF 448x339 500x339+52+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[10] GIF 448x339 500x339+52+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[11] GIF 500x339 500x339+0+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[12] GIF 500x339 500x339+0+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[13] GIF 500x339 500x339+0+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[14] GIF 500x339 500x339+0+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[15] GIF 448x339 500x339+52+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[16] GIF 500x339 500x339+0+0 8-bit sRGB 32c 508KB 0.000u 0:00.000
1.gif[17] GIF 500x339 500x339+0+0 8-bit sRGB 32c 508KB 0.000u 0:00.000

Mmmm,18帧不同尺寸,这意味着我们需要使用 -coalesce 将部分帧重建为完整帧。

Mmmm, 18 frames with different sizes, that means we need to use -coalesce to rebuild partial frames into full ones.

让我们复制它并制作 2.gif

cp 1.gif 2.gif

现在我们可以将两个GIF分成它们的组件框架,如下所示:

Now we can split the two gifs into their component frames, like this:

convert 1.gif -coalesce a-%04d.gif     # split frames of 1.gif into a-0001.gif, a-0002.gif etc
convert 2.gif -coalesce b-%04d.gif     # split frames of 2.gif into b-0001.gif, b-0002.gif etc

现在让我们并排加入各个框架:

Now let's join the individual frames side-by-side:

for f in a-*.gif; do convert $f ${f/a/b} +append $f; done

请注意 $ {f / a / b} 是一个bash-ism,意思是取f的值并用'b'替换字母'a'

Note that ${f/a/b} is a bash-ism meaning "take the value of f and replace the letter 'a' with 'b'".

并将它们重新组合在一起:

And put them back together again:

convert -loop 0 -delay 20 a-*.gif result.gif

这看起来更长,更难,因为我试图解释这一切,但它看起来真的如此:

That looks longer, and harder, than it is because I tried to explain it all, but it looks like this really:

convert 1.gif -coalesce a-%04d.gif                         # separate frames of 1.gif
convert 2.gif -coalesce b-%04d.gif                         # separate frames of 2.gif
for f in a-*.gif; do convert $f ${f/a/b} +append $f; done  # append frames side-by-side
convert -loop 0 -delay 20 a-*.gif result.gif               # rejoin frames

请注意这个概念性代码,而不是生产质量。它不会删除它创建的临时文件,也不会携带原始GIF的帧间时间。如果你想获得原始帧速率,你可以像这样得到它们并将它们保存到一个数组中并在最后将延迟反馈给重新动画命令:

Note that this conceptual code, not production quality. It doesn't remove the temporary files it creates, nor does it carry the inter-frame time forward from the original GIFs. If you want to get the original frame rate you could get them like this and save them into an array and feed the delays back into the re-animation command at the end:

identify -format "%f[%s] %T\n" 1.gif
1.gif[0] 8
1.gif[1] 8
1.gif[2] 8
1.gif[3] 8
1.gif[4] 8
1.gif[5] 8
1.gif[6] 8
1.gif[7] 8
1.gif[8] 8
1.gif[9] 8
1.gif[10] 11
1.gif[11] 11
1.gif[12] 11
1.gif[13] 11
1.gif[14] 11
1.gif[15] 11
1.gif[16] 11
1.gif[17] 26

另外,你可能需要两个动画之间的间隔,比如10个像素,你可以通过替换<$ c $里面的 convert 命令来做c> for 循环使用这个:

Also, you may want a spacer between the two animations, say 10 pixels, which you can do by replacing the convert command inside the for loop with this one:

convert $f -size 10x xc:none ${f/a/b} +append $f

这篇关于ImageMagick - 使用IM转换将2个GIF并排成GIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆