issue43, also return a thumbnail if requested width is below image size
[phpfspot.git] / phpfspot.class.php
index 579054d6ebd70a18caba3abd46612723c6e5474f..00c84dbd9884e4d074972ea6fd8f5c589b192514 100644 (file)
@@ -191,6 +191,12 @@ class PHPFSPOT {
       }
 
       $details = $this->get_photo_details($photo);
+
+      if(!$details) {
+         print "error";
+         return;
+      }
+
       $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
       $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->photo_width ."_". $this->getMD5($photo);
 
@@ -205,6 +211,7 @@ class PHPFSPOT {
       /* If the thumbnail doesn't exist yet, try to create it */
       if(!file_exists($thumb_path)) {
          $this->gen_thumb($photo, true);
+         $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->photo_width ."_". $this->getMD5($photo);
       }
 
       $meta = $this->get_meta_informations($orig_path);
@@ -254,6 +261,7 @@ class PHPFSPOT {
       }
       else {
          $this->_warning("Can't open file ". $thumb_path ."\n");
+         return;
       }
 
       if($previous_img) {
@@ -708,8 +716,9 @@ class PHPFSPOT {
 
    public function create_thumbnail($orig_image, $thumb_image, $width)
    {  
-      if(!file_exists($orig_image))
+      if(!file_exists($orig_image)) {
          return false;
+      }
 
       $details = getimagesize($orig_image);
       
@@ -754,9 +763,11 @@ class PHPFSPOT {
       $cur_height = imagesy($src_img);
 
       // If requested width is more then the actual image width,
-      // do not generate a thumbnail
+      // do not generate a thumbnail, instead safe the original
+      // as thumbnail but with lower quality
 
       if($width >= $cur_width) {
+         $result = imagejpeg($src_img, $thumb_image, 75);
          imagedestroy($src_img);
          return true;
       }
@@ -910,7 +921,6 @@ class PHPFSPOT {
             if(!$this->create_thumbnail($full_path, $thumb_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) {