X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/6eaf259c375a83613907b31437bc4fae005360b4..f88a74c510e90c9c864d37bfaaf23fefa1a0fbdc:/tools/mkimgthumb diff --git a/tools/mkimgthumb b/tools/mkimgthumb index 8875252..217b773 100755 --- a/tools/mkimgthumb +++ b/tools/mkimgthumb @@ -5,17 +5,28 @@ use warnings; my $failcount = 0; for my $src (@ARGV) { - my ($name, @cmds) = split /:/, $src =~ s/\.(\w+)\z//r; + my ($name, @cmds) = split /:(? or next; } + s/\\(.)/$1/g for @cmds; say $name; - unshift @cmds, -gravity => 'northwest'; - push @cmds, -resize => '300x200^', -gravity => 'north', -extent => '300x200'; - push @cmds, '-strip', -quality => '60%'; - system(convert => @cmds, $src => "../$name.jpg") == 0 + + if (@cmds and $cmds[0] =~ /^\d/) { + # crop shorthand from initial dimension argument + my @crop = split /\D/, shift @cmds; + unshift @cmds, -gravity => 'southeast', -chop => "$crop[2]%x$crop[3]%" + if @crop > 2; + unshift @cmds, -chop => "$crop[0]%x$crop[1]%"; + } + unshift @cmds, -gravity => 'northwest' if @cmds; + push @cmds, '-strip', -gravity => 'north', -quality => 60; + my @cmdwebp = (-resize => '630x420^', -extent => '630x420', -quality => 30); + my @cmdjpeg = (-resize => '300x200^', -extent => '300x200'); + system(convert => $src, @cmds, @cmdjpeg, "../$name.jpg" ) == 0 and + system(convert => $src, @cmds, @cmdwebp, "../$name.webp") == 0 or $failcount += warn "error creating $name.jpg from $src\n"; }