Saturday, June 16, 2012

Linux Tech Tip: Terrain magic on your Linux server

The magic trick: take a 256 x 256 terrain heightmap image (png, jpg, or tga, maybe other formats) blow it up to 512 x 512 px or 768 x 768 px or any multiple of 256 in either x or y direction; slice the blown image up into 256 x 256 px images; then reload the images into a block of 2 x 2 or 3 x 3 regions resulting in perfect, seamless borders. Explaining it may take several paragraphs but the actual process only takes a minute or two assuming you have already created the block of new empty regions to load the heightmaps into.

You need to be comfortable with the Linux terminal command-line interface, or at least be willing to try once. I guarantee you will be amazed  and impressed when you are in your virtual world watching what was previously a single region being transformed into a mult-region sim in the course of just a few minutes!

So, if you are running Opensim on a Linux server, either a remote server or in your home/office as a desktop machine or dedicated box, read on and I'll run you through step by step what you need to do.

 If you are fairly new to Linux, you might not realize there is a magic image processing tool available, that will do anything Gimp will do without even clicking any buttons with the mouse. All you need is the correct incantation, usually only a single line in the terminal, and the job is done in less time than it takes for Gimp to open it's splash screen and load some plugins.

And it can be done with the terrain heightmap image right in your Opensim server bin directory.

A while back, I was looking at Linda Kellie's terrains at and my favorite was Intertwined, 5th one down. So I grabbed it directly from her site to my opensim/bin directory with


Then I got experimental and thought this would look cool expanded as a group of regions. 3 x 3 seemed like a good one to try so with a simple command, I blew the image up to 768 x 768. People will gasp in horror at the thought, it's not something I would do with any image ordinarily, but hey, I was just messing around  Of course, make sure ImageMagick is installed. In Ubuntu, just type:

sudo apt-get install imagemagick

Now, with your command line location in the directory where the 256 x 256 terrain image is, type this ImageMagick command to enlarge the image:

convert -resize 768x768 terrain-intertwined.png terrain-intertwined-big.png

You might think it wise to do a gaussian blur on the image to depixelize it after being enlarged--but I didn't bother and it turned out ok in the end. I had used this command in the past and it worked but this time I am getting syntax errors after trying several combinations so I gave up. Maybe someone can figure it out, or just don't bother - anyway, here is what I thought would work:

convert -gaussian-blur radius 3 terrain-intertwined-big.png terrain-intertwined-big.png

Moving on, you next need to slice up the image into 9 256 square images. This is where ImageMagick earns it's name! Here's the command:

convert -crop 256x256 terrain-intertwined-big.png -depth 8 intertwined.png

Note, this is where the color depth is set for 8-bit. You could have done this above in the resize operation also, not sure if it makes any diff.

The ending file name is the destination file name of all your sliced images, with a number appended to the end of each one starting with zero. Magic, eh?

Do the ls (list) command and see:



intertwined-0.png intertwined-1.png intertwined-2.png
intertwined-3.png intertwined-4.png intertwined-5.png
intertwined-6.png intertwined-7.png intertwined-8.png terrain-intertwined.png terrain-intertwined-big.png

Now you have 9 tiled images, so go ahead and create 9 regions and load the images for each one. I started with a fresh instance of Opensim to create the first region, then shut down and created the Regions.ini file manually for the remaining 8 regions. You can see them inworld by searching for Intertwined but that sim will likely not be online after June 31 so here's a pic from the map:

If you visit the sim, and get up close to a border, you will see just the slightest hint of a dividing line. The seams between regions are very smooth and you really have to look close to see borders. Here I have dropped a prim cube right at the corner of one region, where 4 regions converge, to mark it so I know where to look - the OSGrid inworld location is

Notice that even from enlarging the original heightmap image x3, you don't see any pixel squares which would have been 3 meters across on the the terrain. 

Well, I hope you find this a useful trick, and if you have any questions please add them in the comments section. Thank you for looking, and be well :)

Key Gruin / Ken Grunke

P.S. Here's one more little Linux trick, for those creating a group of regions by manually editing the Regions.ini file: Most Linux distros have a neat little utility to create UUIDs so you don't have to go to a website to get them. Just type this in the terminal anywhere:


That's all!


  1. Thank you this is very useful and helpful x3

  2. And here I've been typing "cat /proc/sys/kernel/random/uuid" all this time.

  3. Use terrain load-tile, no need to slice image up.

    1. SignpostMarv, can you explain how to use this command please? The console help only says "terrain load-tile - Loads a terrain from a section of a larger file."
      I assume you need to create the regions first, so does this command assign the tiles in proper order to each region?

    2. see

      You basically use `change region` to switch between regions and specify the most south-west region coordinates as arguments.

    3. I can't make heads or tails of what to do with the parameters *scratches head*. Sounds like a good alternative, if one can figure it out and if the region borders look equal to or better than this method. You still have to do each region individually so it won't be any quicker. Maybe I'll play around with it sometime.

    4. You might have to do each region individually, but it saves having different files to work with :)