summaryrefslogtreecommitdiff
path: root/katana.raku
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2022-04-07 23:36:20 +0100
committerPaul Buetow <paul@buetow.org>2022-04-07 23:36:20 +0100
commit2e6574439f36069fc70ef5ade9182167bffb2a1e (patch)
tree0dfc065ceb5972e804a45ccdfdf49927d88b6b9b /katana.raku
parent476995151d43db28b78c7e4f2acfcd988c97ee4f (diff)
rename script
Diffstat (limited to 'katana.raku')
-rwxr-xr-xkatana.raku72
1 files changed, 72 insertions, 0 deletions
diff --git a/katana.raku b/katana.raku
new file mode 100755
index 0000000..ff9e6fa
--- /dev/null
+++ b/katana.raku
@@ -0,0 +1,72 @@
+#!/usr/bin/env raku
+
+sub prefix:<❱>( *@args ) {
+ say "❱ {@args}";
+ my $proc = run @args, :out, :err;
+ for $proc.out.slurp(:close), $proc.err.slurp(:close) {
+ .say if .chars > 0;
+ }
+}
+
+class Template {
+ has Str %!vars;
+ has Str $!frame = 'frame.html';
+}
+
+class Image {
+ has Str $!filename;
+ has Str $!source;
+ has Str $!dist-dir;
+
+ submethod BUILD(IO::Path :$source, Str :$dist-dir) {
+ $!filename = $source.basename;
+ $!source = $source.path;
+ $!dist-dir = $dist-dir;
+ }
+
+ method generate(Int :$thumb-geometry, Str :$bg-blur) {
+ my $thumb = "$!dist-dir/thumb/{$!filename}";
+ ❱ ['convert', '-auto-orient', '-geometry', $thumb-geometry, $!source, $thumb]
+ unless $thumb.IO.f;
+
+ my $blur = "$!dist-dir/blur/{$!filename}";
+ ❱ ['convert', '-flip', '-geometry', $thumb-geometry/2, '-blur', $bg-blur, $!source, $blur]
+ unless $blur.IO.f;
+
+ my $large = "$!dist-dir/large/{$!filename}";
+ ❱ ['cp', $!source, $large] unless $large.IO.f;
+ }
+
+ method thumb_tag { "<img class='thumb' src='./thumb/{$!filename}' />" }
+ method large_tag { "<img class='large' src='./large/{$!filename}' />" }
+}
+
+sub make-mr-proper(:$dist-dir) {
+ ❱ 'rm', '-r', '-f', $dist-dir if $dist-dir.IO.d;
+}
+
+sub ensure-directories(:$dist-dir) {
+ mkdir $dist-dir unless $dist-dir.IO.d;
+ .IO.d or mkdir $_ for $dist-dir <<~>> </large /blur /thumb>;
+}
+
+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 = 'Yay', #= Album title
+) {
+
+ my @images = dir($in-dir, test => { "$in-dir/$_".IO.f })
+ .map: { Image.new: source => $_, :$dist-dir };
+ @images = @images.pick: * if $randomize;
+
+ make-mr-proper :$dist-dir if $mr-proper;
+ ensure-directories :$dist-dir;
+
+ @images.hyper.map: { .generate: :$thumb-geometry, :$bg-blur };
+}
+