#!/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 { "" } method large_tag { "" } } 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 <<~>> ; } 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 }; }