Page 1 of 1

[SOLVED] How to montage a large number of images in order

Posted: 2015-09-23T12:31:49-07:00
by Ecen
I have 50 PNG images I want to montage into a single spritesheet. They're named img-0.png, img-1.png, ..., img-9.png, img-10.png, ..., img-49.png.

What I want to do is essentially:

Code: Select all

montage img-*.png spritesheet.png
This however messes up the order so the result is: img-0.png, img-1.png, img-10.png, img-11.png, ..., img-19.png, img-2.png, img-20.png, ...

Now, I could just add an extra 0 to img-1.png through img-9.png so that I would have img-01.png, img-02.png, ... but this is a bit of a hassle and in this case I would have to do it several times. I've read that it's possible to use a text file containing a list of files, but then I would need to create a correctly ordered list, which would be even more time consuming as far as I know. I've also tried:

Code: Select all

montage img-[0-9].png img-[10-25].png spritesheet.png
but that doesn't seem to work either. It really seems to me that there should be a simple way of doing this when all the files are named in increasing numerical order, even if those leading zeroes aren't there on all the numbers. So, is there one or do I have to set up some renaming script?

(I'm running Imagemagick 6.9.1 under Windows 7.)

Re: How to montage a large number of images in order

Posted: 2015-09-23T13:02:29-07:00
by snibgo
Always use leading zeros. It saves a lot of hassle.

This works for me:

Code: Select all

montage img-?.png img-??.png spritesheet.png

Re: How to montage a large number of images in order

Posted: 2015-09-23T14:24:15-07:00
by Ecen
I'll check it out! And yea, it does save alot of hazzle. However, when I use several Imagemagick commands, Imagemagick always spits out names without leading zeroes. For example

Code: Select all

convert -crop 500x500 rawImg-*.png img.png
where rawImg-*.png has leading zeroes such as rawImg-01.png, rawImg-02.png, ... the result will be files named img-1.png, img-2.png, ... That is, without leading zeroes.

Is there perhaps a way I can get Imagemagick to generate names WITH leading zeroes?

Re: How to montage a large number of images in order

Posted: 2015-09-23T14:30:21-07:00
by Ecen
In any case, using question marks like you suggested works quite splendidly, so thanks for that! :)

Re: How to montage a large number of images in order

Posted: 2015-09-23T14:55:23-07:00
by snibgo
Try:

Code: Select all

convert -crop 500x500 rawImg-*.png img-%06d.png

Re: How to montage a large number of images in order

Posted: 2015-09-24T16:56:56-07:00
by Ecen
That does work! Thanks!