Defining the file order for ImageMagick convert

瘦欲@ 提交于 2019-12-03 06:22:53

You just give the order of your PNG files as they should appear in the animation. Use:

foo0.png foo5.png foo10.png foo15.png foo20.png foo25.png

instead of

foo*.png

After all, it's only 6 different file names which should be easy enough to type:

convert                                                      \
  -delay 10                                                  \
   foo0.png foo5.png foo10.png foo15.png foo20.png foo25.png \
  -loop 0                                                    \
   animated.gif

If you have more input images than are convenient enough to type (say, foo0..foo100.png), you could do this (on Linux, Unix and Mac OS X):

convert                                                  \
  -delay 10                                              \
   $(for i in $(seq 0 5 100); do echo foo${i}.png; done) \
  -loop 0                                                \
   animated.gif

Simple and easy, list your images and sort them:

convert -delay 10 -loop 0 $(ls -1 *.png | sort -V) animated.gif

You can use "find" with "sort":

convert -delay 10 $(find . -name "*.png" -print0 | sort -zV | xargs -r0 echo) -loop 0 animated.gif

Or if you know a bit of python, then you can easily leverage the help of it from python shell.

Hit up python shell by typing python in your terminal. And apply following magic spells-

# 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)

Your job should be done!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!