diff options
author | Richard Steinmetz <richard@steinmetz.cloud> | 2022-11-11 14:21:05 +0100 |
---|---|---|
committer | Richard Steinmetz <richard@steinmetz.cloud> | 2022-11-11 14:21:05 +0100 |
commit | 98e55ea4f0b1e26f16c1df967b97a7727fe17c8f (patch) | |
tree | 93c383305555d4d5a48c5950b13fb51ef483adab /lib/private/Preview | |
parent | 96855d73a23dd702653674031ee4e1e78a7f7c66 (diff) | |
download | nextcloud-server-98e55ea4f0b1e26f16c1df967b97a7727fe17c8f.tar.gz nextcloud-server-98e55ea4f0b1e26f16c1df967b97a7727fe17c8f.zip |
Fix distorted previews when using imaginary
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Diffstat (limited to 'lib/private/Preview')
-rw-r--r-- | lib/private/Preview/Imaginary.php | 18 |
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; } |