]> source.dussan.org Git - nextcloud-server.git/commitdiff
Also keep maxY into account when scaling a preview while preserving aspect ratio
authorRobin Appelman <icewind@owncloud.com>
Tue, 29 Jul 2014 15:23:44 +0000 (17:23 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Wed, 30 Jul 2014 11:52:40 +0000 (13:52 +0200)
apps/files_sharing/ajax/publicpreview.php
core/ajax/preview.php
lib/private/preview.php

index 0b2af7a6e5960863fed90885dc10c1a2e7e044df..f5343a7ef269519f08f4091ca1956f855c6eb221 100644 (file)
@@ -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);
index d38043707ac7086c4673946223f58300c1aa5705..edbd41d2db45c3b43883430c55ea350daf0fa56f 100644 (file)
@@ -21,10 +21,6 @@ if ($file === '') {
        exit;
 }
 
-if ($keepAspect === true) {
-       $maxY = $maxX;
-}
-
 if ($maxX === 0 || $maxY === 0) {
        //400 Bad Request
        \OC_Response::setStatus(400);
index 8089379bde5ba20d195baf329543c96800b0c3f9..6172519c7d19cafaaa05e99f6e8552fe14fb8172 100755 (executable)
@@ -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) {