#!/usr/bin/perl use warnings; use strict; use Imager; sub IMAGE_NAME () { "./189.php?image=1" } unlink IMAGE_NAME; system("/usr/local/bin/wget", "-U", "Mozilla", "http://drunkmenworkhere.org/189.php?image=1" ) and die $!; my $img = Imager->new(); $img->open( file => IMAGE_NAME, type => "png" ) or die $img->errstr(); my %coords; for (my $y = 0; $y < $img->getheight(); $y += 2) { for (my $x = 0; $x < $img->getwidth(); $x += 2) { my $color = $img->getpixel( x => $x, y => $y ); my $color_hash = sprintf("%2.2x%2.2x%2.2x", $color->rgba()); next if $color_hash eq "ffffff"; $coords{$color_hash} = [] unless exists $coords{$color_hash}; push @{$coords{$color_hash}}, [ $x, $y ]; } } my %freq; while (my ($color, $coords) = each %coords) { my $freq = @$coords; $freq{$freq} = [] unless exists $freq{$freq}; push @{$freq{$freq}}, $color; } foreach (sort { $b <=> $a } keys %freq) { printf "Frequency %6d = @{$freq{$_}}\n", $_; }