I am using the animation tool Synfig to export a sequence of .png files. These are in the following format: C1.0000.png , C1.0001.png, C1.0002.png and so on.

I want to convert these to a spritesheet (i.e. append all of them together) however, I also need the same animations but flipped.

Here's where I have the problem. When using the following syntax:

 convert C1.*.png -flop C1right.*.png

I don't get a sequence similar to what I had before. (C1right.0000.png, C1right.0001.png etc) but instead C1right.-0.png, C1right.-1.png, etc.

This on its own isn't that bad, but because the +append command sorts the images alphabetically and not numerically, I end up with a sequence where not image 2 follows image 1 but image 11 follows image 1, with 2 ending up after 19.

Is there any way to keep the original file name structure? Or is there a way to ensure that the +append sorts the files numerically?


Only using glob patterns will not do. You must loop on all files:

for f in C1*.png ;do convert $f -flop $(echo $f | sed 's/\./right./') ;done

This will execute like this:

convert C1.01000.png -flop C1right.01000.png
convert C1.01001.png -flop C1right.01001.png
convert C1.01002.png -flop C1right.01002.png

Use format specifier %04d (0 means zero left-padded, 4d means 4 decimal positions):

convert C1.*.png -flop C1right.%04d.png

The resulted names will be


Note: In ImageMagick version 7+ simply replace convert command with magick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.