summaryrefslogtreecommitdiff
path: root/slice.raku
blob: f1af53627da4f318bfe89916ccfbdadc1c6f957b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env raku

class Image {
  has Str $!source;
  has Str $!thumb;
  has Str $!blur;

  submethod BUILD(IO::Path :$source, Str :$outdir) {
    $!source = $source.path;
    $!thumb = "$outdir/thumbs/{$source.basename}";
    $!blur = "$outdir/blur/{$source.basename}";
  }

  multi method generate() {
    self.generate(<-auto-orient -geometry 800>, dest => $!thumb)
      unless $!thumb.IO.f;

    self.generate(<-flip -blur 0x8>, dest => $!blur)
      unless $!blur.IO.f;
  }

  multi method generate(Str :@args, Str :$dest) {
    say @args;
    @args.push: $!source;
    @args.push: $dest;
    say @args;
  }
}

sub make-mrproper() {
}

sub make-thumb(IO::Path $image, Str :$thumb-dir) {
  my $thumb = "$thumb-dir/{$image.basename}";
  return if $thumb.IO.f;
}

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 });
}

multi MAIN(
  Bool :$mrproper,           #= Clean output dir
  Str :$indir = './indir',   #= Input dir
  Str :$outdir = './outdir', #= Output dir
) {

  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;
  });
}