Skip to content

Commit

Permalink
imaginary - allow to generate heif, pdf and svg thumbnails
Browse files Browse the repository at this point in the history
Signed-off-by: Simon L <[email protected]>
  • Loading branch information
szaimen committed Feb 7, 2023
1 parent 2ddd7f5 commit 7c7dd6f
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 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)/';
}

public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop): ?IImage {
Expand All @@ -81,33 +81,48 @@ 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':
$convert = true;
$operations = [
[
'operation' => 'convert',
'params' => [ 'type' => 'png', ]
]
];

break;
default:
$mimeType = 'jpeg';
}

$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,
if (!$convert) {
$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,
]
]
]
];
];
}

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

0 comments on commit 7c7dd6f

Please sign in to comment.