X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/d04b40e629676a9b8fdd015d4b432e121925749b..54ea9d7c62215933a9b77f16b28717ea65a178ad:/termcol.plp
diff --git a/termcol.plp b/termcol.plp
index 0b3d236..73bf0d2 100644
--- a/termcol.plp
+++ b/termcol.plp
@@ -14,6 +14,8 @@ Html({
stylesheet => [qw'light dark'],
});
+my $imgfile = $get{img} // exists $get{img} && 'indi.png';
+
my @termlist;
push @termlist, split /\W+/, $ENV{PATH_INFO} || 'default';
@@ -42,6 +44,7 @@ print
<:
+use 5.010;
use Shiar_Sheet::Colour '1.03';
use List::Util qw( min max );
@@ -69,6 +72,24 @@ sub colcell {
return "$out\n";
}
+sub img_egapal {
+ my ($palette) = @_;
+ return eval {
+ require Imager;
+ require MIME::Base64;
+
+ my @imgpal = map { Imager::Color->new(ref $_ ? @$_ : $_) } @{$palette};
+ state $img = Imager->new(file => "data/$imgfile")
+ or die Imager->errstr.$/;
+ @{[ $img->getcolors ]} == @imgpal
+ or die "incompatible palette size\n";
+ $img->setcolors(colors => \@imgpal);
+ $img->write(data => \my $imgdata, type => 'png');
+ return sprintf '
',
+ MIME::Base64::encode_base64($imgdata);
+ } || $@;
+}
+
for my $term (@termlist) {
my $info = $palettes->{$term};
ref $info eq 'HASH' or next;
@@ -104,6 +125,8 @@ for my $term (@termlist) {
$name = [ $name, ['#333'] ] if $term eq 'xkcd';
print '
', colcell($name, $rgb);
}
+
+ print '
', img_egapal(\@{$colours}) if $imgfile;
print "\n\n";
}
}
@@ -168,10 +191,17 @@ sub coltable_hsv {
my $colbreak = scalar map { @$_ } @colmap; # same width as hue rows
for my $num (sort { $greymap{$a} <=> $greymap{$b} } keys %greymap) {
$out .= ' |
' unless $col++ % $colbreak;
- $out .= colcell($num, ($greymap{$num}) x 3);
+ $out .= colcell($num, ($greymap{$num}));
}
}
+ if ($imgfile) {
+ my @palette = map { [ @{$_}[1 .. 3] ] } map {@$_} map {@$_} @colmap;
+ my $imgdata = img_egapal(\@palette);
+ my $tablespan = scalar map { @$_ } @colmap;
+ $out .= "
$imgdata";
+ }
+
return $out;
}
|