Last active
August 29, 2015 14:04
-
-
Save perlpilot/e64383c7fde61c197f34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use 5.010; | |
use strict; use warnings; | |
use Data::Dumper; | |
use Image::Magick; | |
my $image = Image::Magick->new; | |
$image->Read('cpira-weirdness.png'); | |
$image->Quantize(colors=>256); | |
my @histo = $image->Histogram(); | |
my @colors; | |
while (my @color = splice @histo, 0, 5) { | |
push @colors, [ @color ]; # r, g, b, opacity, count | |
} | |
# sort descending so that the first one is the most common color | |
@colors = sort { $b->[4] <=> $a->[4] } @colors; | |
say Dumper \@colors; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment