Skip to content

Commit

Permalink
Merge pull request #35115 from nextcloud/backport/35105/stable24
Browse files Browse the repository at this point in the history
[stable24] Fix distorted previews when using imaginary
  • Loading branch information
st3iny authored Nov 15, 2022
2 parents d3c68c1 + 939abff commit 479aa6f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/private/Preview/Imaginary.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IImage;
use OCP\Image;

use OC\StreamImage;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -126,12 +127,21 @@ public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop
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;
}

Expand Down

0 comments on commit 479aa6f

Please sign in to comment.