14

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?

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
Yotam
  • 10,295
  • 30
  • 88
  • 128
  • 1
    Rename 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 Answers7

16

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
Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
13

Simple and easy, list your images and sort them:

convert -delay 10 -loop 0 $(ls -1 *.png | sort -V) animated.gif
Andrey Portnoy
  • 1,430
  • 15
  • 24
6

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
Kurt Pfeifle
  • 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
  • 1
    It;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
1

You can use "find" with "sort":

convert -delay 10 $(find . -name "*.png" -print0 | sort -zV | xargs -r0 echo) -loop 0 animated.gif
nvd
  • 2,995
  • 28
  • 16
1

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.

J. Doe
  • 19
  • 3
0

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!

Munim
  • 2,626
  • 1
  • 19
  • 28
0

Actually, you can do something like:

convert $(ls -v *.png) animated.gif