use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IImage;
+use OCP\Image;
use OC\StreamImage;
use Psr\Log\LoggerInterface;
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;
}