以不同的速度创建 GIF

Posted

技术标签:

【中文标题】以不同的速度创建 GIF【英文标题】:Creating GIF with different speed 【发布时间】:2020-07-08 23:43:17 【问题描述】:

我创建了一系列图,并希望以不同的速度制作它们的 GIF。

我知道如何通过以下命令使用 imagemagick 创建 GIF:magick *jpeg -delay 10 name.gif。

但是我希望某些 jpeg 文件的显示时间比其他文件长,我该如何实现呢?

另外,也许在 python 中更容易做到这一点?我有一个数字列表,我想从中创建这个 GIF。

【问题讨论】:

【参考方案1】:

您可以在加载图像之前单独设置延迟:

magick -delay 30 red.png -delay 80 green.png -delay 99 blue.png anim.gif

像这样检查延迟、偏移、处置:

magick identify -format "%f[%s] canvas=%Wx%H size=%wx%h offset=%X%Y %D %Tcentisecs\n"  anim.gif
anim.gif[0] canvas=100x100 size=100x100 offset=+0+0 Undefined 30centisecs
anim.gif[1] canvas=100x100 size=100x100 offset=+0+0 Undefined 80centisecs
anim.gif[2] canvas=100x100 size=100x100 offset=+0+0 Undefined 99centisecs

请注意,由于-delay 是一个设置,它会一直保持设置直到更改,因此前 4 帧继承 10 厘秒的延迟,其余帧获得 25 厘秒:

magick -delay 10 frame-[0-3].jpg -delay 25 frame-[4-7].jpg  anim.gif
identify -format "%f[%s] canvas=%Wx%H size=%wx%h offset=%X%Y %D %Tcentisecs\n"  anim.gif
anim.gif[0] canvas=100x100 size=100x100 offset=+0+0 Undefined 10centisecs
anim.gif[1] canvas=100x100 size=100x100 offset=+0+0 Undefined 10centisecs
anim.gif[2] canvas=100x100 size=100x100 offset=+0+0 Undefined 10centisecs
anim.gif[3] canvas=100x100 size=100x100 offset=+0+0 Undefined 10centisecs
anim.gif[4] canvas=100x100 size=100x100 offset=+0+0 Undefined 25centisecs
anim.gif[5] canvas=100x100 size=100x100 offset=+0+0 Undefined 25centisecs
anim.gif[6] canvas=100x100 size=100x100 offset=+0+0 Undefined 25centisecs
anim.gif[7] canvas=100x100 size=100x100 offset=+0+0 Undefined 25centisecs

从那里继续,如果你想做一些更复杂的事情,我会求助于gifsicle,所以说你想要我上面的内容,但第 4 帧有 17 厘米的延迟:

# Change delay to 17 on frame 4 only
gifsicle -b anim.gif "#0-3" -d17 "#4" --same-delay "#5-" 

# Check again
anim.gif[0] canvas=100x100 size=100x100 offset=+0+0 Undefined 10centisecs
anim.gif[1] canvas=100x100 size=100x100 offset=+0+0 Undefined 10centisecs
anim.gif[2] canvas=100x100 size=100x100 offset=+0+0 Undefined 10centisecs
anim.gif[3] canvas=100x100 size=100x100 offset=+0+0 Undefined 10centisecs
anim.gif[4] canvas=100x100 size=100x100 offset=+0+0 Undefined 17centisecs    <--- HERE
anim.gif[5] canvas=100x100 size=100x100 offset=+0+0 Undefined 25centisecs
anim.gif[6] canvas=100x100 size=100x100 offset=+0+0 Undefined 25centisecs
anim.gif[7] canvas=100x100 size=100x100 offset=+0+0 Undefined 25centisecs

关键字:ImageMagick、gifsicle、延迟、单独设置延迟、单个帧、厘秒。

【讨论】:

谢谢,我有两个问题!例如,如果我想制作 5 张速度为 30 的 jpeg,我可以用一个延迟实例来做到这一点吗?另外,如果我想以 10 的速度包含除我已经使用过的所有其他 jpeg,我该怎么做? 我添加了一些进一步的细节 - 请再看看。

以上是关于以不同的速度创建 GIF的主要内容,如果未能解决你的问题,请参考以下文章

比较两个不同大小的矩阵以制作一个大矩阵 - 速度改进?

加快加载动画 gif kivy

gif/jpg/png 图片格式 简单对比

JQuery.animate() 在某些浏览器上以不同的速度移动 div

将不同的图片格式(jpg、gif、png等)转换为TIFF格式

Firemonkey 中的 GIF 动画