Imager-File-SIXEL
view release on metacpan or search on metacpan
tools/make-images view on Meta::CPAN
},
{
name => 'sixel-palette',
source => 'scene',
panels => [
['original'],
["sixel_palette => 'adaptive'", { sixel_palette => 'adaptive' }],
["sixel_palette => 'webmap'", { sixel_palette => 'webmap' }],
["sixel_palette => 'webmap',\nsixel_dither => 'none'", { sixel_palette => 'webmap', sixel_dither => 'none' }],
],
},
{
name => 'colors',
source => 'scene',
panels => [
['original'],
["colors => [8 colors picked by hand\nfrom the picture]", { colors => \@picked }],
['colors => [8 basic colors]', { colors => \@basic }],
['colors => [4 grays]', { colors => \@grays }],
["colors => ['black', 'white']", { colors => ['black', 'white'] }],
],
},
{
name => 'sixel-alpha-threshold',
source => 'alpha',
panels => [
['original'],
['sixel_alpha_threshold => 0', { sixel_alpha_threshold => 0 }],
['sixel_alpha_threshold => 1', { sixel_alpha_threshold => 1 }],
['sixel_alpha_threshold => 128', { sixel_alpha_threshold => 128 }],
['sixel_alpha_threshold => 224', { sixel_alpha_threshold => 224 }],
],
},
{
name => 'sixel-pan-pad',
source => 'scene',
panels => [
['sixel_pan => 1, sixel_pad => 1', { sixel_pan => 1, sixel_pad => 1 }, 'aspect'],
['sixel_pan => 2, sixel_pad => 1', { sixel_pan => 2, sixel_pad => 1 }, 'aspect'],
],
},
);
my $outdated = updatePodPictures([glob('lib/Imager/File/SIXEL.pm lib/Imager/File/SIXEL/*.pod')], "v$Imager::File::SIXEL::VERSION", $options{check}, map { $_->{name} } @figures);
my $font = labelFont();
my %sources = (scene => scenePicture(), alpha => alphaPicture());
foreach my $figure (@figures) {
my $image = renderFigure($figure, $sources{ $figure->{source} }, $font);
my $file = File::Spec->catfile($options{output}, "$figure->{name}.png");
$outdated += storeImage($image, $file, $options{check});
}
exit($options{check} && $outdated ? 1 : 0);
# Dies unless the pod files together show exactly the pictures this
# script renders, each through an
# <img src="IMAGE_URL_BASE/TAG/images/NAME.png"> tag, then points every
# such tag to $tag. Returns the number of pod files that were (or, with
# $checkOnly, would be) changed. tools/pod2markdown turns the URLs into
# those of the master branch for the Markdown files.
sub updatePodPictures($podFiles, $tag, $checkOnly, @names) {
my $imageUrl = qr{<img src="\Q@{[IMAGE_URL_BASE]}\E/[^"/]+/images/([^"/]+)\.png"};
my (%shown, %updatedPods);
foreach my $podFile ($podFiles->@*) {
my $pod = readFile($podFile);
my @imageTags = $pod =~ m{(<img\b[^>]*>)}g;
my @badTags = grep { !/^$imageUrl/ } @imageTags;
die map {"$podFile: $_ does not start with <img src=\"@{[IMAGE_URL_BASE]}/TAG/images/NAME.png\"\n"} @badTags if @badTags;
$shown{$_} = 1 foreach $pod =~ m{$imageUrl}g;
(my $updated = $pod) =~ s{(<img src="\Q@{[IMAGE_URL_BASE]}\E/)[^"/]+/}{$1$tag/}g;
$updatedPods{$podFile} = $updated if $updated ne $pod;
}
my %rendered = map { $_ => 1 } @names;
my @problems = (
(map {"the pod shows images/$_.png, which this script does not render\n"} grep { !$rendered{$_} } sort keys %shown),
(map {"no pod shows images/$_.png\n"} grep { !$shown{$_} } @names),
);
die @problems if @problems;
storeFile($_, $updatedPods{$_}, $checkOnly) foreach sort keys %updatedPods;
return scalar keys %updatedPods;
}
sub labelFont() {
die "Imager was built without FreeType support; it is needed for the labels\n"
unless $Imager::formats{ft2};
open(my $match, '-|', 'fc-match', '--format=%{file}', 'DejaVu Sans:style=Book')
or die "cannot run fc-match: $!\n";
my $file = <$match>;
close($match);
die "fc-match found no font\n" unless defined $file && -f $file;
return Imager::Font->new(file => $file, size => FONT_SIZE, color => '#202020', aa => 1)
// die Imager->errstr, "\n";
}
# A sunset: smooth gradients that show banding, a hue ramp that shows
# the limits of a palette, and single pixel stars that show fine detail.
sub scenePicture() {
my ($width, $height) = (PICTURE_WIDTH, PICTURE_HEIGHT);
my $picture = Imager->new(xsize => $width, ysize => $height);
$picture->box(fill => Imager::Fill->new(
fountain => 'linear',
xa => 0, ya => 0,
xb => 0, yb => 90,
segments => Imager::Fountain->simple(
positions => [0, 0.55, 1],
colors => [map { Imager::Color->new($_) } '#0B1D51', '#7A3E9D', '#F6A04D'],
),
));
$picture->box(fill => Imager::Fill->new(
fountain => 'radial',
combine => 'normal',
xa => 112, ya => 70,
xb => 150, yb => 70,
segments => Imager::Fountain->simple(
positions => [0, 1],
colors => [Imager::Color->new(255, 233, 168, 220), Imager::Color->new(255, 233, 168, 0)],
),
));
$picture->circle(x => 112, y => 70, r => 14, color => '#FFD98A', aa => 1);
( run in 1.261 second using v1.01-cache-2.11-cpan-500dd33cbaf )