diff options
Diffstat (limited to 'apps/gallery/ajax')
-rw-r--r-- | apps/gallery/ajax/cover.php | 62 | ||||
-rw-r--r-- | apps/gallery/ajax/createAlbum.php | 14 | ||||
-rw-r--r-- | apps/gallery/ajax/getCovers.php | 16 | ||||
-rw-r--r-- | apps/gallery/ajax/scanForAlbums.php | 14 | ||||
-rw-r--r-- | apps/gallery/ajax/thumbnail.php | 59 |
5 files changed, 165 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); +?> diff --git a/apps/gallery/ajax/createAlbum.php b/apps/gallery/ajax/createAlbum.php new file mode 100644 index 00000000000..93e3312d324 --- /dev/null +++ b/apps/gallery/ajax/createAlbum.php @@ -0,0 +1,14 @@ +<? +require_once('../../../lib/base.php'); + +if( !OC_User::isLoggedIn()){ + echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => 'You need to log in.'))); + exit(); +} + +$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums ("uid_owner", "album_name") VALUES ("'.OC_User::getUser().'", "'.$_GET['album_name'].'")'); +$stmt->execute(array()); + +echo json_encode(array( 'status' => 'success', 'name' => $_GET['album_name'])); + +?> diff --git a/apps/gallery/ajax/getCovers.php b/apps/gallery/ajax/getCovers.php new file mode 100644 index 00000000000..69c03d3a446 --- /dev/null +++ b/apps/gallery/ajax/getCovers.php @@ -0,0 +1,16 @@ +<? + +require_once('../../../lib/base.php'); + +$album_name = $_GET['album']; + +$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)); +$images = array(); +while ($i = $result->fetchRow()) { + $images[] = $i['file_path']; +} + +echo json_encode(array('status' => 'success', 'imageCount' => $result->numRows(), 'images' => $images)); + +?> diff --git a/apps/gallery/ajax/scanForAlbums.php b/apps/gallery/ajax/scanForAlbums.php new file mode 100644 index 00000000000..64832a113b6 --- /dev/null +++ b/apps/gallery/ajax/scanForAlbums.php @@ -0,0 +1,14 @@ +<? + +require_once('../../../lib/base.php'); +require_once('../lib_scanner.php'); + +if (!OC_User::IsLoggedIn()) { + echo json_encode(array('status' => 'error', 'message' => 'You need to log in')); + exit(); +} + +echo json_encode(array( 'status' => 'success', 'albums' => OC_GALLERY_SCANNER::scan(''))); +//echo json_encode(array('status' => 'success', 'albums' => array(array('name' => 'test', 'imagesCount' => 1, 'images' => array('dupa'))))); + +?> diff --git a/apps/gallery/ajax/thumbnail.php b/apps/gallery/ajax/thumbnail.php new file mode 100644 index 00000000000..c8b9ee3ef3e --- /dev/null +++ b/apps/gallery/ajax/thumbnail.php @@ -0,0 +1,59 @@ +<? +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": + case "tiff": + $myImage = imagecreatefromjpeg($imgSrc); + break; + case "png": + $myImage = imagecreatefrompng($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; +$img = $_GET['img']; + +$tmp = OC::$CONFIG_DATADIRECTORY . $img; +$imagesize = getimagesize($tmp); + +header('Content-Type: image/png'); +$image = CroppedThumbnail($tmp, $box_size, $box_size); + +imagepng($image); +imagedestroy($image); +?> |