stitch-level.pl

This script uses GD to stitch 100 screenshots from Montezuma's Revenge into a single PNG with a map of each level. The script is not intended for use as is (but rather for inspiration if you want to do something similar), and is therefore rather crude, especially concerning the hard-coded paths to the files, and the command line arguments.

If you are not satisfied with the listing below, you can also download stitch-level.pl.

#!/usr/bin/perl -w
use GD;

$screen_w=320;
$screen_h=197;
$num_w=19;
$num_h=10;

$fullImage=GD::Image->new($screen_w*$num_w,$screen_h*$num_h);
$bg=$fullImage->colorAllocate(0,0,0); 
$fullImage->filledRectangle(0,0,$screen_w*$num_w,$screen_h*$num_h,$bg);

$level=shift or die("Must have one argument (level-number)");

while (<perfect/l$level/*.png>) {
    $fil=$_;
    if (/^.*\/([a-s])([0-9])\.png$/) {
	$s=ord($1)-ord('a');
	$t=int($2);
	print("processing level$level $1$2 at ($s,$t)\n");
my $screen = GD::Image->new($fil);
	$fullImage->copy($screen,$s*$screen_w,$t*$screen_h,0,0,$screen_w,$screen_h);
    }
}

$imageName="montezuma-$level.png";
open(IMAGEOUT,">$imageName") or die("Could not open file $imageName for writing");
binmode IMAGEOUT;
print IMAGEOUT $fullImage->png;
close IMAGEOUT;
Last updated: 2007.01.24