[Bast-commits] r5421 - trunk/PhotoOp/lib/PhotoOp/Controller

castaway at dev.catalyst.perl.org castaway at dev.catalyst.perl.org
Sat Feb 7 15:00:05 GMT 2009


Author: castaway
Date: 2009-02-07 15:00:05 +0000 (Sat, 07 Feb 2009)
New Revision: 5421

Modified:
   trunk/PhotoOp/lib/PhotoOp/Controller/Root.pm
Log:
Add thumbnail file creation, use file if newer than image its a thumbnail of


Modified: trunk/PhotoOp/lib/PhotoOp/Controller/Root.pm
===================================================================
--- trunk/PhotoOp/lib/PhotoOp/Controller/Root.pm	2009-02-07 13:43:35 UTC (rev 5420)
+++ trunk/PhotoOp/lib/PhotoOp/Controller/Root.pm	2009-02-07 15:00:05 UTC (rev 5421)
@@ -358,12 +358,41 @@
     return if(!-f "$file");
     
     return if $self->is_private($c, $file);
+
+    ## Try and fetch thumbnail from ".thumbnails" dir first
+    ## Check mtimes to make sure it is newer than the actual file!
+
+    my $thumbnailpath = $file->dir->subdir('.thumbnails');
+    $thumbnailpath->mkpath();
+    my $thumbnailfile = $thumbnailpath->file($file->basename);
+    my $thumbfh;
+    if(-f "$thumbnailfile") 
+    {
+        $c->log->debug("Thumbnail for $file exists\n");
+        my $t_mt = $thumbnailfile->stat->mtime;
+        my $f_mt = $file->stat->mtime;
+        if($t_mt > $f_mt) 
+        {
+            $c->log->debug("Thumbnail for $file is newer\n");
+            $thumbfh = $thumbnailfile->openr();
+        }
+    }
+    if(!$thumbfh)
+    {
+        $c->log->debug("Thumbnail for $file is missing\n");
+        my $tool = Image::ExifTool->new();
+        my $thumbnail = $tool->ImageInfo($file->stringify, 'ThumbnailImage');
+        my $thumbwrite = $thumbnailfile->openw();
+        $thumbwrite->binmode();
+        print $thumbwrite ${ $thumbnail->{ThumbnailImage} };
+        $thumbwrite->close();
+        $thumbfh = $thumbnailfile->openr();
+    }
     
-    my $tool = Image::ExifTool->new();
-    my $thumbnail = $tool->ImageInfo($file->stringify, 'ThumbnailImage');
     $c->res->content_type('image/jpeg');
 #    $c->log->info("Thumbnail body ref: ", ref(${$thumbnail->{ThumbnailImage}}));
-    $c->res->body(${$thumbnail->{ThumbnailImage}});
+#    $c->res->body(${$thumbnail->{ThumbnailImage}});
+    $c->res->body($thumbfh);
 }
 
 sub is_private




More information about the Bast-commits mailing list