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.
sub new {
my ($class, $target) = @_;
sub new {
my ($class, $target) = @_;
- my ($imgpath, $thumbpath, $cmds) = @_;
+ my ($imgpath, $thumbpath, $cmds, $xyres) = @_;
if (not -e $$imgpath) {
return !-e $thumbpath || unlink $thumbpath;
}
#my ($w, $h) = $imgpath->dimensions;
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) {
my $aspect = 3/2;
my @cmds = @{ $cmds // [] };
if (my ($cmdarg) = grep { $cmds[$_] eq '-area' } 0 .. $#cmds) {
use Shiar_Sheet::DB;
use JSON ();
use Shiar_Sheet::DB;
use JSON ();
my $db = Shiar_Sheet::DB->connect;
my %filter = @ARGV ? (id => shift) : ();
my $db = Shiar_Sheet::DB->connect;
my %filter = @ARGV ? (id => shift) : ();
eval {
my $meta = eval { JSON->new->decode($row->{image} // '{}') }
or die ["Invalid JSON metadata in image column.", $@];
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}: @{$@}";
}
} or warn "$row->{id}: @{$@}";
}