chiark / gitweb /
mason/.perl-lib/TrivGal.pm (%SIZE): Modify and extend the available sizes.
[tgal] / mason / .perl-lib / TrivGal.pm
index 96f66f12ea693318999d190383514682b49a23c7..4e5527bb3c3a30f2721fa9f40d4c5bd68da6bfd8 100644 (file)
@@ -148,10 +148,16 @@ our $SRCURL = "https://git.distorted.org.uk/~mdw/tgal/";
 export qw{%SIZE};
 our %SIZE = (smallthumb => 96,
             medthumb => 144,
-            bigthumb => 228,
+            bigthumb => 216,
+            tiny => 320,
             small => 480,
             embed => 720,
-            view => 1200);
+            medium => 1080,
+            big => 1600,
+            large => 2400,
+            huge => 3600,
+            vast => 5400,
+            immense => 8100);
 
 export qw{init};
 my $initp = 0;
@@ -217,6 +223,8 @@ package TrivGal::Image {
       path => $path, imgpath => $imgpath,
       mtime => $st->mtime,
       img => undef,
+      rot => undef, flip => undef,
+      wd => undef, ht => undef,
       _wd => undef, _ht => undef,
       sz => undef
     }, $cls;
@@ -232,7 +240,24 @@ package TrivGal::Image {
     @$me{"_wd", "_ht", "sz"} = ($wd, $ht, $sz);
   }
 
+  sub _getexif ($) {
+    my ($me) = @_;
+    return if defined $me->{wd};
+
+    $me->_getsz;
+    my $exif = new Image::ExifTool; $exif->ExtractInfo($me->{imgpath});
+    my $orient = $exif->GetValue("Orientation", "ValueConv");
+    my ($wd, $ht) = @$me{"_wd", "_ht"};
+    my ($rot, $flip);
+    if (defined $orient) { ($rot, $flip) = $ORIENT{$orient}->@*; }
+    else { ($rot, $flip) = (0, 0); }
+    if ($rot%2) { ($wd, $ht) = ($ht, $wd); }
+    @$me{"rot", "flip", "wd", "ht"} = ($rot, $flip, $wd, $ht);
+  }
+
   sub sz ($) { my ($me) = @_; $me->_getsz; return $me->{sz}; }
+  sub wd ($) { my ($me) = @_; $me->_getexif; return $me->{wd}; }
+  sub ht ($) { my ($me) = @_; $me->_getexif; return $me->{ht}; }
 
   sub scale ($$;$) {
     my ($me, $scale, $forcep) = @_;
@@ -257,22 +282,16 @@ package TrivGal::Image {
          $m->interp->apply_escapes("$SCRIPTURL/$path", "u") .
          "?scale=$scale";
       } else {
-       my ($dir, undef, $ext) = TrivGal::split_path $thumb;
-       my $ty = $TYPE{lc $ext} or die "unknown type `$ext'";
-
        my $img = $me->{img};
        unless (defined $img) {
-         my $exif = new Image::ExifTool;
-         $exif->ExtractInfo($me->{imgpath});
-         my $orient = $exif->GetValue("Orientation", "ValueConv");
+         $me->_getexif;
          $img = $me->{img} = Image::Imlib2->load($me->{imgpath});
-         if (defined $orient) {
-           my ($rot, $flip) = @{$ORIENT{$orient}};
-           if ($rot) { $img->image_orientate($rot); }
-           if ($flip) { $img->flip_horizontal(); }
-         }
+         if ($me->{rot}) { $img->image_orientate($me->{rot}); }
+         if ($me->{flip}) { $img->flip_horizontal(); }
        }
 
+       my ($dir, undef, $ext) = TrivGal::split_path $thumb;
+       my $ty = $TYPE{lc $ext} or die "unknown type `$ext'";
        my $sc = $sz/$me->sz;
        my $scaled = $img->create_scaled_image($sc*$wd, $sc*$ht);