Animate images in correct order

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
hellocatfood
Posts: 44
Joined: 2010-01-01T13:29:41-07:00
Authentication code: 8675309

Animate images in correct order

Post by hellocatfood »

I'm using Imagemagick on Ubuntu Linux and I'm attempting to convert sequentially named files into a gif animation. Usually this is an easy operation and only requires that I run something like

Code: Select all

convert input-*.png output.gif
. However, the filenames don't have leading zeros and so the animation order is something like input-0.png input-10.png input-11.png input-12.png etc. See image below:

Image

I'm aware that I should have used the file padding operator (e.g. intput-03%d.jpg) when creating the files. I'm also aware of variety of methods for adding leading zeros to the files. However, at this time renaming the files would not be feasible.

Is there a way to convert those files using the command line on Linux into a gif with the files animated in the correct order?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Animate images in correct order

Post by fmw42 »

Why can you not rename the files or convert them into new files with proper alphabetic order. Alternately, you can just list the files in the order you want them to show up in the animation in the convert command

Code: Select all

convert -delay XX image1 image2 image3 ... image10 ... image20 -loop 0 animation.gif
alternately, make a text file listing the images in the order you want and then

Code: Select all

convert -delay xx @file.txt -loop 0 animation.gif
User avatar
hellocatfood
Posts: 44
Joined: 2010-01-01T13:29:41-07:00
Authentication code: 8675309

Re: Animate images in correct order

Post by hellocatfood »

fmw42 wrote:Why can you not rename the files or convert them into new files with proper alphabetic order.
Lots of different sequences in lots of different folders.

I've asked this same question elsewhere and the (sometimes harsh) answers focus on renaming. I appreciate that this is an option but I want to know if imaegmagick/bash has a way to put the files in the correct order.
Alternately, you can just list the files in the order you want them to show up in the animation in the convert command

Code: Select all

convert -delay XX image1 image2 image3 ... image10 ... image20 -loop 0 animation.gif
Some of the animations have 50/60 frames so it could take a long time to write it out.
alternately, make a text file listing the images in the order you want and then

Code: Select all

convert -delay xx @file.txt -loop 0 animation.gif
Perhaps the best suggestion so far. I thought about using ls or find and piping its output to a text file but both have the same problem of listing files in an "incorrect" order.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Animate images in correct order

Post by magick »

This seems to work for us:
  • convert 'input-%d.png[0-20]' output.gif
User avatar
hellocatfood
Posts: 44
Joined: 2010-01-01T13:29:41-07:00
Authentication code: 8675309

Re: Animate images in correct order

Post by hellocatfood »

magick wrote:This seems to work for us:
  • convert 'input-%d.png[0-20]' output.gif
Thank you! That's exactly what I needed.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Animate images in correct order

Post by magick »

This feature is documented @ http://www.imagemagick.org/script/comma ... essing.php. Tough to find, but there it is.
Post Reply