[SOLVED] How to montage a large number of images in 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
Ecen
Posts: 4
Joined: 2015-09-23T12:12:39-07:00
Authentication code: 1151

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

Post 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.)
Last edited by Ecen on 2015-09-24T16:57:50-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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
snibgo's IM pages: im.snibgo.com
Ecen
Posts: 4
Joined: 2015-09-23T12:12:39-07:00
Authentication code: 1151

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

Post 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?
Ecen
Posts: 4
Joined: 2015-09-23T12:12:39-07:00
Authentication code: 1151

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

Post by Ecen »

In any case, using question marks like you suggested works quite splendidly, so thanks for that! :)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

Try:

Code: Select all

convert -crop 500x500 rawImg-*.png img-%06d.png
snibgo's IM pages: im.snibgo.com
Ecen
Posts: 4
Joined: 2015-09-23T12:12:39-07:00
Authentication code: 1151

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

Post by Ecen »

That does work! Thanks!
Post Reply