| 1 |
#!/opt/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
no utf8; |
| 5 |
|
| 6 |
use Crossfire::Map; |
| 7 |
use Storable; |
| 8 |
use POSIX; |
| 9 |
use File::Compare; |
| 10 |
|
| 11 |
my $USAGE = "usage: gen_palette_from_plt <gridmap.arch.plt> <output.png>\n"; |
| 12 |
|
| 13 |
my @type; |
| 14 |
|
| 15 |
my $plt_file = $ARGV[0] || die $USAGE; |
| 16 |
my $out_file = $ARGV[1] || die $USAGE; |
| 17 |
|
| 18 |
open my $plt, $plt_file or die "Couldn't open $plt_file: $!\n"; |
| 19 |
|
| 20 |
for (<$plt>) { |
| 21 |
my ($arch, $color) = split /\s+/; |
| 22 |
push @type, [$arch, "#$color"] if $arch =~ /\S/; |
| 23 |
} |
| 24 |
|
| 25 |
mkdir "/tmp/$$.palette" |
| 26 |
or die "Couldn't make /tmp/$$.palette"; |
| 27 |
|
| 28 |
for (@type) { |
| 29 |
my ($name, $color) = @$_; |
| 30 |
$color =~ s/^#//; |
| 31 |
system ("convert -size 300x30 xc:\\#$color -pointsize 32 -fill \"red\" -gravity east -draw \"text 0,0 \\\"$name\\\"\" /tmp/$$.palette/$color.png"); |
| 32 |
} |
| 33 |
|
| 34 |
system ("convert -append " |
| 35 |
. join (' ', |
| 36 |
map { |
| 37 |
my $c = $_->[1]; $c =~ s/^#//; "/tmp/$$.palette/$c.png" |
| 38 |
} @type |
| 39 |
) |
| 40 |
. " $out_file" |
| 41 |
); |
| 42 |
|
| 43 |
system ("rm -r /tmp/$$.palette"); |
| 44 |
|