Created
November 29, 2021 13:57
-
-
Save bduggan/a929bd7a063a74f896507955dcb7b316 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env raku | |
sub mk-thumb(IO::Path $src, Bool :$force) { | |
my $dst = "{$src.dirname}/thumb-{$src.basename}"; | |
return False if $dst.IO.e && !$force; | |
(shell "gm convert -auto-orient $src -thumbnail '400x400>' $dst") == 0; | |
} | |
multi files(IO::Path $f where *.f) { $f } | |
multi files(IO::Path $f where *.d) { | |
my @ls = $f.IO.dir( | |
test => { not .starts-with('thumb' | '.' ) } | |
); | |
@ls.map: { |files($_) } | |
} | |
multi MAIN($dir = "photos", | |
Bool :$n, #= dry run | |
Bool :$v, #= verbose | |
Bool :$force, #= force regenerate existing thumbnails | |
Int :$degree = 4, #= degree of parallelism | |
) { | |
say "dry run!" if $n; | |
&shell.wrap: -> |c { note c.raku if $n || $v; callsame unless $n } | |
my atomicint $converted = 0; | |
my atomicint $considered = 0; | |
files($dir.IO).race(:$degree).map: -> $f { | |
with ++⚛$considered { | |
note "$_ files considered" if $_ %% 100; | |
} | |
++⚛$converted if mk-thumb($f, :$force); | |
} | |
say "converted $converted out of $considered"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment