summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2015-09-25 16:00:05 +0200
committerMorris Jobke <hey@morrisjobke.de>2015-09-29 13:07:03 +0200
commitf41a38ba1510e65be675834aefe5b57368b119dd (patch)
tree3bcf1aa983af838a7a01c93a1b2efa7916543c0f /lib
parentc269f658eb2ab8a69287a36b3bb923ae071a40d0 (diff)
downloadnextcloud-server-f41a38ba1510e65be675834aefe5b57368b119dd.tar.gz
nextcloud-server-f41a38ba1510e65be675834aefe5b57368b119dd.zip
Cover both width and height for the sidebar preview
Diffstat (limited to 'lib')
-rw-r--r--lib/private/preview.php50
1 files changed, 27 insertions, 23 deletions
diff --git a/lib/private/preview.php b/lib/private/preview.php
index de964b72df2..cd92f15b921 100644
--- a/lib/private/preview.php
+++ b/lib/private/preview.php
@@ -837,14 +837,6 @@ class Preview {
$askedWidth = $this->getMaxX();
$askedHeight = $this->getMaxY();
- /**
- * Phase 1: If required, adjust boundaries to keep aspect ratio
- */
- if ($this->keepAspect) {
- list($askedWidth, $askedHeight) =
- $this->applyAspectRatio($askedWidth, $askedHeight, $previewWidth, $previewHeight);
- }
-
if ($this->mode === self::MODE_COVER) {
list($scaleWidth, $scaleHeight) =
$this->applyCover($askedWidth, $askedHeight, $previewWidth, $previewHeight);
@@ -854,6 +846,14 @@ class Preview {
}
/**
+ * Phase 1: If required, adjust boundaries to keep aspect ratio
+ */
+ if ($this->keepAspect) {
+ list($scaleWidth, $scaleHeight) =
+ $this->applyAspectRatio($scaleWidth, $scaleHeight, $previewWidth, $previewHeight);
+ }
+
+ /**
* Phase 2: Resizes preview to try and match requirements.
* Takes the scaling ratio into consideration
*/
@@ -870,26 +870,30 @@ class Preview {
/**
* Phase 3: We're still not there yet, so we're clipping and filling
- * to match the asked dimensions
+ * to match the asked dimensions if we're not asked to keep aspect ratio
*/
- // It turns out the scaled preview is now too big, so we crop the image
- if ($newPreviewWidth >= $askedWidth && $newPreviewHeight >= $askedHeight) {
- $this->crop($image, $askedWidth, $askedHeight, $newPreviewWidth, $newPreviewHeight);
- $this->storePreview($fileId, $askedWidth, $askedHeight);
- return;
- }
+ if (!$this->keepAspect) {
+ // It turns out the scaled preview is now too big, so we crop the image
+ if ($newPreviewWidth >= $askedWidth && $newPreviewHeight >= $askedHeight) {
+ $this->crop($image, $askedWidth, $askedHeight, $newPreviewWidth, $newPreviewHeight);
+ $this->storePreview($fileId, $askedWidth, $askedHeight);
- // At least one dimension of the scaled preview is too small,
- // so we fill the space with a transparent background
- if (($newPreviewWidth < $askedWidth || $newPreviewHeight < $askedHeight)) {
- $this->cropAndFill(
- $image, $askedWidth, $askedHeight, $newPreviewWidth, $newPreviewHeight
- );
- $this->storePreview($fileId, $askedWidth, $askedHeight);
+ return;
+ }
- return;
+ // At least one dimension of the scaled preview is too small,
+ // so we fill the space with a transparent background
+ if (($newPreviewWidth < $askedWidth || $newPreviewHeight < $askedHeight)) {
+ $this->cropAndFill(
+ $image, $askedWidth, $askedHeight, $newPreviewWidth, $newPreviewHeight
+ );
+ $this->storePreview($fileId, $askedWidth, $askedHeight);
+
+ return;
+ }
}
+
// The preview is smaller, but we can't touch it
$this->storePreview($fileId, $newPreviewWidth, $newPreviewHeight);
}