diff options
| author | Paul Buetow <paul@buetow.org> | 2022-04-07 22:04:45 +0100 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2022-04-07 22:04:45 +0100 |
| commit | 94c3f21d7669ae10b81259e74f607880e5ab138e (patch) | |
| tree | d844ae796674ab3b9ac9ccf96ee01679ea57dcb4 /slice.raku | |
| parent | f49aa7371424d3a12364ef223889ec1f7c532d0f (diff) | |
refactor
Diffstat (limited to 'slice.raku')
| -rwxr-xr-x | slice.raku | 47 |
1 files changed, 23 insertions, 24 deletions
@@ -1,37 +1,38 @@ #!/usr/bin/env raku +sub cmd(Str $command, @args) { + say "=> {$command} {@args}"; + my $proc = run $command, @args, :out, :err; + for $proc.out.slurp(:close), $proc.err.slurp(:close) { + .say if .chars > 0; + } +} + class Image { + has Str $!filename; has Str $!source; - has Str $!thumb; - has Str $!blur; - has Str $!large; + has Str $!dist-dir; submethod BUILD(IO::Path :$source, Str :$dist-dir) { + $!filename = $source.basename; $!source = $source.path; - $!thumb = "$dist-dir/thumb/{$source.basename}"; - $!blur = "$dist-dir/blur/{$source.basename}"; - $!large = "$dist-dir/large/{$source.basename}"; + $!dist-dir = $dist-dir; } 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; + $!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; + $!source, $blur] + unless $blur.IO.f; - cmd 'cp', [$!source, $!large] unless $!large.IO.f; - } -} - -sub cmd(Str $command, @args) { - say "=> {$command} {@args}"; - my $proc = run $command, @args, :out, :err; - for $proc.out.slurp(:close), $proc.err.slurp(:close) { - .say if .chars > 0; + my $large = "$!dist-dir/large/{$!filename}"; + cmd 'cp', [$!source, $large] unless $large.IO.f; } } @@ -52,14 +53,12 @@ multi MAIN( Str :$bg-blur = '0x8', #= Background blur factor ) { - my @images = dir($in-dir, test => { "$in-dir/$_".IO.f }); + my @images = dir($in-dir, test => { "$in-dir/$_".IO.f }) + .map: { Image.new: source => $_, :$dist-dir }; make-mr-proper :$dist-dir if $mr-proper; ensure-directories :$dist-dir; - @images.hyper.map({ - my $image = Image.new: source => $_, :$dist-dir; - $image.generate: :$thumb-geometry, :$bg-blur; - }); + @images.hyper.map: { .generate: :$thumb-geometry, :$bg-blur }; } |
