moved resize_image function to PHPFSPOT class
authorAndreas Unterkircher <unki@netshadow.at>
Thu, 7 Jun 2007 20:05:18 +0000 (20:05 +0000)
committerAndreas Unterkircher <unki@netshadow.at>
Thu, 7 Jun 2007 20:05:18 +0000 (20:05 +0000)
git-svn-id: file:///var/lib/svn/phpfspot/trunk@46 fa6a889d-dae6-447d-9e79-4ba9a3039384

phpfspot.class.php
phpfspot_img.php

index 5df3115d03861c517002144fd1c141af094d3992..641cc0efbd215feb6d8fb08473e4340837b3f69b 100644 (file)
@@ -8,6 +8,7 @@ class PHPFSPOT {
 
    var $cfg;
    var $db;
 
    var $cfg;
    var $db;
+   var $cfg_db;
    var $tmpl;
    var $tags;
    var $avail_tags;
    var $tmpl;
    var $tags;
    var $avail_tags;
@@ -17,7 +18,8 @@ class PHPFSPOT {
    {
       $this->cfg = new PHPFSPOT_CFG;
 
    {
       $this->cfg = new PHPFSPOT_CFG;
 
-      $this->db = new PHPFSPOT_DB(&$this, $this->cfg->db);
+      $this->db = new PHPFSPOT_DB(&$this, $this->cfg->fspot_db);
+      $this->cfg_db = new PHPFSPOT_DB(&$this, $this->cfg->phpfspot_db);
       $this->tmpl = new PHPFSPOT_TMPL($this);
 
       $this->get_tags();
       $this->tmpl = new PHPFSPOT_TMPL($this);
 
       $this->get_tags();
@@ -275,6 +277,58 @@ class PHPFSPOT {
 
    } // showCredits()
 
 
    } // showCredits()
 
+   public function resize_image($image, $width)
+   {  
+      // if thumbnail already exists, don't recreate it
+      if(file_exists(dirname($image) ."/thumbs/". $width ."_". basename($image)))
+         return;
+
+      $src_img = @imagecreatefromjpeg($image);
+
+      if($src_img)
+      {  
+         /* grabs the height and width */
+         $new_w = imagesx($src_img);
+         $new_h = imagesy($src_img);
+
+         // If requested width is more then the actual image width,
+         // do not generate a thumbnail
+
+         if($width >= $new_w) {
+            imagedestroy($src_img);
+            return;
+         }
+
+         /* calculates aspect ratio */
+         $aspect_ratio = $new_h / $new_w;
+
+         /* sets new size */
+         $new_w = $width;
+         $new_h = abs($new_w * $aspect_ratio);
+
+         /* creates new image of that size */
+         $dst_img = imagecreatetruecolor($new_w,$new_h);
+
+         imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
+
+         /* copies resized portion of original image into new image */
+         imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
+
+         /* write down new generated file */
+
+         if(!file_exists(dirname($image) ."/thumbs"))
+            mkdir(dirname($image) ."/thumbs");
+
+         $newfile = dirname($image) ."/thumbs/". $width ."_". basename($image);
+         imagejpeg($dst_img, $newfile, 75);
+
+         /* free your mind */
+         imagedestroy($dst_img);
+         imagedestroy($src_img);
+      }
+
+   } // resize_image()
+
 }
 
 ?>
 }
 
 ?>
index ec6c7db92be9cfd13b6fa7fc23efc0eaf259dfdf..986fbccbb251a20930bccdf3abacfd4cfbb9189e 100644 (file)
@@ -24,8 +24,8 @@ class PHPFSPOT_IMG {
    {
       $details = $this->parent->get_photo_details($idx);
 
    {
       $details = $this->parent->get_photo_details($idx);
 
-               foreach(Array($this->parent->cfg->thumb_width, $this->parent->cfg->photo_width) as $resolution)
-                 $this->resize_image($this->parent->translate_path($details['directory_path'])  ."/". $details['name'], $resolution);
+      foreach(Array($this->parent->cfg->thumb_width, $this->parent->cfg->photo_width) as $resolution)
+         $this->parent->resize_image($this->parent->translate_path($details['directory_path'])  ."/". $details['name'], $resolution);
 
       if($width == "")
          $fullpath = $this->parent->translate_path($details['directory_path'])  ."/". $details['name'];
 
       if($width == "")
          $fullpath = $this->parent->translate_path($details['directory_path'])  ."/". $details['name'];
@@ -50,57 +50,6 @@ class PHPFSPOT_IMG {
 
    } // show()
 
 
    } // show()
 
-   public function resize_image($image, $width)
-   {
-      // if thumbnail already exists, don't recreate it
-      if(file_exists(dirname($image) ."/thumbs/". $width ."_". basename($image)))
-         return;
-
-      $src_img = @imagecreatefromjpeg($image);
-        
-      if($src_img)
-      {
-         /* grabs the height and width */
-         $new_w = imagesx($src_img);
-         $new_h = imagesy($src_img);
-                
-         // If requested width is more then the actual image width,
-         // do not generate a thumbnail
-         
-         if($width >= $new_w) {
-            imagedestroy($src_img);
-            return;
-         }
-                
-         /* calculates aspect ratio */
-         $aspect_ratio = $new_h / $new_w;
-                
-         /* sets new size */
-         $new_w = $width;
-         $new_h = abs($new_w * $aspect_ratio);
-                
-         /* creates new image of that size */
-         $dst_img = imagecreatetruecolor($new_w,$new_h);
-
-         imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
-                
-         /* copies resized portion of original image into new image */
-         imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
-                
-         /* write down new generated file */
-         
-         if(!file_exists(dirname($image) ."/thumbs"))
-            mkdir(dirname($image) ."/thumbs");
-
-         $newfile = dirname($image) ."/thumbs/". $width ."_". basename($image);
-         imagejpeg($dst_img, $newfile, 75);
-                
-         /* free your mind */
-         imagedestroy($dst_img);
-         imagedestroy($src_img);
-      }
-
-   } // resize_image()
 }
 
 if(isset($_GET['idx']) && is_numeric($_GET['idx'])) {
 }
 
 if(isset($_GET['idx']) && is_numeric($_GET['idx'])) {