Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imaginary - fix autorotate for heic and improve the logic #37140

Merged
merged 1 commit into from
Mar 9, 2023
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
65 changes: 32 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,43 @@ 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are $autorotate and $convert mutually exclusive ? If no, I would convert to if instead of ifesle

Copy link
Contributor Author

@szaimen szaimen Mar 9, 2023

Choose a reason for hiding this comment

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

Currently they are mutually exclusive as autorate only makes sense for images (and not other files) that dont need to be converted and the other way around.

$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