md5 checksum handling with extra sqlite database
authorAndreas Unterkircher <unki@netshadow.at>
Sat, 9 Jun 2007 06:55:53 +0000 (06:55 +0000)
committerAndreas Unterkircher <unki@netshadow.at>
Sat, 9 Jun 2007 06:55:53 +0000 (06:55 +0000)
git-svn-id: file:///var/lib/svn/phpfspot/trunk@66 fa6a889d-dae6-447d-9e79-4ba9a3039384

phpfspot.class.php

index d62be697f2c0677878dff847f7e72edb255d846c..a936eecba35b32eaa7c1822707f2e73f2cd60ebd 100644 (file)
@@ -360,6 +360,64 @@ class PHPFSPOT {
 
    } // check_config_table
 
 
    } // check_config_table
 
+   public function gen_thumbs($fromcmd = 0)
+   {
+      /* get all available photos */
+      $all = $this->getAllTagPhotos();                                                                                                                                                                    
+      foreach($all as $photo) {
+
+         $full_path = $this->translate_path($details['directory_path'])  ."/". $details['name'];
+         $file_md5 = md5_file($full_path);
+
+         $details = $this->get_photo_details($photo);
+         if($fromcmd) print "Image ". $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);
+
+         /* create thumbnails for the requested resolutions */
+         foreach(Array($this->cfg->thumb_width, $this->cfg->photo_width) as $resolution) {
+            if($fromcmd) print " ". $resolution ."px";
+            $this->resize_image($full_path, $resolution);
+         }
+
+         if($fromcmd) print "\n";
+
+      }
+
+   } // gen_thumbs()
+
+   private function getMD5($idx)
+   {
+      $result = $this->cfg_db->db_query("
+         SELECT img_md5 
+         FROM images
+         WHERE img_idx='". $idx ."'
+      ");
+
+      if(!$result)
+         return 0;
+
+      $img = $this->cfg_db->db_fetch_object($result);
+      return $img['img_md5'];
+      
+   } // getMD5()
+
+   private function setMD5($idx, $md5)
+   {
+      $result = $this->cfg_db->db_exec("
+         REPLACE INTO images (img_idx, img_md5)
+         VALUES ('". $idx ."', '". $md5 ."')
+      ");
+
+   } // setMD5()
+
 }
 
 ?>
 }
 
 ?>