Making Maps, Version 2.0: Imagemagick Montage

Well I did it. I looked into using Imagemagick for the full process and came away with a process that makes a clearer, smaller image, so I’m very satisfied.

The goal is to take a set of images and stitch them together like a quilt. Here are the steps I took to do that.

Step 1: Make blank tiles.

The Legend of Zelda map is a grid, and then same grid every time but the way I’ve been making my maps is with blank white spaces for those areas that Link did not travel to that day. The whole script I wrote below is a very dance way of calling this one line imagemagick command repeatedly.

convert -size <span class="pl-vo">${WIDTH}</span>x<span class="pl-vo">${HEIGHT}</span> xc:<span class="pl-vo">${COLOR}</span> <span class="pl-vo">${full name}

There are many fancier and faster ways to create a blank image, or canvas, but this one is good enough for my purposes. I could make all the tiles so I can manually add the ones that I need to the folder with the pre trimmed images.

Step 2: Prep the image tiles

This step was fairly easy and based on the batch image processing used in Making Maps, Verions 1.5 except instead of adding a border, I need to simply splice on a bit of black at the bottom so when tiles don’t have anyone below them they don’t look so weird.

Step 3: Learn how to stitch together images

This was super easy. There is a command called montage. that all you need to do is feed a folder of images to and it will stitch them together row by row. That row by row action is why for right now my file names start with the Y coordinate. The basic template for what I’m doing is:

montage *.png -mode concatenate -tile WIDTHxHEIGHT OUTPUTNAME

Testing of montage command, Imagemagick

Testing of montage command, Imagemagick

It can be very funny when it goes wrong. Typical mistakes?

  • Switching width and height (shown here before I wrote creating just a subset map)
  • Having the wrong number of png files for the width vs height being asked for (too few or too many of the blank tiles)
  • Having non-relevant png files in the folder being processed, for example a previously generated map.

Full Map of where I explored (outside) on Day 60.

Full Map of where I explored (outside) on Day 60.

Doing these tests involved me dragging the appropriate white tiles from my “blank_tiles” folder into the folder with the prepped images in it and manually running the montage command. The result is a file that is much clearer, but smaller in file size. This could have been a good place to stop, but I still wanted EASIER. No manual work from me other than the file sizes.

Step 4: Auto create a subset map

This step was pulling it all together. Using inputs on the shell script to indicate what subset of the map I was going to be building, looking at file names to auto create the missing blank tiles with white images, adding a bit of trim and border at the end so the map is upload ready.

For now the trim and border step means that for now I have had to create 2 scripts on my machine. One for when I want trim and one for when there will be a tile in the top left. When there is a tile in the top left the corner is black, not white. The trim function uses the color of the top left corner to determine what to trim. Trimming black eats away at the top of the image. Using Imagemagick to look at the corner color and behave accordingly doesn’t seem like it would be too hard, but I was pretty satisfied with the afternoon’s work.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s