views:

91

answers:

1

I have a table that is 26 squares by 26 squares. Each square is going to be 30px * 30px.

Given the tiles

  • upper_left.png
  • upper_right.png
  • upper_wall.png

and:

  • left_wall.png
  • right_wall.png

and:

  • bottom_left.png
  • bottom_wall.png
  • bottom_right.png

I aim to comprise a background that is 780px*780px. For the sake of speed and to prevent possible rendering errors, I want these tilesets to be composited into one big background. Making 8 tiles was easy, but I'm not a designer...
I believe I need to use an image library like RMagick to put them together, but I have no idea where to begin.

Ideally I'd like to just iterate over the image as though it were a multidimensional array of 26 rows and columns. That way I could just load up each spot with the image I need, and write it out to a file.

Can anybody point me in the right direction as to how I can manipulate images using a program?

The eventual goal is to just upload a tile_set.zip with the 8 images to the server, and have it do this on its own.

But for now, just a simple Ruby shell script would suffice.

Thanks in advance :)

+1  A: 

I won't write the script for you, but ImageMagick's +append and -append are the tools that will solve this. The corresponding RMagick documentation is here.

x1a4
It worked perfectly, although for some odd reason, doing it entirely in memory doesn't work.I have to save rows made with append(false) to disk, and then do append(true) on those.I can only assume it's a bug; but it happens on a local Windows machine and my shared server, both with Ruby 1.8.6.
Robbie
Cool. RMagick can be a memory hog, at least in my experience. 780x780 final size certainly isn't enormous or anything though. I wonder what's up with it.
x1a4
@x1a4 I think it has something to do with appending an image [in memory] to itself. I haven't tried to set up a debugger or anything but I think it's entering an infinite loop.http://pastie.org/960707If I get rid of the second << row1, the code works just fine.
Robbie
I do see that `row2` isn't being appended to `final`Do you want to append row1 multiple times to the final image? What if you use `final << row1.dup` instead?
x1a4
That's not my production code, I actually have 3 rows in the production and it goesfinal << row124.times dofinal << row2endfinal << row3That was just the simplest example of the 'bug'I'll try the .dup though
Robbie
Awesome, I just put row2.dup into the loop and it works:i.e: http://pastie.org/960774It still seems odd that an image object in memory doesn't behave the same as an image from the disk.
Robbie