Skip to content

Instantly share code, notes, and snippets.

@audreyt
Created October 18, 2014 15:37
Show Gist options
  • Save audreyt/fb6695ee980b2f782b75 to your computer and use it in GitHub Desktop.
Save audreyt/fb6695ee980b2f782b75 to your computer and use it in GitHub Desktop.
Raster Line txt decoder
# CC0 Public Domain (唐鳳)
use Imager;
my $img = Imager->new( xsize => 512, ysize => 512, channels=>1 );
my $color = Imager::Color->new( 255, 255, 255 );
my $dir = 0;
die "Usage: $0 input.txt" unless @ARGV;
while (<>) {
if (/^(\d+),\d+\s*$/) {
$dir = $1;
next;
}
/(\d+),(\d+),(\d+)/ or next;
if ($dir == 1) {
my ($x, $y1, $y2) = ($1, $2, $3);
$img->line(x1 => $x, x2 => $x, y1 => $y1, y2 => $y2, color => $color);
}
else {
my ($y, $x1, $x2) = ($1, $2, $3);
$img->line(x1 => $x1, x2 => $x2, y1 => $y, y2 => $y, color => $color);
}
}
$img->write(file=>'output.png');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment