Skip to content

Instantly share code, notes, and snippets.

@perlpilot
Last active August 29, 2015 14:04
Show Gist options
  • Save perlpilot/e64383c7fde61c197f34 to your computer and use it in GitHub Desktop.
Save perlpilot/e64383c7fde61c197f34 to your computer and use it in GitHub Desktop.
#!/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