Skip to content

Commit

Permalink
imaginary - fix autorotate and improve the logic
Browse files Browse the repository at this point in the history
Signed-off-by: Simon L <szaimen@e.mail.de>
  • Loading branch information
szaimen committed Mar 8, 2023
1 parent 80e12cf commit 2a538b1
Showing 1 changed file with 34 additions and 33 deletions.
67 changes: 34 additions & 33 deletions lib/private/Preview/Imaginary.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop
$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';
Expand All @@ -92,50 +98,45 @@ public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop
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', [
Expand Down

0 comments on commit 2a538b1

Please sign in to comment.