diff --git a/bin/make-sizes b/bin/make-sizes index 0ed4e62..fcbecad 100755 --- a/bin/make-sizes +++ b/bin/make-sizes @@ -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 , $out.dirname; - cmd , $in, '-resize', $size, '-quality', $quality, $out; + cmd , $in, '-resize', $size, '-quality', $quality, @bg-flags, $out; cmd , $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, :formats(@mastodon), :size($MASTO-SIZE)}, - {:name, :formats(@itaku), :size($SQUARE)}, - {:name, :formats(@furaffinity), :size($SQUARE)}, - {:name, :formats(@gallery), :size($GALLERY-SQUARE)}, + {:name, :formats(@mastodon), :size("{1280²}@")}, + {:name, :formats(@itaku), :size(square 2800)}, + {:name, :formats(@furaffinity), :size(square 1500)}, + {:name, :formats(@gallery), :size(square 3000)}, ];