diff options
author | Andreas Unterkircher <unki@netshadow.at> | 2007-06-20 20:02:26 +0000 |
---|---|---|
committer | Andreas Unterkircher <unki@netshadow.at> | 2007-06-20 20:02:26 +0000 |
commit | 322fc50246f37ef26090dd954aa78b2649218c38 (patch) | |
tree | 594a78527e67dc287cdb46ddb27e63beed621f99 /phpfspot.class.php | |
parent | 474ad4bfaf3a83f01fcbc09f1d60ee0b1f084640 (diff) |
some much more flexible thumbnail generation
git-svn-id: file:///var/lib/svn/phpfspot/trunk@118 fa6a889d-dae6-447d-9e79-4ba9a3039384
Diffstat (limited to 'phpfspot.class.php')
-rw-r--r-- | phpfspot.class.php | 94 |
1 files changed, 62 insertions, 32 deletions
diff --git a/phpfspot.class.php b/phpfspot.class.php index 18c00cf..06ded52 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -117,25 +117,39 @@ class PHPFSPOT { } } - $details = $this->get_photo_details($photo); - $meta = $this->get_meta_informations($this->translate_path($details['directory_path']) ."/". $details['name']); - $info = getimagesize($this->translate_path($details['directory_path']) ."/thumbs/". $this->cfg->photo_width ."_". $details['name']); + $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name']; + $thumb_path = $this->translate_path($details['directory_path']) ."/thumbs/". $this->cfg->photo_width ."_". $details['name']; + + /* If the thumbnail doesn't exist yet, try to create it */ + if(!file_exists($thumb_path)) { + $this->gen_thumb($photo, 0, 1); + } + + $meta = $this->get_meta_informations($orig_path); - $this->tmpl->assign('description', $details['description']); - $this->tmpl->assign('image_name', $details['name']); + if(file_exists($thumb_path)) { - $this->tmpl->assign('width', $info[0]); - $this->tmpl->assign('height', $info[1]); - $this->tmpl->assign('ExifMadeOn', strftime("%a %x %X", $meta['FileDateTime'])); - $this->tmpl->assign('ExifMadeWith', $meta['Make'] ." ". $meta['Model']); - $this->tmpl->assign('ExifOrigResolution', $meta['ExifImageWidth'] ."x". $meta['ExifImageLength']); - $this->tmpl->assign('ExifFileSize', round($meta['FileSize']/1024, 1)); - - $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width); - $this->tmpl->assign('image_url_full', 'phpfspot_img.php?idx='. $photo); + $info = getimagesize($thumb_path); - $this->tmpl->assign('tags', $this->get_photo_tags($photo)); + $this->tmpl->assign('description', $details['description']); + $this->tmpl->assign('image_name', $details['name']); + + $this->tmpl->assign('width', $info[0]); + $this->tmpl->assign('height', $info[1]); + $this->tmpl->assign('ExifMadeOn', strftime("%a %x %X", $meta['FileDateTime'])); + $this->tmpl->assign('ExifMadeWith', $meta['Make'] ." ". $meta['Model']); + $this->tmpl->assign('ExifOrigResolution', $meta['ExifImageWidth'] ."x". $meta['ExifImageLength']); + $this->tmpl->assign('ExifFileSize', round($meta['FileSize']/1024, 1)); + + $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width); + $this->tmpl->assign('image_url_full', 'phpfspot_img.php?idx='. $photo); + + $this->tmpl->assign('tags', $this->get_photo_tags($photo)); + } + else { + print "Can't open file ". $thumb_path ."\n"; + } if($previous_img) { $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");"); @@ -532,34 +546,50 @@ class PHPFSPOT { } // check_config_table + /** + * Generates a thumbnail from photo idx + * + * This function will generate JPEG thumbnails from provided F-Spot photo + * indizes. + * + * 1. Check if all thumbnail generations (width) are already in place and + * readable + * 2. Check if the md5sum of the original file has changed + * 3. Generate the thumbnails if needed + */ public function gen_thumb($idx = 0, $fromcmd = 0, $force = 0) { - $details = $this->get_photo_details($idx); + $resolutions = Array( + $this->cfg->thumb_width, + $this->cfg->bubble_width, + $this->cfg->photo_width, + ); + $details = $this->get_photo_details($idx); $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 the file hasn't changed there is no need to regen the thumb */ - if(!$force && $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 - ); - $error = 0; - /* create thumbnails for the requested resolutions */ foreach($resolutions as $resolution) { - if($fromcmd) print " ". $resolution ."px"; - if(!$this->create_thumbnail($full_path, $resolution)) - $error = 1; + $thumb_path = $this->translate_path($details['directory_path']) ."/thumbs/". $resolution ."_". $details['name']; + if(!file_exists($thumb_path)) { + + if($fromcmd) print " ". $resolution ."px"; + if(!$this->create_thumbnail($full_path, $resolution)) + $error = 1; + + } + /* if the file hasn't changed there is no need to regen the thumb */ + elseif($file_md5 != $this->getMD5($idx) || $force) { + + if($fromcmd) print " ". $resolution ."px"; + if(!$this->create_thumbnail($full_path, $resolution)) + $error = 1; + + } } /* set the new/changed MD5 sum for the current photo */ |