summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRichard Steinmetz <richard@steinmetz.cloud>2022-11-11 14:21:05 +0100
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>2022-11-11 22:02:05 +0000
commit8424e506c450da0b860f65e9cfea3d2f949f6446 (patch)
treef503b3563b5f1fed46d5152801de23aef30959b8 /lib
parent70414b15f9723e0c573122abe95f5aa9030fe09b (diff)
downloadnextcloud-server-8424e506c450da0b860f65e9cfea3d2f949f6446.tar.gz
nextcloud-server-8424e506c450da0b860f65e9cfea3d2f949f6446.zip
Fix distorted previews when using imaginary
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Preview/Imaginary.php18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/private/Preview/Imaginary.php b/lib/private/Preview/Imaginary.php
index 4da88f1ab26..a9883a1dd9c 100644
--- a/lib/private/Preview/Imaginary.php
+++ b/lib/private/Preview/Imaginary.php
@@ -27,6 +27,7 @@ use OCP\Files\File;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IImage;
+use OCP\Image;
use OC\StreamImage;
use Psr\Log\LoggerInterface;
@@ -126,12 +127,21 @@ class Imaginary extends ProviderV2 {
return null;
}
- if ($response->getHeader('X-Image-Width') && $response->getHeader('X-Image-Height')) {
- $maxX = (int)$response->getHeader('X-Image-Width');
- $maxY = (int)$response->getHeader('X-Image-Height');
+ // This is not optimal but previews are distorted if the wrong width and height values are
+ // used. Both dimension headers are only sent when passing the option "-return-size" to
+ // Imaginary.
+ if ($response->getHeader('Image-Width') && $response->getHeader('Image-Height')) {
+ $image = new StreamImage(
+ $response->getBody(),
+ $response->getHeader('Content-Type'),
+ (int)$response->getHeader('Image-Width'),
+ (int)$response->getHeader('Image-Height'),
+ );
+ } else {
+ $image = new Image();
+ $image->loadFromFileHandle($response->getBody());
}
- $image = new StreamImage($response->getBody(), $response->getHeader('Content-Type'), $maxX, $maxY);
return $image->valid() ? $image : null;
}