This is only quickly tested, I may have the shift order wrong, etc. The color count dosn't seem to agree with GD. Please test yourself to verify worthiness.
#!/usr/bin/perl use warnings; use strict; use Image::Magick; my $file = shift or die "Need a file $!\n"; my $img = Image::Magick->new; $img->ReadImage($file); $img->Quantize( colors => 18 ); $img->Set( type => 'Palette' ); #$img->Write("$0.png"); # if you want a pixel by pixel list of every color # a huge slow output #$img->Set(magick => 'txt'); #$img->Write("$0.txt"); #histogram #returned values are an array of #red, green, blue, opacity, and count values. my $tot = 0; my (@colors) = $img->Histogram(); #print join "\n\n", @colors; # probably some array slice would be better than multi-shifts, # any code improvement's welcome while (1){ if (scalar @colors == 0){last} my $r = shift @colors; my $g = shift @colors; my $b = shift @colors; my $o = shift @colors; my $count = shift @colors; $tot++; print "$count ($r,$g,$b) at $o opacity\n"; } print "\n$tot total colors\n";
In reply to Re: Reading an image palette
by zentara
in thread Reading an image palette
by leocharre
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |