rename image resize function
[phpfspot.git] / phpfspot.class.php
index d62be697f2c0677878dff847f7e72edb255d846c..948a87e56fb3cd9463e5bab647e3093fcfcb027e 100644 (file)
@@ -287,7 +287,7 @@ class PHPFSPOT {
 
    } // showCredits()
 
-   public function resize_image($image, $width)
+   public function create_thumbnail($image, $width)
    {  
       // if thumbnail already exists, don't recreate it
       if(file_exists(dirname($image) ."/thumbs/". $width ."_". basename($image)))
@@ -337,7 +337,7 @@ class PHPFSPOT {
          imagedestroy($src_img);
       }
 
-   } // resize_image()
+   } // create_thumbnail()
 
    public function get_meta_informations($file)
    {
@@ -360,6 +360,64 @@ class PHPFSPOT {
 
    } // 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->create_thumbnail($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()
+
 }
 
 ?>