summaryrefslogtreecommitdiff
path: root/slice.raku
diff options
context:
space:
mode:
Diffstat (limited to 'slice.raku')
-rwxr-xr-xslice.raku32
1 files changed, 20 insertions, 12 deletions
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;