summaryrefslogtreecommitdiffstats
path: root/apps/gallery
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gallery')
-rw-r--r--apps/gallery/ajax/thumbnail.php24
-rw-r--r--apps/gallery/lib/photo.php33
2 files changed, 39 insertions, 18 deletions
diff --git a/apps/gallery/ajax/thumbnail.php b/apps/gallery/ajax/thumbnail.php
index ad91edfa3c8..2dfe936d9dd 100644
--- a/apps/gallery/ajax/thumbnail.php
+++ b/apps/gallery/ajax/thumbnail.php
@@ -25,22 +25,14 @@ require_once('../../../lib/base.php');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('gallery');
-$box_size = 200;
$img = $_GET['img'];
-$imagePath = OC_Filesystem::getLocalFile($img);
-
-if(file_exists($imagePath)) {
- $image = new OC_Image($imagePath);
- $image->centerCrop();
- $image->resize($box_size, $box_size);
- $image->fixOrientation();
-
- $offset = 3600 * 24;
- // calc the string in GMT not localtime and add the offset
- header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
- header('Cache-Control: max-age='.$offset.', must-revalidate');
- header('Pragma: public');
-
- $image->show();
+$image = OC_Gallery_Photo::getThumbnail($img);
+if ($image) {
+ $offset = 3600 * 24; // 24 hour
+ // calc the string in GMT not localtime and add the offset
+ header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
+ header('Cache-Control: max-age='.$offset.', must-revalidate');
+ header('Pragma: public');
+ $image->show();
}
diff --git a/apps/gallery/lib/photo.php b/apps/gallery/lib/photo.php
index d1fb166aee9..15783cb341a 100644
--- a/apps/gallery/lib/photo.php
+++ b/apps/gallery/lib/photo.php
@@ -21,7 +21,7 @@
*
*/
-class OC_Gallery_Photo{
+class OC_Gallery_Photo {
public static function create($albumId, $img){
$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_photos (album_id, file_path) VALUES (?, ?)');
$stmt->execute(array($albumId, $img));
@@ -65,5 +65,34 @@ class OC_Gallery_Photo{
$stmt = OC_DB::prepare("UPDATE *PREFIX*gallery_photos SET file_path = ?, album_id = ? WHERE album_id = ? and file_path = ?");
$stmt->execute(array($newpath, $newAlbumId, $oldAlbumId, $oldpath));
}
-}
+ public static function getThumbnail($image_name) {
+ $imagePath = OC_Filesystem::getLocalFile($image_name);
+ if(!file_exists($imagePath)) {
+ return null;
+ }
+ $save_dir = OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/';
+ $save_dir .= dirname($image_name). '/';
+ $image_name = basename($image_name);
+ $thumb_file = $save_dir . $image_name;
+ if (file_exists($thumb_file)) {
+ $image = new OC_Image($thumb_file);
+ } else {
+ $image = new OC_Image($imagePath);
+ if ($image->valid()) {
+ $image->centerCrop();
+ $image->resize(200);
+ $image->fixOrientation();
+ if (!is_dir($save_dir)) {
+ mkdir($save_dir, 0777, true);
+ }
+ $image->save($thumb_file);
+ }
+ }
+ if ($image->valid()) {
+ //var_dump($image, $image->resource());
+ return $image;
+ }
+ return null;
+ }
+}