Complex numbering: create simple column/row pattern

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
honeybee
Posts: 6
Joined: 2015-01-31T04:40:31-07:00
Authentication code: 6789

Complex numbering: create simple column/row pattern

Post by honeybee »

Hi everybody,

I have a series of smaller images from which I'm trying to build a larger one. I fiddled around quite a bit, but I'm not really getting it. I'm fighting with spacings, parameters in general and the biggest problem is probably the numbering of the tiles.

I try to explain what I'm intending to do:

I have 140 jpg's numbered from 0_[0-9].jpg to 13_[0-9].jpg. ImageMagick should put those images into 14 columns with 10 rows each, sewing them together seamlessly (like a photo) and with no loss of quality. For better visualization of this pattern I attached a picture.

I tried things like this. It's coming close, but misses pictures, parameters and of course it's only dealing with one row:

Code: Select all

montage [0-9]_1.jpg  -tile 13x10 test.jpg
I need to create about a hundred of those "puzzles" and it's very important to me. If anyone has a good idea how to accomplish that I'd be more than thankful.

Regards
honeybee

Edit: I'm sorry, I'm using the latest version of ImageMagick (6.9.0-1 I guess?) on Win XP. The tiles are about 20kb and 256x256 px each with slight variations, but will come out as a perfect whole when stitched together.


Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Complex numbering: create simple column/row pattern

Post by snibgo »

You can probably do this neatly with montage, but I'm not familiar with montage.

I'd do it something like this (untested):

Code: Select all

setlocal enabledelayedexpansion

set ALL_ROWS=convert
for /l %%y in (0,1,9) do (
  set ONE_ROW=convert
  for /l %%x in (0,1,13) do (
    echo %%x_%%y
    set ONE_ROW=!ONE_ROW! %%x_%%y.jpg
  )
  echo !ONE_ROW!
  !ONE_ROW! +append ROW_%%y.png
  set ALL_ROWS=!ALL_ROWS! ROW_%%y.png
)
echo !ALL_ROWS! -append allrows.png
!ALL_ROWS! -append allrows.png
The "echos" aren't needed, but are helpful for debugging.
snibgo's IM pages: im.snibgo.com
honeybee
Posts: 6
Joined: 2015-01-31T04:40:31-07:00
Authentication code: 6789

Re: Complex numbering: create simple column/row pattern

Post by honeybee »

Oh snibgo, that was quick! It works perfectly. Thanks soo much.

Best regards
honeybee
Posts: 6
Joined: 2015-01-31T04:40:31-07:00
Authentication code: 6789

Re: Complex numbering: create simple column/row pattern

Post by honeybee »

I'm sorry, is it possible to give the output file a dynamic name (folder name would be great) instead of a static (here "allrows")?

Say, the files are in (sub)folder "xyz". Is it possible to have the output file named xyz.png? Thank you.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Complex numbering: create simple column/row pattern

Post by snibgo »

Well, that's just about the scripting. Put this near the top:

set FOLDER=xyz

Then refer to %FOLDER%\%%x_%%y.jpg

The output file would be %FOLDER%.png
snibgo's IM pages: im.snibgo.com
honeybee
Posts: 6
Joined: 2015-01-31T04:40:31-07:00
Authentication code: 6789

Re: Complex numbering: create simple column/row pattern

Post by honeybee »

Ok, thank you. I will try that. But will this name the files differently according to their specific folder names or will the name be what is specified in the top of the script (here xyz)?

It's because my tile sets are in various numbered folders which have names like 364, 865, 1112 and so on. I'd like to copy my standard batch file to each of those folders and start it from there without having to edit it every time (in this case I could rename the output file manually as well and probably easier).

It's not the biggest deal, but as I said, I have quite a lot of tile sets and they will become more (ongoing project), so every automated step would be a labor-saver. Thank you.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Complex numbering: create simple column/row pattern

Post by fmw42 »

I have 140 jpg's numbered from 0_[0-9].jpg to 13_[0-9].jpg. ImageMagick should put those images into 14 columns with 10 rows each, sewing them together seamlessly (like a photo) and with no loss of quality. For better visualization of this pattern I attached a picture.
I believe you would need to rename your images with leading zeros for the first numer as 00_[0-9] to 13_[0-9]. Then you could just do

montage *.jpg -tile 13x10 test.jpg

You of course would need to specify the offset (-geometry) and other montage arguments as desired.

However, montage reads all images into memory and so you may be running out of RAM. Working by append first in rows then in columns may be a better approach if memory is the issue.

You could easily get the folder name using the OS and put that into a variable that could be used for the output name.
honeybee
Posts: 6
Joined: 2015-01-31T04:40:31-07:00
Authentication code: 6789

Re: Complex numbering: create simple column/row pattern

Post by honeybee »

Thanks for the explanation. For now I'll be using snibgo's script. It's doing what I want and I'm really happy with it. ImageMagick is a powerful tool though and it might be that I want to use it in future projects as well.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Complex numbering: create simple column/row pattern

Post by snibgo »

honeybee wrote:Ok, thank you. I will try that. But will this name the files differently according to their specific folder names or will the name be what is specified in the top of the script (here xyz)?

It's because my tile sets are in various numbered folders which have names like 364, 865, 1112 and so on. I'd like to copy my standard batch file to each of those folders and start it from there without having to edit it every time (in this case I could rename the output file manually as well and probably easier).
Again, this is just a scripting issue and nothing to do with ImageMagick.
snibgo's IM pages: im.snibgo.com
honeybee
Posts: 6
Joined: 2015-01-31T04:40:31-07:00
Authentication code: 6789

Re: Complex numbering: create simple column/row pattern

Post by honeybee »

Ok, thanks and sorry. I will try and see if I can find a way :) Best
Post Reply