]> source.dussan.org Git - nextcloud-server.git/commitdiff
gallery :: display big picture according to exif
authorBlackEagle <ike.devolder@gmail.com>
Fri, 25 May 2012 20:07:36 +0000 (22:07 +0200)
committerJörn Friedrich Dreyer <jfd@butonic.de>
Wed, 11 Jul 2012 00:33:10 +0000 (02:33 +0200)
- fixes oc-314
- caching of the 'big' images in subfolder view
  next to the tumbnails
- now choosen to use max 1200px for viewing
  this helps speeding up the viewing process

Signed-off-by: BlackEagle <ike.devolder@gmail.com>
apps/gallery/ajax/viewImage.php [new file with mode: 0644]
apps/gallery/js/albums.js
apps/gallery/lib/photo.php

diff --git a/apps/gallery/ajax/viewImage.php b/apps/gallery/ajax/viewImage.php
new file mode 100644 (file)
index 0000000..4f7af14
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+
+/**
+ * ownCloud - gallery application
+ *
+ * @author Ike Devolder
+ * @copyright 2012 Ike Devolder
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either 
+ * version 3 of the License, or any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *  
+ * You should have received a copy of the GNU Lesser General Public 
+ * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+
+
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('gallery');
+
+$img = $_GET['img'];
+
+$image = OC_Gallery_Photo::getViewImage($img);
+if ($image) {
+    OCP\Response::enableCaching(3600 * 24); // 24 hour
+    $image->show();
+}
index 413c71471a34bebe1f7639598d625b7dac54adbb..62d3f783eceded951993c3499e02b1ee7631cdbb 100644 (file)
@@ -79,7 +79,7 @@ Albums={
                        });
                        element.append(local);
                }
-               var photoDisplayTemplate = '<div class="gallery_box"><div class="dummy"></div><div><a rel="images" href="'+OC.linkTo('files','download.php')+'?file=URLPATH"><img src="'+OC.filePath('gallery','ajax','thumbnail.php')+'?img=IMGPATH"></a></div></div>';
+        var photoDisplayTemplate = '<div class="gallery_box"><div class="dummy"></div><div><a rel="images" href="'+OC.linkTo('gallery/ajax','viewImage.php')+'?img=URLPATH"><img src="'+OC.filePath('gallery','ajax','thumbnail.php')+'?img=IMGPATH"></a></div></div>';
                for (var i in Albums.photos) {
                        element.append(photoDisplayTemplate.replace("IMGPATH", escape(Albums.photos[i])).replace("URLPATH", escape(Albums.photos[i])));
                }
index f9527cb5fdbe8301ad70265b25c40e2e01a5ca58..38a6690c63b9c9446860048ee69ff7baebd3b7a0 100644 (file)
@@ -97,6 +97,37 @@ class OC_Gallery_Photo {
                return null;
        }
 
+    public static function getViewImage($image_name, $owner = null) {
+        if (!$owner) $owner = OCP\USER::getUser();
+        $save_dir = OCP\Config::getSystemValue("datadirectory").'/'. $owner .'/gallery/';
+        $save_dir .= dirname($image_name). '/view/';
+        $image_path = $image_name;
+        $view_file = $save_dir . basename($image_name);
+        if (!is_dir($save_dir)) {
+            mkdir($save_dir, 0777, true);
+        }
+        if (file_exists($view_file)) {
+            $image = new OC_Image($view_file);
+        } else {
+            $image_path = OC_Filesystem::getLocalFile($image_path);
+            if(!file_exists($image_path)) {
+                return null;
+            }
+            $image = new OC_Image($image_path);
+            if ($image->valid()) {
+                $image->resize(1200);
+                $image->fixOrientation();
+                $image->save($view_file);
+            }
+        }
+        if ($image->valid()) {
+            return $image;
+        }else{
+            $image->destroy();
+        }
+        return null;
+    }
+
        public static function getGalleryRoot() {
                return OCP\Config::getUserValue(OCP\USER::getUser(), 'gallery', 'root', '');
        }