mason/.perl-lib/TrivGal.pm (Image): Stash `imgpath' in an object slot.
[tgal] / mason / .perl-lib / TrivGal.pm
index ec011f3..fc93772 100644 (file)
@@ -148,6 +148,8 @@ export qw{%SIZE};
 our %SIZE = (smallthumb => 96,
             medthumb => 144,
             bigthumb => 228,
+            small => 480,
+            embed => 720,
             view => 1200);
 
 export qw{init};
@@ -211,14 +213,14 @@ package TrivGal::Image {
     my $imgpath = "$IMGROOT/$path";
     my $st = stat $imgpath or die "no image `$path'";
     return bless {
-      path => $path,
+      path => $path, imgpath => $imgpath,
       mtime => $st->mtime,
       img => undef
     }, $cls;
   }
 
-  sub scale ($$) {
-    my ($me, $scale) = @_;
+  sub scale ($$;$) {
+    my ($me, $scale, $forcep) = @_;
     my $m = HTML::Mason::Request->instance;
 
     my $path = $me->{path};
@@ -228,17 +230,19 @@ package TrivGal::Image {
       $m->interp->apply_escapes("$CACHEURL/scale.$sz/$path", "u");
     my $st = stat $thumb;
     if (defined $st && $st->mtime > $me->{mtime}) { return $thumburl; }
+    return
+      $m->interp->apply_escapes("$SCRIPTURL/$path", "u") . "?scale=$scale"
+      unless $forcep;
 
     my ($dir, $base, $ext) = TrivGal::split_path $thumb;
     my $ty = $TYPE{lc $ext} or die "unknown type `$ext'";
 
     my $img = $me->{img};
     unless (defined $img) {
-      my $imgpath = "$IMGROOT/$path";
       my $exif = new Image::ExifTool;
-      $exif->ExtractInfo($imgpath);
+      $exif->ExtractInfo($me->{imgpath});
       my $orient = $exif->GetValue("Orientation", "ValueConv");
-      $img = $me->{img} = Image::Imlib2->load($imgpath);
+      $img = $me->{img} = Image::Imlib2->load($me->{imgpath});
       if (defined $orient) {
        my ($rot, $flip) = @{$ORIENT{$orient}};
        if ($rot) { $img->image_orientate($rot); }
@@ -248,16 +252,17 @@ package TrivGal::Image {
 
     my ($wd, $ht) = ($img->width, $img->height);
     my $max = $wd > $ht ? $wd : $ht;
-    if ($max <= $sz) { return "$IMGURL/$path"; }
+    if ($max <= $sz)
+      { return $m->interp->apply_escapes("$IMGURL/$path", "u"); }
     my $sc = $sz/$max;
     my $scaled = $img->create_scaled_image($sc*$wd, $sc*$ht);
 
     $scaled->image_set_format($ty->imlibfmt);
     $scaled->set_quality(90);
     my $new = "$TMP/t$$-$ext";
-    make_path $TMP;
+    make_path $TMP, { mode => 0771 };
     $scaled->save($new);
-    make_path $dir;
+    make_path $dir, { mode => 0771 };
     rename $new, $thumb;
     return $thumburl;
   }
@@ -300,12 +305,14 @@ sub listdir ($) {
        $comment = defined $comment ? $comment . "\n" . $_ : $_;
       } else {
        if ($item && $comment) { $item->comment($comment); }
-       my ($indexp, $name, $c) =
-         /^ (! \s+)?                   # index flag
+       my ($flags, $name, $c) =
+         /^ (?: ([-!]+) \s+)?          # flags
             (\S+) \s*                  # filename
             (\S | \S.*\S )?            # start of the comment
             \s*
             $/x;
+       my $indexp = $flags =~ /!/;
+       my $hidep = $flags =~ /-/;
        $name = urldecode $name;
        my $list;
        $item = TrivGal::Item->new($name);
@@ -322,7 +329,7 @@ sub listdir ($) {
          }
        }
        $comment = $c;
-       push @$list, $item;
+       push @$list, $item unless $hidep;
       }
     }
     if ($item && $comment) { $item->comment($comment); }