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.
my $size = "medthumb";
my %tn;
for my $f (@$ff)
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;
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; }
last DIR;
}
if (!@$ddd) { $tn{$d} = undef; last DIR; }
<div class="gallery <% $size %>">
% for my $d (@$dd) {
<& .thumbnail, target => $d->name, comment => $d->comment,
<div class="gallery <% $size %>">
% for my $d (@$dd) {
<& .thumbnail, target => $d->name, comment => $d->comment,
- img => $tn{$d}, size => $size,
+ tn => $tn{$d}, size => $size,
caption => $m->interp->apply_escapes($d->name, "h") &>\
% }
</div>
caption => $m->interp->apply_escapes($d->name, "h") &>\
% }
</div>
<div class="gallery <% $size %>">
% for my $f (@$ff) {
<& .thumbnail, target => $f->name, comment => $f->comment,
<div class="gallery <% $size %>">
% for my $f (@$ff) {
<& .thumbnail, target => $f->name, comment => $f->comment,
- img => $tn{$f}, size => $size,
+ tn => $tn{$f}, size => $size,
caption => $m->interp->apply_escapes($f->name, "h") &>\
% }
</div>
caption => $m->interp->apply_escapes($f->name, "h") &>\
% }
</div>
% for my $size (qw{smallthumb medthumb bigthumb}) {
<div class="thumbstrip <% $size %>">
% for my $f (@$ff) {
% for my $size (qw{smallthumb medthumb bigthumb}) {
<div class="thumbstrip <% $size %>">
% 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 &>\
% }
caption => $m->interp->apply_escapes($f->name, "h"),
focus => $f eq $this &>\
% }
%
%###-------------------------------------------------------------------------
<%def .thumbnail>\
%
%###-------------------------------------------------------------------------
<%def .thumbnail>\
-% my $tn;
-% if (defined $img) { $tn = $img->scale($size); }
-% else { $tn = "$STATICURL/folder.svg"; }
+% $tn //= "$STATICURL/folder.svg";
% if ($focus) {
<figure class="thumb focusthumb <% $size %>">
<img class="thumb <% $size %>" load=lazy src="<% $tn |h %>">
% if ($focus) {
<figure class="thumb focusthumb <% $size %>">
<img class="thumb <% $size %>" load=lazy src="<% $tn |h %>">
$size
$caption
$comment => undef
$size
$caption
$comment => undef