diff options
-rw-r--r-- | phpfspot.class.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/phpfspot.class.php b/phpfspot.class.php index d62be69..a936eec 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -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->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() + } ?> |