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.


In reply to Table Pictures by fenonn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.