Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Comment on lines -129 to -131
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets wait for @CarlSchwan to chwck if it is okay to not check for this header anymore. It might be possibke that we brake some instances otherwise

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break one instance using my fork of imaginary. I'll communicate this to them after my vacation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative we need to convince the imaginary maintainer that using a X- prefix for custom headers is more correct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so. Thanks Carl! :)

// 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