Leser: 29
Guest AlfDer Hintergrund aendert sich ja immer..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#!/usr/bin/perl use strict; use warnings; use Image::Magick; { my @color = ( [ 255, 0, 0 => 'red' ], [ 0, 255, 0 => 'green' ], [ 0, 127, 255 => 'blue' ], [ 255, 0, 255 => 'pink' ], [ 255, 255, 0 => 'yellow' ], [ 255, 127, 0 => 'orange' ], [ 255, 255, 255 => 'white' ], ); my $tolerance = 64; sub get_approximate_color { my( $r, $g, $b ) = map int( ($_+1) / (2**16) * 255 ), @_; for my $c ( @color ) { return $c->[3] if $c->[0]-$tolerance < $r and $c->[0]+$tolerance > $r and $c->[1]-$tolerance < $g and $c->[1]+$tolerance > $g and $c->[2]-$tolerance < $b and $c->[2]+$tolerance > $b; } # for } # get_approximate_color } for my $file ( @ARGV ) { my $img = Image::Magick->new; $img->Read($file); my %col; my( $w, $h ) = ( $img->Get('width'), $img->Get('height') ); for my $y ( 1 .. $h ) { for my $x ( 1 .. $w ) { my $color = get_approximate_color( $img->GetPixel(x=>$x,y=>$y,normalize=>0) ); $col{$color}++ if length $color; } # for } # for my $most = (sort { $col{$b} <=> $col{$a} } keys %col)[0]; print "$file : $most\n"; } # for