mason/{.perl-lib/TrivGal,dhandler}: Make an image object.
[tgal] / mason / dhandler
index 13731e1..7d76fdf 100755 (executable)
@@ -100,12 +100,12 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 <div class=gallery>
 %   for my $d (@$dd) {
 %     my ($ddd, $fff, $iii) = listdir $real . "/" . $d->name;
-%     my $tn;
-%     if ($iii) { $tn = join_paths $path, $d->name . "/" . $iii->name; }
-%     else { $tn = undef; }
-  <& .thumbnail, target => $d->name . "/", img => $tn,
-                caption => $m->interp->apply_escapes($d->name, "h"),
-                comment => $d->comment &>\
+%     my $tn = $iii ?
+%      TrivGal::Image->new(join_paths $path, $d->name, $iii->name) :
+%       undef;
+  <& .thumbnail, target => $d->name . "/", comment => $d->comment,
+                img => $tn, size => "bigthumb",
+                caption => $m->interp->apply_escapes($d->name, "h") &>\
 %   }
 </div>
 % }
@@ -114,9 +114,10 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 <h2>Images</h2>
 <div class=gallery>
 %   for my $f (@$ff) {
-  <& .thumbnail, target => $f->name, img => $path . $f->name,
-                caption => $m->interp->apply_escapes($f->name, "h"),
-                comment => $f->comment &>\
+  <& .thumbnail, target => $f->name, comment => $f->comment,
+                img => TrivGal::Image->new($path . $f->name),
+                size => "bigthumb",
+                caption => $m->interp->apply_escapes($f->name, "h") &>\
 %   }
 </div>
 % }
@@ -139,7 +140,7 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
        my $realdir = join_paths $IMGROOT, $dir;
        my $urldir = join_paths $SCRIPTURL, $dir;
        my ($dd, $ff, $ii) = listdir $realdir;
-       my $vw = scaled "view", $path;
+       my $vw = TrivGal::Image->new($path)->scale("view");
 
        my $fi = undef;
        FILE: for (my $i = 0; $i < @$ff; $i++)
@@ -191,7 +192,8 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 %
 <div class=thumbstrip>
 % for my $f (@$ff) {
-  <& .thumbnail, target => $f->name, img => $dir . "/" . $f->name,
+%   my $img = TrivGal::Image->new($dir . "/" . $f->name);
+  <& .thumbnail, target => $f->name, img => $img, size => "bigthumb",
                 caption => $m->interp->apply_escapes($f->name, "h"),
                 focus => $f->name eq "$base$ext" &>\
 % }
@@ -235,16 +237,16 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 %###-------------------------------------------------------------------------
 <%def .thumbnail>\
 % my $tn;
-% if (defined $img) { $tn = scaled "thumb", $img; }
+% if (defined $img) { $tn = $img->scale($size); }
 % else { $tn = "$STATICURL/folder.svg"; }
 % if ($focus) {
-  <figure class=thumb id=focusthumb>
-    <img class=thumb src="<% $tn |u %>">
+  <figure class="thumb <% $size %>" id=focusthumb>
+    <img class="thumb <% $size %>" load=lazy src="<% $tn |u %>">
     <figcaption><span class=name><% $caption %></span></figcaption>
 % } else {
-  <figure class=thumb>
+  <figure class="thumb <% $size %>">
     <a class=thumb href="<% $target |u %>">
-      <img class=thumb src="<% $tn |u %>">
+      <img class="thumb <% $size %>" load=lazy src="<% $tn |u %>">
       <figcaption>
        <span class=name><% $caption %></span>
 % if (defined $comment) {
@@ -258,6 +260,7 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 <%args>
        $target
        $img
+       $size
        $caption
        $comment => undef
        $focus => 0