aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Preview
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-10-31 13:40:41 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2018-10-31 19:34:42 +0100
commitce10f8b8c42ab67a1bf523a31e72cdcf13a98900 (patch)
treeccc45ba1edfc7504d303370950e18fbabedb425b /lib/private/Preview
parent654365581b50590efda188fbd8a2c961c99a386c (diff)
downloadnextcloud-server-ce10f8b8c42ab67a1bf523a31e72cdcf13a98900.tar.gz
nextcloud-server-ce10f8b8c42ab67a1bf523a31e72cdcf13a98900.zip
Only generate previews in powers of 4 and set min
Before we'd round up all preview request to their nearest power of two. This resulted still in a lot of possible images. Generating a lot of server load and taking up a lot of space. This moves it to previews to be powers of 4: 64, 256, 1024 and 4096 Also the first two powers are always skipped (4, 16) as it doesn't make sense to generate previews for that. We cache preview pretty agressively and I feel this is a better tradeoff. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Preview')
-rw-r--r--lib/private/Preview/Generator.php18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php
index 86579e3480b..1f7decf2b79 100644
--- a/lib/private/Preview/Generator.php
+++ b/lib/private/Preview/Generator.php
@@ -298,19 +298,23 @@ class Generator {
if ($height !== $maxHeight && $width !== $maxWidth) {
/*
- * Scale to the nearest power of two
+ * Scale to the nearest power of four
*/
- $pow2height = 2 ** ceil(log($height) / log(2));
- $pow2width = 2 ** ceil(log($width) / log(2));
+ $pow4height = 4 ** ceil(log($height) / log(4));
+ $pow4width = 4 ** ceil(log($width) / log(4));
- $ratioH = $height / $pow2height;
- $ratioW = $width / $pow2width;
+ // Minimum size is 64
+ $pow4height = max($pow4height, 64);
+ $pow4width = max($pow4width, 64);
+
+ $ratioH = $height / $pow4height;
+ $ratioW = $width / $pow4width;
if ($ratioH < $ratioW) {
- $width = $pow2width;
+ $width = $pow4width;
$height /= $ratioW;
} else {
- $height = $pow2height;
+ $height = $pow4height;
$width /= $ratioH;
}
}