From 98e55ea4f0b1e26f16c1df967b97a7727fe17c8f Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Fri, 11 Nov 2022 14:21:05 +0100 Subject: [PATCH] Fix distorted previews when using imaginary Signed-off-by: Richard Steinmetz --- lib/private/Preview/Imaginary.php | 18 ++++++++++++++---- 1 file 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; } -- 2.39.5