make-sizes updates

This commit is contained in:
rhiannon morris 2024-01-11 20:33:35 +01:00
parent dc0081be69
commit 38efa0ef7f
1 changed files with 15 additions and 16 deletions

View File

@ -20,8 +20,9 @@ unit sub MAIN(
Bool :v(:$verbose) = False,
#| out dir, default ./out
IO(Str) :o(:$outdir) = 'out'.IO,
#| use a subdirectory for each site
Bool :d(:$subdirs) = False,
#| output as e.g. thing.mastodon.webp instead of mastodon/thing.webp
Bool :F(:$flat) = False,
Str :B(:$background) = 'white',
#| defaults to all *.png & *.jpg files in the current dir
*@files,
);
@ -44,13 +45,14 @@ sub to-formats($_, *@default) {
.lc.split(',').map: { Format::{$_} // die qq/unrecognised format "$_"/ }
}
die "furaffinity/weasyl don't know what webp are" if $furaffinity ~~ /:i webp/;
my @mastodon = to-formats $mastodon, webp;
my @itaku = to-formats $itaku, webp;
my @furaffinity = to-formats $furaffinity, png, jpg;
my @gallery = to-formats $gallery, webp;
die "furaffinity/weasyl don't know what webp are" if @furaffinity.any == webp;
unless @files.=map(*.IO) {
@files = $*CWD.dir: test => /:i \.[jpe?g|png]$/ && *.IO.f;
}
@ -60,26 +62,23 @@ for @files { die "$_ is not a regular file" unless .f; }
# running imagemagick (and oxipng sometimes) 🪄
sub convert($in, $name, $size, $format) {
my $out = $subdirs
?? $outdir.child($name).child($in.basename).extension("$format")
!! $outdir.child($in.basename).extension("$name.$format");
my $out = $flat
?? $outdir.child($in.basename).extension("$name.$format")
!! $outdir.child($name).child($in.basename).extension("$format");
my @bg-flags = «-background $background -alpha remove» if $format == jpg;
cmd <mkdir -p>, $out.dirname;
cmd <convert>, $in, '-resize', $size, '-quality', $quality, $out;
cmd <convert>, $in, '-resize', $size, '-quality', $quality, @bg-flags, $out;
cmd <oxipng -q>, $out if $format == png;
$out
}
constant $SIZE = 2800;
constant $SQUARE = "{$SIZE}x{$SIZE}>";
constant $MASTO-SIZE = "{1280²}@";
constant $GALLERY-SIZE = 3000;
constant $GALLERY-SQUARE = "{$GALLERY-SIZE}x{$GALLERY-SIZE}>";
sub square($s) { "{$s}x{$s}>" }
my @sites = [
{:name<mastodon>, :formats(@mastodon), :size($MASTO-SIZE)},
{:name<itaku>, :formats(@itaku), :size($SQUARE)},
{:name<furaffinity>, :formats(@furaffinity), :size($SQUARE)},
{:name<gallery>, :formats(@gallery), :size($GALLERY-SQUARE)},
{:name<mastodon>, :formats(@mastodon), :size("{1280²}@")},
{:name<itaku>, :formats(@itaku), :size(square 2800)},
{:name<furaffinity>, :formats(@furaffinity), :size(square 1500)},
{:name<gallery>, :formats(@gallery), :size(square 3000)},
];