+
+ my $overlaymin = Imager->new(
+ xsize => $img->getwidth,
+ ysize => $img->getheight,
+ channels => 4,
+ );
+ my $overlaygas = $overlaymin->copy;
+ for my $unit ($map->units) {
+ my $info = $UNITINFO{ $unit->{id} } or next;
+ my ($name, $color, $xsize, $ysize) = @$info or next;
+ if ($name eq 'min') {
+ next if $unit->{amount} <= 8;
+ $overlaymin->circle(
+ x => 4 * ($unit->{x} + $xsize/2),
+ y => 4 * ($unit->{y} + $ysize/2),
+ r => 4 * ($unit->{amount} <= 40 ? 2 : 4),
+ color => $color,
+ filled => 1,
+ aa => 1,
+ );
+ }
+ elsif ($name eq 'gas') {
+ $overlaygas->circle(
+ x => 4 * ($unit->{x} + $xsize/2),
+ y => 4 * ($unit->{y} + $ysize/2),
+ r => 4 * ($unit->{amount} <= 40 ? 2 : 4),
+ color => $color,
+ filled => 1,
+ aa => 1,
+ );
+ }
+ }
+ $img->compose(src => $overlaymin, opacity => 0.1875);
+ $img->compose(src => $overlaygas, opacity => 0.125);
+
+ for my $unit ($map->units) {
+ my $info = $UNITINFO{ $unit->{id} }
+ or warn("No unit styling for unit #$unit->{id}"), next;
+ my ($name, $color, $xsize, $ysize, $sprite) = @$info;
+ if ($sprite) {
+ $img->paste(src => $sprite, x => $unit->{x}, y => $unit->{y});
+ }
+ else {
+ $img->box(
+ xmin => 4 * $unit->{x},
+ ymin => 4 * $unit->{y},
+ xmax => 4 * ($unit->{x} + ($xsize || 1)),
+ ymax => 4 * ($unit->{y} + ($ysize || 1)),
+ color => $color,
+ filled => 1,
+ );
+ }
+ }
+
+ $img->write(fd => fileno(STDOUT), type => 'png')
+ or die 'Cannot output image: ', $img->errstr;