From 256f6aee2a09d51c0350a5c3ed60ba354b115abc Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 29 Dec 2021 05:23:31 +0100 Subject: [PATCH] word: webp images at double resolution 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 | 6 +++--- tools/mkwordthumb | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Shiar_Sheet/ImagePrep.pm b/Shiar_Sheet/ImagePrep.pm index 6457a83..f76cb31 100644 --- a/Shiar_Sheet/ImagePrep.pm +++ b/Shiar_Sheet/ImagePrep.pm @@ -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) { diff --git a/tools/mkwordthumb b/tools/mkwordthumb index 2404324..8e7909f 100755 --- a/tools/mkwordthumb +++ b/tools/mkwordthumb @@ -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}: @{$@}"; } -- 2.30.0