P3(just those characters) Then another that reads:
W Hwhere W is the image's width and H is its height.
#!/usr/bin/perl
use warnings;
use strict;
use GD::Simple;
# use standard input to read coordinates into array reference
my $coordinatesRef;
my $index = 0;
while (<>) {
chomp($_);
my @coordinates = split("\t", $_);
$coordinatesRef->[$index]->{x} = $coordinates[0];
$coordinatesRef->[$index]->{y} = $coordinates[1];
$coordinatesRef->[$index]->{r} = $coordinates[2];
$coordinatesRef->[$index]->{g} = $coordinates[3];
$coordinatesRef->[$index++]->{b} = $coordinates[4];
}
my $img = GD::Simple->new(maxX($coordinatesRef), maxY($coordinatesRef));
foreach my $coordinate (@$coordinatesRef) {
$img->fgcolor($coordinate->{r}, $coordinate->{g}, $coordinate->{b});
$img->rectangle($coordinate->{x}, $coordinate->{y}, $coordinate->{x}, $coordinate->{y});
}
print $img->png;
# subroutines
sub maxX {
my ($coordsRef) = @_;
my $result = 0;
foreach my $coord (@$coordsRef) {
if ($coord->{x} > $result) { $result = $coord->{x}; }
}
return $result;
}
sub maxY {
my ($coordsRef) = @_;
my $result = 0;
foreach my $coord (@$coordsRef) {
if ($coord->{y} > $result) { $result = $coord->{y}; }
}
return $result;
}imgScript.pl < myCoordinates.txt > myBitmap.png
<head><title>Your Title Here</title>
<style>
td {width:1px}
tr {height:1px}
</style>
</head>
<body>
<table border='0' cellspacing='0' cellpadding='0'>
<tr>
<td style='background-color: #ffffff'/>
<td style='background-color: #ffffff'/>
<td style='background-color: #ffffff'/>
<td style='background-color: #ffffff'/>
<td style='background-color: #ffffff'/>
<td style='background-color: #ffffff'/>
...
<td style='background-color: #000000'/>
<td style='background-color: #000000'/>
<td style='background-color: #000000'/>
</tr
></table>
</body>
</html>
This uses the pixels in hex; you can also useYou are not logged in, either login or create an account to post comments
posted by aubilenon at 4:43 PM on March 11