diff options
| author | Paul Buetow <paul@buetow.org> | 2022-04-06 22:12:24 +0100 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2022-04-06 22:12:24 +0100 |
| commit | 9d7768631e9429bd97924db65559b5277180785d (patch) | |
| tree | 4e24e1f6a8d1e891e579a6c0c90e71f802fe60fc | |
| parent | d9bf1401a5eaebca7d304ae07897ebe0605aa10c (diff) | |
more on this
| -rw-r--r-- | .gitignore | 1 | ||||
| -rwxr-xr-x | slice.raku | 72 |
2 files changed, 40 insertions, 33 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1521c8b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dist @@ -5,54 +5,60 @@ class Image { has Str $!thumb; has Str $!blur; - submethod BUILD(IO::Path :$source, Str :$outdir) { + submethod BUILD(IO::Path :$source, Str :$dist-dir) { $!source = $source.path; - $!thumb = "$outdir/thumbs/{$source.basename}"; - $!blur = "$outdir/blur/{$source.basename}"; + $!thumb = "$dist-dir/thumb/{$source.basename}"; + $!blur = "$dist-dir/blur/{$source.basename}"; } - multi method generate() { - self.generate(<-auto-orient -geometry 800>, dest => $!thumb) - unless $!thumb.IO.f; + method generate(Int :$thumb-geometry, Str :$bg-blur) { + my @args = 1, 2; + self.convert(@args); + #['-auto-orient', '-geometry']' + #['-auto-orient', '-geometry', $thumb-geometry, $!source, $!thumb]; - self.generate(<-flip -blur 0x8>, dest => $!blur) - unless $!blur.IO.f; + #@args = '-flip', '-geometry', $thumb-geometry/2, '-blur', $bg-blur, + # $!source, $!blur; + # self.generate(:@args); + #my @foo = 1, 2, 3; + #self.generate(@foo); } - multi method generate(Str :@args, Str :$dest) { + method convert(@args) { say @args; - @args.push: $!source; - @args.push: $dest; - say @args; - } -} - -sub make-mrproper() { + #return if $dest.IO.f; + #say "Generating $dest"; + #my $proc = run 'convert', (@args, $!source, $dest).flat, :out, :err; + #say $proc.out.slurp(:close); + #say $proc.err.slurp(:close); + #} } -sub make-thumb(IO::Path $image, Str :$thumb-dir) { - my $thumb = "$thumb-dir/{$image.basename}"; - return if $thumb.IO.f; +sub make-mr-proper(:$dist-dir) { + run 'rm', '-rf', $dist-dir if $dist-dir.IO.d; } -sub make-thumbs(:@images, Str :$outdir) { - my $thumb-dir = "$outdir/thumbs"; - mkdir $thumb-dir unless $thumb-dir.IO.d; - @images.hyper(batch => 10).map({ make-thumb $_, :$thumb-dir }); +sub ensure-directories(:$dist-dir) { + mkdir $dist-dir unless $dist-dir.IO.d; + .IO.d or mkdir $_ for $dist-dir <<~>> </large /blur /thumb>; } multi MAIN( - Bool :$mrproper, #= Clean output dir - Str :$indir = './indir', #= Input dir - Str :$outdir = './outdir', #= Output dir + 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 ) { - my @images = dir($indir, test => { "$indir/$_".IO.f }); - make-mrproper if $mrproper; - mkdir $outdir unless $outdir.IO.d; - #make-thumbs :@images, :$outdir; - @images.hyper(batch => 10).map({ - my \image = Image.new(source => $_, :$outdir); - image.generate; + my @images = dir($in-dir, test => { "$in-dir/$_".IO.f }); + + 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); }); } + |
