Reputation: 2929
I am using ImageMagick to convert sequence of png
files to an animated gif
. Basically the command is
convert -delay 5 img/gif_part_*.png animation.gif
The files go from gif_part_1.png
to gif_part_27.png
, but the gif starts at gif_part_10.png
(maybe 9) and goes to the last. You can see it here. Stack won't allow me to upload the gif
file, so I'll edit it later.
So is there a restriction on the number of files I can make into a gif
(now it looks like the maximum is about 18)? I am working on turtle graphics and I want to show the process when the graphics is created by recursive function. The number of png
files might be hundred or more.
I have also tried using ffmpeg but could not make it working.
Update
I have tried making a gif
out of two smaller gif
s, and it done the job. But it is horrible way I think - that would be so much of a work, putting it all together.
I think the problem might be in naming the files. I have read somewhere, that adding zero might be necessary, since gif_part_10.png
might come before gif_part_1.png
.
Upvotes: 1
Views: 1083
Reputation: 2929
Basically the solution is in my updated question. But for better readability I will add an answer. The problem was in naming individual png
files. When ImageMagick-command convert
creates a gif
file it needs to sort the png
files somehow. The wrong naming would be
img1.png
img2.png
.
img10.png
.
.
img90.png
Because convert
would in this case put img10.png
before img1.png
, which most certainly ruins the output. The correct way is this:
img01.png
img02.png
img03.png
img04.png
img05.png
img06.png
img07.png
img08.png
img09.png
img10.png
.
.
.
img90.png
Now convert
will sort the files in correct order
png
files on my own I could easily correct the script, thanks to this neat approach. I assume you know, how much pictures you want to convert into a gif
, lets put it into variable `num_images' then you can do:
path = 'img_'+ str(index + 1).zfill( len( str( num_images) ) )
path += '.png'
Which will add the necessary amount of leading zeros. E.g. you have 236
images to convert (that is in our case num_images = 236
). Another neat trick is len( str( num_images ) )
. First it creates a string from 236
--> '236'
and then it finds the length of len( '236' ) = 3
This is how the final files will look like zfill
:
img_001.png
img_002.png
.
.
.
img_010.png
img_011.png
.
.
img_100.png
.
.
.
img_236.png
Upvotes: 2