From e1117268a48440364cc10191a40eee45b8f514bd Mon Sep 17 00:00:00 2001 From: Andreas Unterkircher Date: Sat, 9 Jun 2007 06:55:53 +0000 Subject: [PATCH] md5 checksum handling with extra sqlite database git-svn-id: file:///var/lib/svn/phpfspot/trunk@66 fa6a889d-dae6-447d-9e79-4ba9a3039384 --- phpfspot.class.php | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) 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() + } ?> -- 2.25.1