#!/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 = "\n"; $results .= ""; # loop through the pixels for (my $x = 0; $x < $height; $x++) { $count = 0; $results .= ""; 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 .= ""; $count = 0; } $lastcolor = $color; } $count = $count * 2; $results .= ""; $results .= "\n"; } $results .= "
__
"; print "$results\n";