#!/usr/bin/perl # # Downsample ASCII art image with antialiasing use strict; my %dict = ( " " => " ", " X" => "o", " X " => "c", " XX" => "o", " X " => "`", " X X" => "]", " XX " => "/", " XXX" => "d", "X " => "'", "X X" => "\\", "X X " => "[", "X XX" => "b", "XX " => "\"", "XX X" => "9", "XXX " => "P", "XXXX" => "8", ); # Process input 2 lines at a time my @line = ("", ""); while( $line[0] = <> ) { chomp $line[0]; if( $line[1] = <> ) { chomp $line[1]; } else { $line[1] = ""; } # Get line length, round up to multiple of 2. my $width = length($line[0]); if( $width < length($line[1]) ) { $width = length($line[1]); } $width = ($width + 1) & ~1; # Pad lines so that they are of equal width. Also unify # non-whitespace characters. for(my $i = 0; $i < 2; $i++) { $line[$i] =~ s/\S/X/g; $line[$i] .= ' ' x ($width - length($line[$i])); } # Combine pixels for(my $i = 0; $i < $width; $i += 2) { my $cell = substr($line[0], $i, 2) . substr($line[1], $i, 2); print $dict{$cell}; } print "\n"; }