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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#!/usr/bin/env raku
use v6.d;
use lib 'lib';
use Katana::Exec::Command;
use Katana::HTML::Generate;
use Katana::HTML::Tag;
use Katana::Image::Elem;
use Katana::Walk::Dir;
sub camera-stats(@images) {
my %cameras;
%cameras{.camera}++ for @images;
return %cameras.sort(*.value).reverse;
}
multi MAIN(
Bool :$mr-proper, #= Clean output dir
Str :$in-dir = './in', #= Input dir
Str :$dist-dir = './dist', #= Output dir
Int :$thumb-geometry = 800, #= Thumbnail geometry
Str :$bg-blur = '0x8', #= Background blur factor
Bool :$randomize = True, #= Randomize order of images
Str :$title = 'Katana album', #= Album title
Int :$degree = 4, #= Degree of parallelism
) {
my $doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
my @html-elems;
push @html-elems, Tag.new: name => 'html',
params => (
xmlns => 'http://www.w3.org/1999/xhtml',
lang => 'en',
'xml:lang' => 'en'
);
push @html-elems, Tag.new: name => 'head',
succ => [Tag.new: name => 'body'];
push @html-elems, Tag.new: name => 'title',
text => $title;
generate-from-tags $doctype, @html-elems;
my @images = dir($in-dir, test => { "$in-dir/$_".IO.f }).map:{
Elem.new: source => $_, :$dist-dir
};
say "Found {@images.elems} images";
@images = @images.pick: * if $randomize;
dir-cleanup-nonexistent $dist-dir, @images;
dir-make-mr-proper $dist-dir if $mr-proper;
dir-ensure $dist-dir;
@images.hyper(:$degree).map:{
.get-camera-model;
.generate: :$thumb-geometry, :$bg-blur;
};
.say for camera-stats @images;
}
|