#!/usr/bin/perl -w use strict; use GD; # this lib is so cool my $imagename = shift; # get the user specified image my $image = GD::Image->new($imagename) || die "Could not open image: $ +imagename\n"; # get the image size my ($width, $height) = $image->getBounds(); # build the seed color... my $index = $image->getPixel(0, 0); my ($r,$g,$b) = $image->rgb($index); # now format it as 2 digit hex my $color = sprintf "%02x%02x%02x", $r, $g, $b; my $lastcolor = ""; my $count; # the stylesheet is necessary to make the end result acceptably small my $results = "<STYLE>.sm { font-size: 2px; font-family: sans-serif }< +/STYLE>\n"; $results .= "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=$width +HEIGHT=$height>"; # loop through the pixels for (my $x = 0; $x < $height; $x++) { $count = 0; $results .= "<TR>"; for (my $y = 0; $y < $width; $y++) { $count++; # get the color of the current pixel $index = $image->getPixel($y, $x); ($r,$g,$b) = $image->rgb($index); $color = sprintf "%02x%02x%02x", $r, $g, $b; # we use this to build a COLSPAN length # this greatly enhances efficiency if ($color ne $lastcolor) { $count = $count * 2; $results .= "<TD CLASS=sm BGCOLOR=\"$lastcolor +\" COLSPAN=$count>_</TD>"; $count = 0; } $lastcolor = $color; } $count = $count * 2; $results .= "<TD CLASS=sm BGCOLOR=\"$lastcolor\" COLSPAN=$coun +t>_</TD>"; $results .= "</TR>\n"; } $results .= "</TABLE>"; print "$results\n";

In reply to Image to table converter by bastard

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.