首页 > 解决方案 > ImageMagick: How to apply one gif's per-frame delays to another gif?

问题描述

I have a workflow where I take gifs from a client, convert them from gif to sprite sheets (png) I can work on, then convert them back to gifs to send back. The Client's frame delays in their gifs are important though, so I need to preserve them.

Is there a way I can grab the frame delays in one gif, and apply them to another gif, using ImageMagick commandline utilities? I'm doing these through a .bat batch file on windows. The gifs have the same dimensions and frame counts.

标签: imagemagickanimated-gif

解决方案


在 Imagemagick 6 中,您可以使用字符串格式 %T 来获取动画延迟。将其放入一个变量中,然后将该变量用于下一个动画的延迟。见https://imagemagick.org/script/escape.php

convert -delay 100 rose: rose: rose: -loop 0 anim.gif

convert anim.gif -format "%T\n" info: | head -n 1
100

请注意,如果没有管道到 head -n 1,Imagemagick 将为每一帧重复一次延迟。

对于 Imagemagick 7,使用 magick 而不是转换。在 Windows .bat 中,将 % 加倍为 %%。

对于 Windows,您可能需要找到与 head -n 1 等效的工具,或者仅解析 %T 的文本输出以从每一帧的所有重复中仅提取一个值。


推荐阅读