summaryrefslogtreecommitdiffstats
path: root/apps/gallery
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-02-07 22:33:01 +0100
committerBart Visscher <bartv@thisnet.nl>2012-02-08 21:12:30 +0100
commiteb5de4d4f7b98bb1c258dbb5ed5ecf9c2d39e746 (patch)
tree47ae2ac83a8241730c1070ce582564064c778839 /apps/gallery
parent7c03b612d2c58f9cc02c46c82e137087b1591d07 (diff)
downloadnextcloud-server-eb5de4d4f7b98bb1c258dbb5ed5ecf9c2d39e746.tar.gz
nextcloud-server-eb5de4d4f7b98bb1c258dbb5ed5ecf9c2d39e746.zip
Change gallery thumbnail generation to OC_Image
Diffstat (limited to 'apps/gallery')
-rw-r--r--apps/gallery/ajax/galleryOp.php2
-rw-r--r--apps/gallery/ajax/thumbnail.php65
2 files changed, 12 insertions, 55 deletions
diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php
index f819d87f666..0ec447d01f6 100644
--- a/apps/gallery/ajax/galleryOp.php
+++ b/apps/gallery/ajax/galleryOp.php
@@ -69,7 +69,7 @@ function handlePartialCreate($path) {
if (!OC_Filesystem::is_dir($path)) OC_JSON::error(array('cause' => 'Invalid path given'));
$album = OC_Gallery_Album::find(OC_User::getUser(), null, $path);
- $albums;
+ $albums = array();
OC_Gallery_Scanner::scanDir($path, $albums);
OC_JSON::success(array('album_details' => $albums));
}
diff --git a/apps/gallery/ajax/thumbnail.php b/apps/gallery/ajax/thumbnail.php
index 6d25c7a2536..ad91edfa3c8 100644
--- a/apps/gallery/ajax/thumbnail.php
+++ b/apps/gallery/ajax/thumbnail.php
@@ -25,65 +25,22 @@ require_once('../../../lib/base.php');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('gallery');
-function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height) { //$imgSrc is a FILE - Returns an image resource.
- //getting the image dimensions
- if(! function_exists('imagecreatefromjpeg'))
- OC_Log::write('gallery','GD module not installed',OC_Log::ERROR);
-
- 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();
- }
- if(!$myImage) 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;
-}
-
$box_size = 200;
$img = $_GET['img'];
$imagePath = OC_Filesystem::getLocalFile($img);
-if(file_exists($imagePath))
-{
- $image = CroppedThumbnail($imagePath, $box_size, $box_size);
+if(file_exists($imagePath)) {
+ $image = new OC_Image($imagePath);
+ $image->centerCrop();
+ $image->resize($box_size, $box_size);
+ $image->fixOrientation();
- header('Content-Type: image/png');
- $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');
+ $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');
- imagepng($image);
- imagedestroy($image);
+ $image->show();
}