From 2e6574439f36069fc70ef5ade9182167bffb2a1e Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 7 Apr 2022 23:36:20 +0100 Subject: rename script --- katana.raku | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ slice.raku | 72 ------------------------------------------------------------- 2 files changed, 72 insertions(+), 72 deletions(-) create mode 100755 katana.raku delete mode 100755 slice.raku 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 { "" } + 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 }; +} + diff --git a/slice.raku b/slice.raku deleted file mode 100755 index ff9e6fa..0000000 --- a/slice.raku +++ /dev/null @@ -1,72 +0,0 @@ -#!/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 }; -} - -- cgit v1.2.3