summaryrefslogtreecommitdiffstats
path: root/lib/private/image.php
diff options
context:
space:
mode:
authorOlivier Paroz <github@oparoz.com>2015-06-06 16:21:36 +0200
committerOlivier Paroz <github@oparoz.com>2015-06-06 16:25:04 +0200
commit71d65cb713ebfb85ee19f9f3cd17dd915360fe9b (patch)
tree7281b8a32d148d27ae375dd1c45308416e63eee7 /lib/private/image.php
parent16708ae1873ddd563c3177b87cf7a4c395dca609 (diff)
downloadnextcloud-server-71d65cb713ebfb85ee19f9f3cd17dd915360fe9b.tar.gz
nextcloud-server-71d65cb713ebfb85ee19f9f3cd17dd915360fe9b.zip
Fix max preview, some resizing and caching issues and force preview providers to resize their previews properly
* introduces a method in OC_Image which doesn't stretch images when trying to make them fit in a box * adds the method to all key providers so that they can do their job, as expected by the Preview class * improves the caching mechanism of Preview in order to reduce I/O and to avoid filling the available disk space * fixes some long standing issues * **contains mostly tests**
Diffstat (limited to 'lib/private/image.php')
-rw-r--r--lib/private/image.php20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/private/image.php b/lib/private/image.php
index d229ed42511..54e5ef7cad5 100644
--- a/lib/private/image.php
+++ b/lib/private/image.php
@@ -952,6 +952,8 @@ class OC_Image implements \OCP\IImage {
/**
* Resizes the image to fit within a boundary while preserving ratio.
*
+ * Warning: Images smaller than $maxWidth x $maxHeight will end up being scaled up
+ *
* @param integer $maxWidth
* @param integer $maxHeight
* @return bool
@@ -973,6 +975,24 @@ class OC_Image implements \OCP\IImage {
}
/**
+ * Shrinks larger images to fit within specified boundaries while preserving ratio.
+ *
+ * @param integer $maxWidth
+ * @param integer $maxHeight
+ * @return bool
+ */
+ public function scaleDownToFit($maxWidth, $maxHeight) {
+ $widthOrig = imageSX($this->resource);
+ $heightOrig = imageSY($this->resource);
+
+ if ($widthOrig > $maxWidth || $heightOrig >$maxHeight) {
+ return $this->fitIn($maxWidth, $maxHeight);
+ }
+
+ return false;
+ }
+
+ /**
* Destroys the current image and resets the object
*/
public function destroy() {