4

I am making an animated GIF file using following command:

convert -delay 10 -loop 0 *.png animated.gif

But, the problem happens in the order of *.png.

My PNG files are like 1.png, 2.png, ... 100.png.

In the resulting animated GIF, the order of frames are like: 1.png, 10. png, 100.png, 2.png ...

I want that in the resultant GIF the snapshot are in order like 1,2,3 ... 100.

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
user4914499
  • 344
  • 1
  • 3
  • 12

4 Answers4

7

Please try sort:

$ ls | sort -V
1.png
2.png
10.png
100.png

So ultimately:

convert -delay 10 -loop 0 $(ls *.png | sort -V) animated.gif
NarūnasK
  • 4,564
  • 8
  • 50
  • 76
1

This little script will rename your files for you with leading zeroes - try it on a COPY of your files first:

#!/bin/bash
for i in {1..1000}; do
   [ -f "$i.jpg" ] && echo mv "$i.jpg" $(printf "%04d.jpg" $i)
done

It looks for JPEG files from 1.jpg through 1000.jpg and if any exist, it renames then with up to 3 leading zeroes till the number part is 4 digits wide.

If you save it as renamer, you will then run

chmod +x renamer    # just do this once to make it executable
./renamer           # do this any time you want the whole directory of JPEGs renamed

Remove the word echo if you see and like what it is going to do, then run it again.

Sample output

mv 1.jpg 0001.jpg
mv 99.jpg 0099.jpg
mv 102.jpg 0102.jpg
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
0

Rename your images with leading zeroes like:

001.png, 002.png, 003.png,......099.png,100.png.

And it will work fine for you

Kiran Dash
  • 4,816
  • 12
  • 53
  • 84
0

The glob operator (*) sorts the result list by comparing texts. So renaming the files 1.png, 2.png ... to 001.png, 002.png should work.

Peter Paul Kiefer
  • 2,114
  • 1
  • 11
  • 16