]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix distorted previews when using imaginary 35115/head
authorRichard Steinmetz <richard@steinmetz.cloud>
Fri, 11 Nov 2022 13:21:05 +0000 (14:21 +0100)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Fri, 11 Nov 2022 21:51:43 +0000 (21:51 +0000)
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
lib/private/Preview/Imaginary.php

index 4da88f1ab26b9cd0061445b451f8be45e719ddc7..a9883a1dd9c1335457b43d7feebdb551e07c838c 100644 (file)
@@ -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;
        }