I have a bunch of PNG
files named foo<bar>.png
I wish to convert to TIF animation. <bar>
is a number varies from 0 to 25 in leaps of five. ImageMagick place foo5.png
last in the animation while it is supposed to be second. Is there a way, apart from renaming the file to foo05.png
to place it in the right place?

- 86,724
- 23
- 248
- 345

- 10,295
- 30
- 88
- 128
-
1Rename your images with leading zeros for the numbers, e.g.foo005.png. The wild card * reads the images in alphabetic order not numeric order. So the leading zeroes will cause your filenames to be be listed alphabetically when accessed by the wild card. – fmw42 Jan 11 '19 at 03:13
7 Answers
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

- 86,724
- 23
- 248
- 345
-
2Note that you can also use this to reverse the order of the GIF: $(seq 100 -5 0) – MasterScrat Jan 27 '14 at 14:18
-
1Note if you just want to reverse normal order you can use this method but replace sub command with `$(ls -r *.png)`. – AnnanFay May 31 '17 at 12:46
Simple and easy, list your images and sort them:
convert -delay 10 -loop 0 $(ls -1 *.png | sort -V) animated.gif

- 1,430
- 15
- 24
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

- 86,724
- 23
- 248
- 345
-
@Yotam: Did you see my other answer? Is it not good enough for an 'upvote'? – Kurt Pfeifle Oct 12 '12 at 23:37
-
1It;s helpful to write such files with leading zeroes in the number part of the filename; then you can just say "*.png" and get them in the right order. i.e., foo00.png foo05.png foo15.png foo20.png foo25.png. – Glenn Randers-Pehrson Oct 17 '17 at 22:10
You can use "find" with "sort":
convert -delay 10 $(find . -name "*.png" -print0 | sort -zV | xargs -r0 echo) -loop 0 animated.gif

- 2,995
- 28
- 16
-
Why use `find` instead of `ls`? Why `xargs`? See my answer for a simpler solution. – Andrey Portnoy Jan 11 '19 at 00:26
Even easier than ls and sort is to use the built-in -v option of ls:
convert -delay 10 -loop 0 `ls -v *.png` animated.gif
with `...`
being executed instead of interpreted as string.

- 19
- 3
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!

- 2,626
- 1
- 19
- 28