From 6db907e90cee931c98be2684ba5deed698b1ebb6 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 3 Jan 2024 22:32:00 +0100 Subject: [PATCH] dieren: mkimgthumb script options to override export formats Support exceptional quality and resolution for custom results. Fall back to unaltered jpg/webp preset for existing optionless requests. --- tools/mkimgthumb | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/tools/mkimgthumb b/tools/mkimgthumb index 8f0097a..32ae1a3 100755 --- a/tools/mkimgthumb +++ b/tools/mkimgthumb @@ -4,6 +4,32 @@ use warnings; use lib $0 =~ s{[^/]+$}{..}r; # project root use Shiar_Sheet::ImagePrep '1.03'; +our $VERSION = '1.00'; + +my %opt; + +if (@ARGV and $ARGV[0] =~ /^-/) { + require Getopt::Long; + Getopt::Long->import(qw( 2.33 :config gnu_getopt )); + GetOptions(\%opt, + 'jpg=s', + 'webp=s', + ) or exit 64; +} + +%opt or %opt = ( + jpg => '300x200', + webp => '630x420@30', +); + +my @ffs; +for (keys %opt) { + push @ffs, my $ff = [$_]; + my $r = $opt{$_}; + push @{$ff}, -quality => $1 if $r =~ s/@(\d+)//; + push @{$ff}, -resize => "$r^", -extent => $r; +} + my $failcount = 0; for my $src (@ARGV) { @@ -24,12 +50,13 @@ for my $src (@ARGV) { unshift @cmds, -chop => "$crop[0]%x$crop[1]%"; } push @cmds, -gravity => 'north'; - my @cmdwebp = (-resize => '630x420^', -extent => '630x420', -quality => 30); - my @cmdjpeg = (-resize => '300x200^', -extent => '300x200'); eval { my $image = Shiar_Sheet::ImagePrep->new($src); - $image->convert("../$name.jpg", [@cmds, @cmdjpeg]); - $image->convert("../$name.webp", [@cmds, @cmdwebp]); + for (@ffs) { + my ($ff, @ffcmds) = @{$_}; + $image->convert("../$name.$ff", [@cmds, @ffcmds]); + } + 1; } or do { warn "error creating image:\n"; warn ref $@ eq 'ARRAY' ? $@->[1] : $@ if $@; -- 2.30.0