issue10, fixed on-demand thumbnail generation
authorAndreas Unterkircher <unki@netshadow.at>
Mon, 18 Jun 2007 19:36:37 +0000 (19:36 +0000)
committerAndreas Unterkircher <unki@netshadow.at>
Mon, 18 Jun 2007 19:36:37 +0000 (19:36 +0000)
git-svn-id: file:///var/lib/svn/phpfspot/trunk@108 fa6a889d-dae6-447d-9e79-4ba9a3039384

gen_thumbs.php
phpfspot.class.php
phpfspot_img.php

index 46c10d7f4642989c5a13f586c9d4d8565e4d82b3..d8e384a8de51f0125d88a324ecb5e2c0e131a985 100755 (executable)
@@ -4,6 +4,11 @@
 require_once "phpfspot.class.php";
 
 $fspot = new PHPFSPOT;
-$fspot->gen_thumbs(0, 'fromcmd');
+
+$all = $fspot->getPhotoSelection();
+
+foreach($all as $photo) {
+   $fspot->gen_thumb($photo, 'fromcmd');
+}
 
 ?>
index cf0fa25686073478295144508e1b2e9eb5ac2718..2ffec5fa82b5c7f24ddd90c2483981884d5624db 100644 (file)
@@ -536,50 +536,39 @@ class PHPFSPOT {
 
    } // check_config_table
 
-   public function gen_thumbs($idx = 0, $fromcmd = 0)
+   public function gen_thumb($idx = 0, $fromcmd = 0)
    {
-      if(!$idx) {
-         /* get all available photos */
-         $all = $this->getPhotoSelection();
-      }
-      else
-         $all = Array($idx);
-      
-      foreach($all as $photo) {
+      $details = $this->get_photo_details($idx);
 
-         $details = $this->get_photo_details($photo);
+      $full_path = $this->translate_path($details['directory_path'])  ."/". $details['name'];
+      $file_md5 = md5_file($full_path);
 
-         $full_path = $this->translate_path($details['directory_path'])  ."/". $details['name'];
-         $file_md5 = md5_file($full_path);
+      if($fromcmd) print "Image [". $idx ."] ". $details['name'] ." Thumbnails:";
 
-         if($fromcmd) print "Image [". $photo ."] ". $details['name'] ." Thumbnails:";
-
-         /* if the file hasn't changed there is no need to regen the thumb */
-         if($file_md5 == $this->getMD5($photo)) {
-            if($fromcmd) print " file has not changed - skipping\n";
-            continue;
-         }
-
-         /* set the new/changed MD5 sum for the current photo */
-         $this->setMD5($photo, $file_md5);
+      /* if the file hasn't changed there is no need to regen the thumb */
+      if($file_md5 == $this->getMD5($idx)) {
+         if($fromcmd) print " file has not changed - skipping\n";
+         return;
+      }
 
-         $resolutions = Array(
-                           $this->cfg->thumb_width,
-                           $this->cfg->bubble_width,
-                           $this->cfg->photo_width
-                        );
+      /* set the new/changed MD5 sum for the current photo */
+      $this->setMD5($idx, $file_md5);
 
-         /* create thumbnails for the requested resolutions */
-         foreach($resolutions as $resolution) {
-            if($fromcmd) print " ". $resolution ."px";
-            $this->create_thumbnail($full_path, $resolution);
-         }
-
-         if($fromcmd) print "\n";
+      $resolutions = Array(
+         $this->cfg->thumb_width,
+         $this->cfg->bubble_width,
+         $this->cfg->photo_width
+      );
 
+      /* create thumbnails for the requested resolutions */
+      foreach($resolutions as $resolution) {
+         if($fromcmd) print " ". $resolution ."px";
+         $this->create_thumbnail($full_path, $resolution);
       }
 
-   } // gen_thumbs()
+      if($fromcmd) print "\n";
+
+   } // gen_thumb()
 
    private function getMD5($idx)
    {
index 0afdd7b2d8dc5f728492d0dffd32b8ff405bd143..60c06b00d47a2be5565c300332e44bca353e14ef 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 
-require_once "phpfspot_db.php";
 require_once "phpfspot.class.php";
 
 class PHPFSPOT_IMG {
@@ -20,17 +19,18 @@ class PHPFSPOT_IMG {
 
    } // __desctruct()
 
-   public function show($idx, $width = "")
+   public function show($idx, $width = 0)
    {
-      $this->parent->gen_thumbs($idx);
+      $this->parent->gen_thumb($idx);
 
       $details = $this->parent->get_photo_details($idx);
 
-      if($width == "")
+      if($width == 0) {
          $fullpath = $this->parent->translate_path($details['directory_path'])  ."/". $details['name'];
-      else
+      }
+      else {
          $fullpath = $this->parent->translate_path($details['directory_path'])  ."/thumbs/". $width ."_". $details['name'];
-
+      }
 
       $tmp = getimagesize($fullpath);
       $mime = $tmp['mime'];
@@ -38,7 +38,6 @@ class PHPFSPOT_IMG {
       Header("Content-Type: ". $mime);
       Header("Content-Length: ". filesize($fullpath));
       Header("Content-Transfer-Encoding: binary\n");              
-      $user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);     
       Header("Content-Disposition: inline; filename=\"". $details['name'] ."\"");
       Header("Accept-Ranges: bytes");                             
       Header("Connection: close");