我可以以不同的速度或延迟加入 gif 吗?

Gio*_* PY 3 python imagemagick gif animated-gif imagemagick-convert

我尝试以不同的延迟加入两个不同的 gif,但最终的 output.gif 具有相同的延迟,而不是不同...有没有办法在一个 gif 中具有不同的延迟?

import subprocess
import os


def mk(i, o, delay=100):
    subprocess.call("convert -delay " +
                    delay + " -loop 5 " + i + " " + o, shell=True)


delay = input("Delay (default 100): ")
# mk("*png", "gif1, delay) # I used this to make the 2 gif
# with a delay of 100 and 30 respectively
# and then I joined them with the code below, but I dunno how to
# give them a separate delay... I want them one after the other
# in order of time
mk("*.gif", "output.gif", delay)
os.system("start output.gif")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 在此输入图像描述

Mar*_*ell 5

延迟是一个设置,因此它适用于其后的所有图像,并保持设置状态直到您更改它。

让我们制作一个红色、绿色和蓝色图像:

convert -size 400x250 xc:red  f1.gif
convert -size 400x250 xc:lime f2.gif
convert -size 400x250 xc:blue f3.gif
Run Code Online (Sandbox Code Playgroud)

现在将延迟设置为 100 并对前三个进行动画处理,然后将其设置为 300 并再次对相同的三个进行动画处理,但这次使用新的延迟:

convert -delay 100 f1.gif f2.gif f3.gif \
        -delay 300 f1.gif f2.gif f3.gif animated.gif
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

现在检查与各个帧相关的延迟:

identify -format "%f[%s] %T\n" animated.gif
animated.gif[0] 100
animated.gif[1] 100
animated.gif[2] 100
animated.gif[3] 300
animated.gif[4] 300
animated.gif[5] 300
Run Code Online (Sandbox Code Playgroud)

所以我想你想要的是:

convert -delay 200 1.gif -coalesce \( -delay 30 2.gif -coalesce \) animated.gif
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述