When I started my current job in web development at the university I attend, I was required to do a lot of work with HTML tables. I was put through a “table hell” as they call it. It happens that the last emplyee that was hired gets to make the “table hell” for the next incoming employee. I didn’t help create something really wild but the job of making this “table hell” gave me an evil idea. I wondered if I could create an HTML table that had all 1x1 pixel table data with nothing but a background color. That way I could, in a very inefficient way, display graphics using only HTML. I hadn’t learned perl at the time so I just keep the idea in my head.
Shortly thereafter I started learning perl, and decide to revisit this idea because it sounded like a somewhat easy task in perl. I decided that the best place to get data would be from and BMP file because of the lack of compression. After about ten minutes of coding I produced this very useless script that takes an ordinary windows BMP file and converts it into a HTML document.
#!/usr/bin/perl -w
use strict;
my $bmp = "pic.bmp";
my $html = "pic.html";
my $temp;
open (IN, "<$bmp") || die;
while(<IN>)
{
$temp .= $_;
}
close IN;
my $col = (ord(substr $temp,18,1)) + (256*(ord(substr $temp,19,1)));
my $row = (ord(substr $temp,22,1)) + (256*(ord(substr $temp,23,1)));
my $numread = $col * 3;
while ( ($numread % 4) != 0 )
{
$numread++;
}
open (OUT, ">$html") || die;
print OUT "<html><head></head><body><table border='0' cellpadding='0'
+cellspacing='0'>";
for (my $i = ($row-1); $i >= 0; $i--)
{
print OUT "<tr>";
for my $j (0..($col-1))
{
print OUT "<td height='1' width='1' bgcolor='#";
for (my $x = 2; $x >= 0; $x--)
{
my $temp1 = ord(substr($temp,54+$i*$numread+$j*3+$x,3));
print OUT sprintf "%02x",$temp1;
}
print OUT "'></td>";
}
print OUT "</tr>";
}
print OUT "</table></body></html>";
close OUT;
Beware running this script as it has almost no use. Also note that the output of a 400 by 400 BMP could be larger than 10MB. I havn't done extensive testing with this script either. I have only been using 24-bit BMP files created by windows paint.
UPDATED: Added some info on what BMP files I had been using.