word: webp images at double resolution
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 29 Dec 2021 04:23:31 +0000 (05:23 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 31 Dec 2021 04:29:05 +0000 (05:29 +0100)
Modern compression format supported by modern Imagemagick and browsers,
efficient enough to allow 600x400 quality (better detail @2x pixel density
or as workaround for upscaled covers and in quizzes, until dedicated
alternatives) at acceptable file sizes ~25kB.

Shiar_Sheet/ImagePrep.pm
tools/mkwordthumb

index 6457a83a0c08071fbbf7daa185db8403ee600f57..f76cb31d7f4f3a448d91c6799c9fc8277a18a19a 100644 (file)
@@ -3,7 +3,7 @@ package Shiar_Sheet::ImagePrep;
 use 5.014;
 use warnings;
 
-our $VERSION = '1.00';
+our $VERSION = '1.01';
 
 sub new {
        my ($class, $target) = @_;
@@ -34,13 +34,13 @@ sub dimensions {
 }
 
 sub convert {
-       my ($imgpath, $thumbpath, $cmds) = @_;
+       my ($imgpath, $thumbpath, $cmds, $xyres) = @_;
        if (not -e $$imgpath) {
                return !-e $thumbpath || unlink $thumbpath;
        }
 
        #my ($w, $h) = $imgpath->dimensions;
-       my $xyres = 0 ? '600x400' : '300x200'; # cover
+       $xyres //= '300x200'; # cover
        my $aspect = 3/2;
        my @cmds = @{ $cmds // [] };
        if (my ($cmdarg) = grep { $cmds[$_] eq '-area' } 0 .. $#cmds) {
index 2404324d415815fffdb0e570f5fcf511d05ee3ab..8e7909f5daf0fe2be762cd82c7143603ebf3cedf 100755 (executable)
@@ -6,7 +6,7 @@ use Shiar_Sheet::ImagePrep;
 use Shiar_Sheet::DB;
 use JSON ();
 
-our $VERSION = '1.00';
+our $VERSION = '1.01';
 
 my $db = Shiar_Sheet::DB->connect;
 my %filter = @ARGV ? (id => shift) : ();
@@ -17,6 +17,8 @@ while (my $row = $query->hash) {
        eval {
                my $meta = eval { JSON->new->decode($row->{image} // '{}') }
                        or die ["Invalid JSON metadata in image column.", $@];
-               $image->convert("data/word/en/$row->{id}.jpg", $meta->{convert});
+               my $basename = "data/word/en/$row->{id}";
+               $image->convert("$basename.jpg",  $meta->{convert});
+               $image->convert("$basename.webp", $meta->{convert}, '600x400');
        } or warn "$row->{id}: @{$@}";
 }