add gallery site stuff

This commit is contained in:
rhiannon morris 2023-11-20 18:43:59 +01:00
parent e60a61ee76
commit 4093b1ceda
1 changed files with 13 additions and 7 deletions

View File

@ -12,6 +12,8 @@ unit sub MAIN(
Format :i(:$itaku) is copy = DEFAULT,
#| format to use for furaffinity/weasyl
Format :f(:$furaffinity) is copy = DEFAULT,
#| format to use for gallery.n.w
Format :g(:$gallery) is copy = DEFAULT,
#| webp/jpg quality setting (default 98)
Int :Q(:$quality) = 98,
#| only run conversions explicitly mentioned
@ -38,6 +40,7 @@ die "furaffinity/weasyl don't know what webp are" if $furaffinity == webp;
$mastodon ||= $only ?? skip !! webp;
$itaku ||= $only ?? skip !! webp;
$furaffinity ||= $only ?? skip !! png;
$gallery ||= $only ?? skip !! webp;
(@files .= map: *.IO) ||= $*CWD.dir: test => /:i \.[jpe?g|png]$/;
for @files { die "$_ is not a regular file" unless .f; }
@ -45,20 +48,23 @@ for @files { die "$_ is not a regular file" unless .f; }
# running imagemagick (and oxipng sometimes) 🪄
sub convert($in, $site, $format, *@flags) {
my $out = $outdir.child($in.basename).extension("$site.$format");
cmd <convert>, $in, @flags, $out;
sub convert($in, $name, $size, $format) {
my $out = $outdir.child($in.basename).extension("$name.$format");
cmd <convert>, $in, '-resize', $size, '-quality', $quality, $out;
cmd <oxipng -q>, $out if $format == png;
}
constant $SIZE = 2800;
constant $SQUARE = "{$SIZE}x{$SIZE}";
constant $MASTO-SIZE = "{1280**2}@";
constant $SIZE = 2800;
constant $SQUARE = "{$SIZE}x{$SIZE}>";
constant $MASTO-SIZE = "{1280**2}@";
constant $GALLERY-SIZE = 3000;
constant $GALLERY-SQUARE = "{$GALLERY-SIZE}x{$GALLERY-SIZE}>";
my @sites = [
{:name<mastodon>, :format($mastodon), :size($MASTO-SIZE)},
{:name<itaku>, :format($itaku), :size($SQUARE)},
{:name<furaffinity>, :format($furaffinity), :size($SQUARE)},
{:name<gallery>, :format($gallery), :size($GALLERY-SQUARE)},
].grep: *<format> != skip;
@ -76,5 +82,5 @@ my @todo = @files X @sites;
parallel @todo, -> ($file, % (:$name, :$format, :$size)) {
state $i++;
say "[$i/@todo.elems()] $name $file.basename()";
convert $file, $name, $format, '-resize', $size, '-quality', $quality;
convert $file, $name, $size, $format;
};