From ccaab4e8a37a81ce43437a3ed7fbc0fd0cae7e1f Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 12 Jun 2023 11:33:57 +0100 Subject: [PATCH] mason/dhandler (.thumbnail + callers): Pass in pre-scaled thumbnail. The objective here is to give the caller control over the order in which image scaling occurs. In particular, by loading an image once and generating the required scaled versions, we can potentially save a lot of memory, which is a significant factor when dealing with full-size DSLR images. --- mason/dhandler | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/mason/dhandler b/mason/dhandler index 42b324c..a48610c 100755 --- a/mason/dhandler +++ b/mason/dhandler @@ -86,14 +86,14 @@ Failed to find ‘<% $path |h %>’. my $size = "medthumb"; my %tn; for my $f (@$ff) - { $tn{$f} = TrivGal::Image->new($path . $f->name); } + { $tn{$f} = TrivGal::Image->new($path . $f->name)->scale($size); } for my $d (@$dd) { my $p = join_paths $path, $d->name; DIR: for (;;) { my ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p; if (defined $iii) { my $index = join_paths $p, $iii->name; - $tn{$d} = TrivGal::Image->new($index); + $tn{$d} = TrivGal::Image->new($index)->scale($size); last DIR; } if (!@$ddd) { $tn{$d} = undef; last DIR; } @@ -119,7 +119,7 @@ Failed to find ‘<% $path |h %>’. @@ -130,7 +130,7 @@ Failed to find ‘<% $path |h %>’. @@ -212,7 +212,8 @@ Failed to find ‘<% $path |h %>’. % for my $size (qw{smallthumb medthumb bigthumb}) {
% for my $f (@$ff) { - <& .thumbnail, target => $f->name, img => $img{$f}, size => $size, + <& .thumbnail, target => $f->name, + img => $img{$f}->scale($size), size => $size, caption => $m->interp->apply_escapes($f->name, "h"), focus => $f eq $this &>\ % } @@ -257,9 +258,7 @@ Failed to find ‘<% $path |h %>’. % %###------------------------------------------------------------------------- <%def .thumbnail>\ -% my $tn; -% if (defined $img) { $tn = $img->scale($size); } -% else { $tn = "$STATICURL/folder.svg"; } +% $tn //= "$STATICURL/folder.svg"; % if ($focus) {
@@ -280,7 +279,7 @@ Failed to find ‘<% $path |h %>’. % <%args> $target - $img + $tn $size $caption $comment => undef -- 2.11.0