Skip to content
Closed
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
imaginary - allow to generate heif, pdf and svg thumbnails
Signed-off-by: Simon L <[email protected]>
  • Loading branch information
szaimen authored and backportbot-nextcloud[bot] committed Mar 15, 2023
commit 1471e22338f6cd3cabea304fa30a963e6845cc56
32 changes: 29 additions & 3 deletions lib/private/Preview/Imaginary.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getMimeType(): string {
}

public static function supportedMimeTypes(): string {
return '/image\/(bmp|x-bitmap|png|jpeg|gif|heic|svg|tiff|webp)/';
return '/(image\/(bmp|x-bitmap|png|jpeg|gif|heic|heif|svg\+xml|tiff|webp)|application\/(pdf|illustrator))/';
}

public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop): ?IImage {
Expand All @@ -81,11 +81,18 @@ public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop

$httpClient = $this->service->newClient();

$convert = false;

switch ($file->getMimeType()) {
case 'image/gif':
case 'image/png':
$mimeType = 'png';
break;
case 'image/svg+xml':
case 'application/pdf':
case 'application/illustrator':
$convert = true;
break;
default:
$mimeType = 'jpeg';
}
Expand All @@ -103,8 +110,27 @@ public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop
'type' => $mimeType,
'norotation' => 'true',
]
]
];
];

Check failure

Code scanning / Psalm

ParseError

Syntax error, unexpected ';', expecting ',' or ']' or ')' on line 113
} else {
$quality = $this->config->getAppValue('preview', 'jpeg_quality', '80');

Check failure

Code scanning / Psalm

ParseError

Syntax error, unexpected ')', expecting ']' on line 115

$operations = [
[
'operation' => 'autorotate',
],
[
'operation' => ($crop ? 'smartcrop' : 'fit'),
'params' => [
'width' => $maxX,
'height' => $maxY,
'stripmeta' => 'true',
'type' => $mimeType,
'norotation' => 'true',
'quality' => $quality,
]
]
];
}

try {
$response = $httpClient->post(
Expand Down