Merge pull request #37140 from nextcloud/enh/35643/fix-heic-previews

imaginary - fix autorotate for heic and improve the logic
pull/36903/head
Simon L 2023-03-09 10:25:54 +07:00 committed by GitHub
commit 691aa8d025
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 33 deletions

@ -82,8 +82,14 @@ class Imaginary extends ProviderV2 {
$httpClient = $this->service->newClient();
$convert = false;
$autorotate = true;
switch ($file->getMimeType()) {
case 'image/heic':
// Autorotate seems to be broken for Heic so disable for that
$autorotate = false;
$mimeType = 'jpeg';
break;
case 'image/gif':
case 'image/png':
$mimeType = 'png';
@ -92,50 +98,43 @@ class Imaginary extends ProviderV2 {
case 'application/pdf':
case 'application/illustrator':
$convert = true;
// Converted files do not need to be autorotated
$autorotate = false;
$mimeType = 'png';
break;
default:
$mimeType = 'jpeg';
}
$operations = [];
if ($convert) {
$operations = [
[
'operation' => 'convert',
'params' => [
'type' => 'png',
]
],
[
'operation' => ($crop ? 'smartcrop' : 'fit'),
'params' => [
'width' => $maxX,
'height' => $maxY,
'type' => 'png',
'norotation' => 'true',
]
$operations[] = [
'operation' => 'convert',
'params' => [
'type' => $mimeType,
]
];
} else {
$quality = $this->config->getAppValue('preview', 'jpeg_quality', '80');
$operations = [
[
'operation' => 'autorotate',
],
[
'operation' => ($crop ? 'smartcrop' : 'fit'),
'params' => [
'width' => $maxX,
'height' => $maxY,
'stripmeta' => 'true',
'type' => $mimeType,
'norotation' => 'true',
'quality' => $quality,
]
]
} elseif ($autorotate) {
$operations[] = [
'operation' => 'autorotate',
];
}
$quality = $this->config->getAppValue('preview', 'jpeg_quality', '80');
$operations[] = [
'operation' => ($crop ? 'smartcrop' : 'fit'),
'params' => [
'width' => $maxX,
'height' => $maxY,
'stripmeta' => 'true',
'type' => $mimeType,
'norotation' => 'true',
'quality' => $quality,
]
];
try {
$response = $httpClient->post(
$imaginaryUrl . '/pipeline', [