mason/.perl-lib/TrivGal.pm (Image): Stash `imgpath' in an object slot.
[tgal] / mason / .perl-lib / TrivGal.pm
index 80cce08..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,7 +213,7 @@ 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;
@@ -237,11 +239,10 @@ package TrivGal::Image {
 
     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); }
@@ -251,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;
   }