#this is a mix of code from various other things and is largely created #by stripping out the bulk of ThousandWords #use strict;#this doesn't like the open/close stuff... whatever use warnings; use GD; open(FILE_IMG, 'testNumber.png') or die('horribly'); my $image = newFromPng GD::Image(FILE_IMG) or die('miserably'); close(FILE_IMG) or die('pathetically'); my ($x, $y) = $image->getBounds(); my $cssStr = 'div{position:absolute;margin:0;width:1px;padding:0;font-size:1px;line-height:1px} body>div{height:1px;}/* hide height from IE6 */'; my $htmlStr = ''; my $xx = 0; my $yy = 0; my $index0; my $index1; my $index2; my ($r0,$g0,$b0); my ($r1,$g1,$b1); my ($r2,$g2,$b2); my $color0 = ''; my $color1 = ''; my $color2 = ''; my $colorTest = ''; my %colorToClass = (); my %classToColor = (); #this cheats via Photoshop so that I know each dimension is evenly divisible by 3 #54x18 in our example #that means there will be 18 divs across and technically in that case it doesn't matter how many down #but in this case it is 18 divs down #so 18 * 18 divs gives us a total div count of 324 and then some very small subportion of that for classes #since there is a massive overlap of color here - technically should be about two colors in this #but with any anti-aliasing and whatnot, there could be more my $pixelCount = $x * $y; my $classCount = 0; my $divCount = 0; for ($yy = 0; $yy < $y; $yy++) { #we are going to jump by 3 and then look at 3 at a time for ($xx = 0; $xx < $x; $xx += 3) { $index0 = $image->getPixel($xx, $yy); $index1 = $image->getPixel(($xx + 1), $yy); $index2 = $image->getPixel(($xx + 2), $yy); ($r0,$g0,$b0) = $image->rgb($index0); ($r1,$g1,$b1) = $image->rgb($index1); ($r2,$g2,$b2) = $image->rgb($index2); $color0 = '#' . sprintf("%.2X%.2X%.2X", $r0, $g0, $b0); $color1 = '#' . sprintf("%.2X%.2X%.2X", $r1, $g1, $b1); $color2 = '#' . sprintf("%.2X%.2X%.2X", $r2, $g2, $b2); $colorTest = $color0 . $color1 . $color2; #now see if this color exists, if it does not, then create one if($colorToClass{$colorTest}){ #this color already exists, so we do not need to create it $htmlStr .= '