summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2022-04-07 23:36:04 +0100
committerPaul Buetow <paul@buetow.org>2022-04-07 23:36:04 +0100
commit476995151d43db28b78c7e4f2acfcd988c97ee4f (patch)
treea59bd25abcd8069a1f0343e7bbc12c7567c9b7c2
parent94c3f21d7669ae10b81259e74f607880e5ab138e (diff)
use custom operator for shell execution
-rw-r--r--frame.html.templ8
-rwxr-xr-xslice.raku32
2 files changed, 28 insertions, 12 deletions
diff --git a/frame.html.templ b/frame.html.templ
new file mode 100644
index 0000000..4343552
--- /dev/null
+++ b/frame.html.templ
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ <title>{title}</title>
+ </head>
+ <body>
+ {body}
+ </body>
+</html>
diff --git a/slice.raku b/slice.raku
index de29307..ff9e6fa 100755
--- a/slice.raku
+++ b/slice.raku
@@ -1,13 +1,18 @@
#!/usr/bin/env raku
-sub cmd(Str $command, @args) {
- say "=> {$command} {@args}";
- my $proc = run $command, @args, :out, :err;
+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;
@@ -21,23 +26,23 @@ class Image {
method generate(Int :$thumb-geometry, Str :$bg-blur) {
my $thumb = "$!dist-dir/thumb/{$!filename}";
- cmd 'convert', ['-auto-orient', '-geometry', $thumb-geometry,
- $!source, $thumb]
- unless $thumb.IO.f;
+ ❱ ['convert', '-auto-orient', '-geometry', $thumb-geometry, $!source, $thumb]
+ unless $thumb.IO.f;
my $blur = "$!dist-dir/blur/{$!filename}";
- cmd 'convert', ['-flip', '-geometry', $thumb-geometry/2,
- '-blur', $bg-blur,
- $!source, $blur]
- unless $blur.IO.f;
+ ❱ ['convert', '-flip', '-geometry', $thumb-geometry/2, '-blur', $bg-blur, $!source, $blur]
+ unless $blur.IO.f;
my $large = "$!dist-dir/large/{$!filename}";
- cmd 'cp', [$!source, $large] unless $large.IO.f;
+ ❱ ['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) {
- cmd 'rm', <-r -f>, $dist-dir if $dist-dir.IO.d;
+ ❱ 'rm', '-r', '-f', $dist-dir if $dist-dir.IO.d;
}
sub ensure-directories(:$dist-dir) {
@@ -51,10 +56,13 @@ multi MAIN(
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;