Merge pull request #10024 from owncloud/preview-restrict-height

Also keep maxY into account when scaling a preview while preserving aspect ratio
This commit is contained in:
Morris Jobke 2014-07-30 17:22:20 +02:00
commit 62b37fbb99
3 changed files with 8 additions and 10 deletions

View File

@ -70,10 +70,6 @@ if(substr($path, 0, 1) === '/') {
$path = substr($path, 1); $path = substr($path, 1);
} }
if ($keepAspect === true) {
$maxY = $maxX;
}
if($maxX === 0 || $maxY === 0) { if($maxX === 0 || $maxY === 0) {
\OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); \OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST);
\OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG);

View File

@ -21,10 +21,6 @@ if ($file === '') {
exit; exit;
} }
if ($keepAspect === true) {
$maxY = $maxX;
}
if ($maxX === 0 || $maxY === 0) { if ($maxX === 0 || $maxY === 0) {
//400 Bad Request //400 Bad Request
\OC_Response::setStatus(400); \OC_Response::setStatus(400);

View File

@ -561,9 +561,15 @@ class Preview {
$realX = (int)$image->width(); $realX = (int)$image->width();
$realY = (int)$image->height(); $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) { 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) { if ($x === $realX && $y === $realY) {