dieren: mkimgthumb number suffix as crop shorthand
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 2 May 2020 22:22:01 +0000 (00:22 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 6 May 2020 01:18:07 +0000 (03:18 +0200)
Simplifies vleerhond:-crop:70%x0:-chop:20%x30% to vleerhond:12x30x30x0
and many more.

tools/mkimgthumb

index 8875252c214193e7328a5db50f0a7915eaefe152..3c38e7cf2ce419d8033738c6acd5d14db1e4141e 100755 (executable)
@@ -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