diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2018-10-31 20:25:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-31 20:25:53 +0100 |
commit | 3ee7597be038ed199faeafbc102f25970bd3288a (patch) | |
tree | ae9c561a1197f461794bc643125b8df55ebc9243 /lib | |
parent | ed35bc7f4023d74a71422f6521086a21199b546f (diff) | |
parent | ce10f8b8c42ab67a1bf523a31e72cdcf13a98900 (diff) | |
download | nextcloud-server-3ee7597be038ed199faeafbc102f25970bd3288a.tar.gz nextcloud-server-3ee7597be038ed199faeafbc102f25970bd3288a.zip |
Merge pull request #12166 from nextcloud/feature/limit_preview_sizes
Only generate previews in powers of 4 and set min
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Preview/Generator.php | 18 |
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; } } |