[Pkg-owncloud-commits] [owncloud] 46/61: Also keep maxY into account when scaling a preview while preserving aspect ratio

David Prévot taffit at moszumanska.debian.org
Thu Jul 31 03:51:47 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 4f40cde66afe2376ede177020882e5236a5a3373
Author: Robin Appelman <icewind at owncloud.com>
Date:   Tue Jul 29 17:23:44 2014 +0200

    Also keep maxY into account when scaling a preview while preserving aspect ratio
---
 apps/files_sharing/ajax/publicpreview.php |  4 ----
 core/ajax/preview.php                     |  4 ----
 lib/private/preview.php                   | 10 ++++++++--
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/apps/files_sharing/ajax/publicpreview.php b/apps/files_sharing/ajax/publicpreview.php
index 0b2af7a..f5343a7 100644
--- a/apps/files_sharing/ajax/publicpreview.php
+++ b/apps/files_sharing/ajax/publicpreview.php
@@ -70,10 +70,6 @@ if(substr($path, 0, 1) === '/') {
 	$path = substr($path, 1);
 }
 
-if ($keepAspect === true) {
-	$maxY = $maxX;
-}
-
 if($maxX === 0 || $maxY === 0) {
 	\OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST);
 	\OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG);
diff --git a/core/ajax/preview.php b/core/ajax/preview.php
index d380437..edbd41d 100644
--- a/core/ajax/preview.php
+++ b/core/ajax/preview.php
@@ -21,10 +21,6 @@ if ($file === '') {
 	exit;
 }
 
-if ($keepAspect === true) {
-	$maxY = $maxX;
-}
-
 if ($maxX === 0 || $maxY === 0) {
 	//400 Bad Request
 	\OC_Response::setStatus(400);
diff --git a/lib/private/preview.php b/lib/private/preview.php
index 8089379..6172519 100755
--- a/lib/private/preview.php
+++ b/lib/private/preview.php
@@ -561,9 +561,15 @@ class Preview {
 		$realX = (int)$image->width();
 		$realY = (int)$image->height();
 
-		// compute $maxY using the aspect of the generated preview
+		// compute $maxY and $maxX using the aspect of the generated preview
 		if ($this->keepAspect) {
-			$y = $x / ($realX / $realY);
+			$ratio = $realX / $realY;
+			if($x / $ratio < $y) {
+				// width restricted
+				$y = $x / $ratio;
+			} else {
+				$x = $y * $ratio;
+			}
 		}
 
 		if ($x === $realX && $y === $realY) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list