我有一堆名为 foo<bar>.png
的 PNG
文件,希望将它们转换为 TIF 动画。其中 <bar>
是一个数字,范围从 0 至 25,步长为 5。然而 ImageMagick 把 foo5.png
放在了动画的最后,而不是应该放在第二个位置。除了重命名文件为 foo05.png
,有没有其他办法可以把它放在正确的位置呢?
我有一堆名为 foo<bar>.png
的 PNG
文件,希望将它们转换为 TIF 动画。其中 <bar>
是一个数字,范围从 0 至 25,步长为 5。然而 ImageMagick 把 foo5.png
放在了动画的最后,而不是应该放在第二个位置。除了重命名文件为 foo05.png
,有没有其他办法可以把它放在正确的位置呢?
如果你有很多输入图像需要处理,但输入它们太麻烦(比如foo0..foo100.png),可以在Linux、Unix和Mac OS X上使用以下方法:
convert \
-delay 10 \
$(for i in $(seq 0 5 100); do echo foo${i}.png; done) \
-loop 0 \
animated.gif
$(ls -r *.png)
。 - AnnanFay简单易行,列出您的图像并对其进行排序:
convert -delay 10 -loop 0 $(ls -1 *.png | sort -V) animated.gif
foo0.png foo5.png foo10.png foo15.png foo20.png foo25.png
替代
foo*.png
convert \
-delay 10 \
foo0.png foo5.png foo10.png foo15.png foo20.png foo25.png \
-loop 0 \
animated.gif
convert -delay 10 -loop 0 `ls -v *.png` animated.gif
其中`...`
会被执行而不是解释为字符串。convert -delay 10 $(find . -name "*.png" -print0 | sort -zV | xargs -r0 echo) -loop 0 animated.gif
find
而不是ls
?为什么要使用xargs
?请查看我的答案,以获取更简单的解决方案。 - Andrey Portnoy# Suppose your files are like 1.jpeg, 2.jpeg etc. upto 100.jpeg
files = []
for i in range(1, 101):
files.append('{}.jpeg'.format(i))
command = 'convert -delay 10 {} -loop 0 animated.gif'.format(' '.join(files))
from subprocess import call
call(command, shell=True)
你的工作应该完成了!
实际上,你可以这样做:
convert $(ls -v *.png) animated.gif