Create Wesnoth maps from images

Brainstorm ideas of possible additions to the game. Read this before posting!

Moderators: Forum Moderators, Developers

Forum rules
Before posting a new idea, you must read the following:
Post Reply
User avatar
Viliam
Translator
Posts: 1341
Joined: January 30th, 2004, 11:07 am
Location: Bratislava, Slovakia
Contact:

Create Wesnoth maps from images

Post by Viliam » November 19th, 2005, 11:24 pm

I have made a tool that maybe some map creators will find useful. The basic idea is that the map editor will never give you the same comfort as a picture editor. (For example, imagine that you are trying to make the 100x100 map of an island with a shape of perfect circle. Now compare how easy is it to make a circle in a 100x100 pixel bitmap in MS Paint.) So my proposal is this:

1. Prepare a rough design of a map in a picture editor
2. Convert the picture to a map
3. Finish the map in the map editor

You must have installed Perl language, ImageMagick application, and PerlMagick API, and the small tool I have attached here.

Unzip the archive inside a new directory. You can modify the configuration file "colormap.txt" to specify which color means which terrain type. (The colors do not have to match exactly... for any pixel in picture the closest color is chosen.) Create a picture between 20x20 and 200x200 pixels, and save it as "map.bmp" into the same directory. Now, start the Perl script. The map will be written to file "map.txt"; you can copy it to Wesnoth working directory, and finish it in editor (for example, add player start locations).

This is just the first version; if anyone will like this tool, I can add a few new features (e.g. specifying input file name as a command line parameter, ability to resize bigger pictures,...). Also you can modify this tool as you wish.


EDIT: Removed obsolete attachments
Last edited by Viliam on January 12th, 2006, 2:47 pm, edited 1 time in total.

Tux2B
Posts: 1217
Joined: March 29th, 2005, 8:18 pm
Location: Toulouse (South of France)
Contact:

Post by Tux2B » November 20th, 2005, 11:15 am

Intersting, although I think it would be better if bitmap images could be bigger.
"There are two kind of campaign strategies : the good and the bad ones. The good ones almost always fail because of unforeseen consequences that make the bad ones succeed." -- Napoleon

User avatar
Ankka
Posts: 594
Joined: January 2nd, 2005, 2:40 pm
Location: Finland

Post by Ankka » November 20th, 2005, 3:07 pm

Tux2B wrote:Intersting, although I think it would be better if bitmap images could be bigger.
Why? Images can be resized.

User avatar
Viliam
Translator
Posts: 1341
Joined: January 30th, 2004, 11:07 am
Location: Bratislava, Slovakia
Contact:

Post by Viliam » November 21st, 2005, 12:29 am

Technically, the program will process pictures of any size. But 200x200 seems to be a limit for the Wesnoth map size (at least the map editor will not make a bigger map).

For more pleasant editing you can zoom the picture. Or edit a bigger image, and then resize it before converting. (For example the ImageMagick program is good for simple operations with pictures.)


(However, in my next free time I will do the "resize" feature, which will take more pixels, translate each of them into terrain, and choose the most frequent terrain. This is more correct solution than finding a terrain for average color, because for example if there is a terrain A for light green, terrain B for dark green, and terrain C for black; a group of light green and black pixels should be converted to A or C, never to B.)

User avatar
Viliam
Translator
Posts: 1341
Joined: January 30th, 2004, 11:07 am
Location: Bratislava, Slovakia
Contact:

Post by Viliam » November 23rd, 2005, 1:01 am

Here is the updated version of the tool, it supports some command-line parameters, all of them optional:

--image <image-file>
The input image ("map.bmp" by default).

--map <map-file>
The output map ("map.txt" by default).

--colormap <config-file>
The configuration file with "color to terrain" rules ("colormap.txt" by default).

--zoom <factor>
How many pixels in the image should be converted to one map hex (integer; 1 by default).

--noeven
Do not shift even-numbered columns.

So, the basic work is the same - define your colors, make a picture, run a script, finish the map in Wesnoth map editor.

New feature is zooming the picture, for example to make map 100x100 you can make picture 300x300 and then zoom by factor 3. Each map field is calculated from 9 pixels (3×3), and the most frequent terrain wins.

When zooming, program will shift even-numbered columns (by half of zoom factor), to make map more precisely reflect the picture. Just look at the explanation picture, for different zooms which pixels are used to calculate which map field. For example with zoom 3 even-numbered columns are shifted down by 1 pixel (3÷2), so you have to make picture 300x301 to receive 100x100 map.

The program is not very fast; I just made it, there is no speed optimization done yet. Anyway, one does not need to run it often. If you will use it for scenarios, please tell me. ;-)
Attachments
The map in the Wesnoth map editor.
The map in the Wesnoth map editor.
screen.bmp.jpeg (112.58 KiB) Viewed 2618 times
The original picture.
The original picture.
map.bmp.png (1.97 KiB) Viewed 2617 times
Which pixels are used to calculate which map hex (with and without &quot;--noeven&quot; option).
Which pixels are used to calculate which map hex (with and without "--noeven" option).
even.bmp.png (1.61 KiB) Viewed 2614 times

User avatar
Viliam
Translator
Posts: 1341
Joined: January 30th, 2004, 11:07 am
Location: Bratislava, Slovakia
Contact:

Post by Viliam » November 23rd, 2005, 1:02 am

And this is the program in Perl...
Attachments
colormap.zip
The color-map tool.
(6.58 KiB) Downloaded 189 times

Post Reply