mason/.perl-lib/TrivGal.pm: Remove spurious `$e'.
[tgal] / mason / .perl-lib / TrivGal.pm
index 5b5cbfa..8673b75 100644 (file)
@@ -30,6 +30,7 @@ use autodie qw{:all};
 use Errno;
 use Exporter qw{import};
 use File::stat;
+use Image::ExifTool qw{};
 use Image::Imlib2;
 use User::pwent;
 use POSIX;
@@ -137,6 +138,9 @@ our $CACHEURL //= "$ROOTURL/tgal-cache";
 our $STATICURL //= "$ROOTURL/tgal-static";
 our $SCRIPTURL;
 
+export qw{$SRCURL};
+our $SRCURL = "https://git.distorted.org.uk/~mdw/tgal/";
+
 export qw{%SIZE};
 our %SIZE = (smallthumb => 96,
             medthumb => 144,
@@ -185,6 +189,16 @@ sub clean_temp_files () {
 ###--------------------------------------------------------------------------
 ### Scaled images.
 
+my %ORIENT =
+  (1 => [0, 0],
+   2 => [0, 1],
+   3 => [2, 0],
+   4 => [2, 1],
+   5 => [3, 1],
+   6 => [1, 0],
+   7 => [1, 1],
+   8 => [3, 0]);
+
 package TrivGal::Image {
   use File::Path qw{make_path};
   use File::stat;
@@ -216,7 +230,15 @@ package TrivGal::Image {
     my $img = $me->{img};
     unless (defined $img) {
       my $imgpath = "$IMGROOT/$path";
+      my $exif = new Image::ExifTool;
+      $exif->ExtractInfo($imgpath);
+      my $orient = $exif->GetValue("Orientation", "ValueConv");
       $img = $me->{img} = Image::Imlib2->load($imgpath);
+      if (defined $orient) {
+       my ($rot, $flip) = @{$ORIENT{$orient}};
+       if ($rot) { $img->image_orientate($rot); }
+       if ($flip) { $img->flip_horizontal(); }
+      }
     }
 
     my ($wd, $ht) = ($img->width, $img->height);
@@ -295,6 +317,9 @@ sub listdir ($) {
     if ($item && $comment) { $item->comment($comment); }
     close $f;
   } else {
+    my $st = stat $path;
+    unless ($st->mode&0004) { return ([], [], undef); }
+
     opendir $d, $path;
     my @e = readdir $d;
     closedir $d;
@@ -304,7 +329,7 @@ sub listdir ($) {
       my $dotp = $e =~ /^\./;
       my $st = stat "$path/$e";
       my $list = undef;
-      if ($dotp || !($st->mode&0004)) { }
+      if ($dotp) { }
       elsif (-d $st) { $list = \@d; }
       elsif ($TYPE{lc $ext} && -f $st) { $list = \@f; }
       $list and push @$list, TrivGal::Item->new($e);