From ef1924dbbb662a1e33d7fc74cb7c9e1b36585225 Mon Sep 17 00:00:00 2001 From: BlackEagle Date: Fri, 25 May 2012 22:07:36 +0200 Subject: [PATCH] gallery :: display big picture according to exif - 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 --- apps/gallery/ajax/viewImage.php | 34 +++++++++++++++++++++++++++++++++ apps/gallery/js/albums.js | 2 +- apps/gallery/lib/photo.php | 31 ++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 apps/gallery/ajax/viewImage.php diff --git a/apps/gallery/ajax/viewImage.php b/apps/gallery/ajax/viewImage.php new file mode 100644 index 0000000000..4f7af1496f --- /dev/null +++ b/apps/gallery/ajax/viewImage.php @@ -0,0 +1,34 @@ +. + * + */ + + +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(); +} diff --git a/apps/gallery/js/albums.js b/apps/gallery/js/albums.js index 413c71471a..62d3f783ec 100644 --- a/apps/gallery/js/albums.js +++ b/apps/gallery/js/albums.js @@ -79,7 +79,7 @@ Albums={ }); element.append(local); } - var photoDisplayTemplate = ''; + var photoDisplayTemplate = ''; for (var i in Albums.photos) { element.append(photoDisplayTemplate.replace("IMGPATH", escape(Albums.photos[i])).replace("URLPATH", escape(Albums.photos[i]))); } diff --git a/apps/gallery/lib/photo.php b/apps/gallery/lib/photo.php index f9527cb5fd..38a6690c63 100644 --- a/apps/gallery/lib/photo.php +++ b/apps/gallery/lib/photo.php @@ -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', ''); }