Automatically Generating Border Images

Contribute art for mainline Wesnoth.

Moderator: Forum Moderators

Forum rules
Before posting critique in this forum, you must read the following thread:
Post Reply
Dave
Founding Developer
Posts: 7071
Joined: August 17th, 2003, 5:07 am
Location: Seattle
Contact:

Automatically Generating Border Images

Post by Dave »

A user has submitted a Perl script which appears to be able to automatically generate border images for tiles. The way it works is by copying the way in which border tiles are done for an existing terrain type.

The script can be found in CVS at tools/mk-edges.pl

For instance, if you made a new terrain type, 'lava.png' and you wanted to have the same style of edges as snow does, you could run the command

tools/mk-edges.pl images/terrain/lava images/terrain/snow

and it'd make the edges for you.

Note: this Perl script requires some image manipulation programs be present on your system. I haven't got these programs on my system, so I've been unable to test the script, however the user has sent me the output for caves, and it seems to work well.

The complete script is also found below.

David

---

Code: Select all

print "usage: $0 <input> <stem>" and exit 0 if $#ARGV != 1;
my ($input,$stem) = @ARGV;

sub process {
    my $in=shift || die;
    my $edge=shift || die;
    my $out=shift || die;

    system <<EOF;
    pngtopnm -alpha $edge >/tmp/edge-alpha.pgm;
    pngtopnm $edge >/tmp/edge.ppm;
    ppmtopgm /tmp/edge.ppm >/tmp/edge.pgm;
    pngtopnm $in >/tmp/bg.ppm;

    pnmcomp -alpha=/tmp/edge.pgm /tmp/bg.ppm /tmp/edge.ppm | pnmtopng -alpha /tm
p/edge-alpha.pgm >$out;
EOF
}

foreach (glob "${stem}-*.png") {
    my $edge=$1 if /$stem-(.*).png/;
    if($edge=~/^[news-]*$/) {
        process("${input}.png","${stem}-${edge}.png","${input}-${edge}.png");
    }
}
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
telex4
Posts: 404
Joined: December 14th, 2003, 1:24 am
Location: Reading, UK
Contact:

Post by telex4 »

I tried it, but I got empty files and this error with the last of the commands it uses:

usage: pnmcomp [-invert] [-xoff N] [-yoff N] [-alpha file] overlay [image] [output]
pnmtopng: EOF / read error reading magic number

Maybe I'll try to work it out in the morning :wink:
jp30
Posts: 124
Joined: April 2nd, 2004, 10:59 am
Contact:

mk-edges.pl

Post by jp30 »

Hi, I'm the author of mk-edges.pl... I was designing a scenario set "in the land of the Dead" and decided to make it mostly cave and road, hence the need for transitions between those tile types.

Anyway, a few comments on mk-edges.pl. It's really a simple hack and wasn't intended to do much more than I've already used it for - though it could be used on other tile types that are simple tilable 2d patterns (like cave - it would probably work on road too). It works because snow is white, and the snow transitions can therefore be used as a mask on other tile types - if you multiply a snow transition by a pattern the pattern shows up in the white parts of the snow, and the black border of the snow ends up black; then you can use the alpha channel of the snow transition image as the alpha channel of the new image.

The graphics manipulation package needed is netpbm. Telex4, try upgrading your netpbm to version 9.24 or removing the = sign in the pnmcomp invocation.
telex4
Posts: 404
Joined: December 14th, 2003, 1:24 am
Location: Reading, UK
Contact:

Post by telex4 »

Well here is an example generated between snow and grassland.
Post Reply