I need to convert a large number (~10k) of .xpm files generated by my code to a .gif file.

I used ImageMagick as instructed here: How to convert a PNG strip to a GIF?

But my filenames are like plot*.xpm, * from 0 to 10000 and the convert command doesn't seem to understand it right and makes a .gif file with only a few frames.

My .xpm files are like this

they end somewhere with a non-random distribution of blue and green dots. (Like a circle of blue in the middle) in say 1000th frame. (I can't include it's picture because of posting limits)

But this is the .gif file I get

I use this line of code: convert -loop 0 -delay 10 -page +0+0 /*.xpm output.gif

I think I should use another method to introduce .xpm files to ImageMagick.
What should I do?

  • May you please mention the format of your file names (would be great to give few examples). And please include the exact code you used for converting. For those few files that you've converted already, is the result the same as you expected? – Mostafa Ahangarha Feb 8 '17 at 21:34
  • @MostafaAhangarha I added screenshots and examples + the command used. – Alireza Feb 8 '17 at 22:01
  • I am a bit confused. You want to put these .xpm in an animated .gif or you want to simply convert each .xpm file in to a non-animated .gif? if the first one is what you want, what is wrong with your current output? – Mostafa Ahangarha Feb 12 '17 at 15:43
  • @MostafaAhangarha The first one. current output is not complete. It has only a few frames. I guess because file numbers vary from 1 to 10000 instead of 00001 to 10000 this happens. Am I using the right command? – Alireza Feb 17 '17 at 19:46
  • I have made a set of pictures with the same name format you use and I noticed the problem is that the convert command is not able to sort numbers properly. So, it seems there is a need to convert filenames before starting conversion. I think actually all the pictures are converted but not in proper order. Should I share the command for doing this? – Mostafa Ahangarha Feb 18 '17 at 8:47

It seems all of your pictures are converted but not in a proper order as you expect.

As per my experience, the convert commands cannot work with files with same filenames format you have used. It works on files with this sort:


So, you need to rename all your files before conversion. So, your filenames should become like:


This is what I have written. See if using it would solve your problem:

rename 's/plot(\d{1})\.xpm/plot0000$1\.xpm/' *  # plot#.xpm     >    plot0000#.xpm
rename 's/plot(\d{2})\.xpm/plot000$1\.xpm/' *   # plot##.xpm    >    plot000##.xpm
rename 's/plot(\d{3})\.xpm/plot00$1\.xpm/' *    # plot###.xpm   >    plot00###.xpm
rename 's/plot(\d{4})\.xpm/plot0$1\.xpm/' * # plot####.xpm  >    plot0####.xpm

convert -loop 0 -delay 10 *.xpm output.gif

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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