aboutsummaryrefslogtreecommitdiffstats
path: root/apps/gallery/ajax/cover.php
diff options
context:
space:
mode:
authorBartek Przybylski <bart.p.pl@gmail.com>2011-09-25 22:32:08 +0200
committerBartek Przybylski <bart.p.pl@gmail.com>2011-09-25 22:32:08 +0200
commitbc43851d74e8fceea1c914e98a8cd571b84610d5 (patch)
tree171216b960b26719fe124db95a20520c9a3d0081 /apps/gallery/ajax/cover.php
parentfb01a7269304fe38369f01293f8f7fb707061363 (diff)
downloadnextcloud-server-bc43851d74e8fceea1c914e98a8cd571b84610d5.tar.gz
nextcloud-server-bc43851d74e8fceea1c914e98a8cd571b84610d5.zip
initial commit for gallery app
Diffstat (limited to 'apps/gallery/ajax/cover.php')
-rw-r--r--apps/gallery/ajax/cover.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/apps/gallery/ajax/cover.php b/apps/gallery/ajax/cover.php
new file mode 100644
index 00000000000..33d913c60ac
--- /dev/null
+++ b/apps/gallery/ajax/cover.php
@@ -0,0 +1,62 @@
+<?
+require_once('../../../lib/base.php');
+
+function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height) { //$imgSrc is a FILE - Returns an image resource.
+ //getting the image dimensions
+ list($width_orig, $height_orig) = getimagesize($imgSrc);
+ switch (strtolower(substr($imgSrc, strrpos($imgSrc, '.')+1))) {
+ case "jpeg":
+ case "jpg":
+ $myImage = imagecreatefromjpeg($imgSrc);
+ break;
+ default:
+ exit();
+ }
+ $ratio_orig = $width_orig/$height_orig;
+
+ if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
+ $new_height = $thumbnail_width/$ratio_orig;
+ $new_width = $thumbnail_width;
+ } else {
+ $new_width = $thumbnail_height*$ratio_orig;
+ $new_height = $thumbnail_height;
+ }
+
+ $x_mid = $new_width/2; //horizontal middle
+ $y_mid = $new_height/2; //vertical middle
+
+ $process = imagecreatetruecolor(round($new_width), round($new_height));
+
+ imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
+ $thumb = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
+ imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);
+
+ imagedestroy($process);
+ imagedestroy($myImage);
+ return $thumb;
+}
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => 'You need to log in.')));
+ exit();
+}
+$box_size = 200;
+$album_name = $_GET['album'];
+$x = $_GET['x'];
+
+$stmt = OC_DB::prepare('SELECT file_path FROM *PREFIX*gallery_photos,*PREFIX*gallery_albums WHERE *PREFIX*gallery_albums.uid_owner = ? AND album_name = ? AND *PREFIX*gallery_photos.album_id == *PREFIX*gallery_albums.album_id');
+$result = $stmt->execute(array(OC_User::getUser(), $album_name));
+$x = min((int)($x/($box_size/$result->numRows())), $result->numRows()-1); // get image to display
+$result->seek($x); // never throws
+$path = $result->fetchRow();
+$path = $path['file_path'];
+$tmp = OC::$CONFIG_DATADIRECTORY . $path;
+$imagesize = getimagesize($tmp);
+
+header('Content-Type: image/png');
+$image = CroppedThumbnail($tmp, $box_size, $box_size);
+
+imagepng($image);
+imagedestroy($image);
+?>