set a startup variable. unset it with the first call of the photo index page
[phpfspot.git] / phpfspot.class.php
index 980dc818a09ed510a3d62e6a2f0f727594b9788b..9d159ff3ff02e09d46c374d50a0a23d1ccb89d87 100644 (file)
@@ -399,6 +399,9 @@ class PHPFSPOT {
 
       $count = count($photos);
 
 
       $count = count($photos);
 
+      if(isset($_SESSION['begin_with']) && $_SESSION['begin_with'] != "")
+         $anchor = $_SESSION['begin_with'];
+
       if(!isset($this->cfg->rows_per_page) || $this->cfg->rows_per_page == 0) {
 
          $begin_with = 0;
       if(!isset($this->cfg->rows_per_page) || $this->cfg->rows_per_page == 0) {
 
          $begin_with = 0;
@@ -435,10 +438,12 @@ class PHPFSPOT {
       $images[$rows] = Array();
       $img_height[$rows] = Array();
       $img_width[$rows] = Array();
       $images[$rows] = Array();
       $img_height[$rows] = Array();
       $img_width[$rows] = Array();
+      $img_id[$rows] = Array();
 
       for($i = $begin_with; $i < $end_with; $i++) {
 
          $images[$rows][$cols] = $photos[$i];
 
       for($i = $begin_with; $i < $end_with; $i++) {
 
          $images[$rows][$cols] = $photos[$i];
+         $img_id[$rows][$cols] = $i;
 
          $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->thumb_width ."_". $this->getMD5($photos[$i]);
 
 
          $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->thumb_width ."_". $this->getMD5($photos[$i]);
 
@@ -535,10 +540,14 @@ class PHPFSPOT {
       $this->tmpl->assign('images', $images);
       $this->tmpl->assign('img_width', $img_width);
       $this->tmpl->assign('img_height', $img_height);
       $this->tmpl->assign('images', $images);
       $this->tmpl->assign('img_width', $img_width);
       $this->tmpl->assign('img_height', $img_height);
+      $this->tmpl->assign('img_id', $img_id);
       $this->tmpl->assign('rows', $rows);
       $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
       $this->tmpl->assign('rows', $rows);
       $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
+
       $this->tmpl->show("photo_index.tpl");
 
       $this->tmpl->show("photo_index.tpl");
 
+      if(isset($anchor))
+         print "<script language=\"JavaScript\">self.location.hash = '#image". $anchor ."';</script>\n";
 
    } // showPhotoIndex()
 
 
    } // showPhotoIndex()
 
@@ -631,23 +640,39 @@ class PHPFSPOT {
       }
 
       /* grabs the height and width */
       }
 
       /* grabs the height and width */
-      $new_w = imagesx($src_img);
-      $new_h = imagesy($src_img);
+      $cur_width = imagesx($src_img);
+      $cur_height = imagesy($src_img);
 
       // If requested width is more then the actual image width,
       // do not generate a thumbnail
 
 
       // If requested width is more then the actual image width,
       // do not generate a thumbnail
 
-      if($width >= $new_w) {
+      if($width >= $cur_width) {
          imagedestroy($src_img);
          return true;
       }
 
       /* calculates aspect ratio */
          imagedestroy($src_img);
          return true;
       }
 
       /* calculates aspect ratio */
-      $aspect_ratio = $new_h / $new_w;
+      $aspect_ratio = $cur_height / $cur_width;
 
       /* sets new size */
 
       /* sets new size */
-      $new_w = $width;
-      $new_h = abs($new_w * $aspect_ratio);
+      if($aspect_ratio < 1) {
+         $new_w = $width;
+         $new_h = abs($new_w * $aspect_ratio);
+      } else {
+         /* 'virtually' rotate the image and calculate it's ratio */
+         $tmp_w = $cur_height;
+         $tmp_h = $cur_width;
+         /* now get the ratio from the 'rotated' image */
+         $tmp_ratio = $tmp_h/$tmp_w;
+         /* now calculate the new dimensions */
+         $tmp_w = $width;
+         $tmp_h = abs($tmp_w * $tmp_ratio);
+
+         // now that we know, how high they photo should be, if it
+         // gets rotated, use this high to scale the image
+         $new_h = $tmp_h;
+         $new_w = abs($new_h / $aspect_ratio);
+      }
 
       /* creates new image of that size */
       $dst_img = imagecreatetruecolor($new_w, $new_h);
 
       /* creates new image of that size */
       $dst_img = imagecreatetruecolor($new_w, $new_h);
@@ -667,7 +692,7 @@ class PHPFSPOT {
       }
 
       if($rotate) {
       }
 
       if($rotate) {
-         print "(ROTATE)";
+         $this->_debug("(ROTATE)");
          $dst_img = $this->rotateImage($dst_img, $rotate);
       }
 
          $dst_img = $this->rotateImage($dst_img, $rotate);
       }