#!/usr/bin/perl
###############################################################################################################
#
# img2col [-d <N>] *.jpg
#
# Liefert auf STDOUT eine HTML-Seite mit den <N> (default=2) Hauptfarben der übergebenen JPGs 

my($n,$m)=(2,6);

print qq{<html><body>};

foreach(@ARGV)
{
 $n=$1,$m=3*$1 if(/^-(\d+)$/);

 if(/^(.*\.jpg)$/)
 {
  print qq{<div style="float:left;padding:10px"><center><h5 style="align=center">$_</h5></center>};

  my $hist=qx{convert "$_" +dither -colors $m -format %c histogram:info:-|sort -n|tail -$n}; $hist=~s/(#[0-9a-fA-F]{6})/div($1)/ge;

  print qq{</div>};
}}
print qq{</body></html>};

sub div { my($col)=@_; print qq{<div style="background:$col; width:100px; height:100px"> $col </div>}; }