From 39da13d7b9031b578228f21c13b4fa1e3f9c8ef9 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sun, 3 May 2020 00:22:01 +0200 Subject: [PATCH] dieren: mkimgthumb number suffix as crop shorthand Simplifies vleerhond:-crop:70%x0:-chop:20%x30% to vleerhond:12x30x30x0 and many more. --- tools/mkimgthumb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/mkimgthumb b/tools/mkimgthumb index 8875252..3c38e7c 100755 --- a/tools/mkimgthumb +++ b/tools/mkimgthumb @@ -12,7 +12,15 @@ for my $src (@ARGV) { ($src) = grep {-e} glob qq<"$name"{,:*}.$ext> or next; } say $name; - unshift @cmds, -gravity => 'northwest'; + + 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, -resize => '300x200^', -gravity => 'north', -extent => '300x200'; push @cmds, '-strip', -quality => '60%'; system(convert => @cmds, $src => "../$name.jpg") == 0 -- 2.30.0