mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
imaginary - allow to generate heif, pdf and svg thumbnails
Signed-off-by: Simon L <szaimen@e.mail.de>
This commit is contained in:
parent
2ddd7f52bf
commit
112d516f27
1 changed files with 45 additions and 18 deletions
|
|
@ -57,7 +57,7 @@ class Imaginary extends ProviderV2 {
|
|||
}
|
||||
|
||||
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 {
|
||||
|
|
@ -81,33 +81,60 @@ class Imaginary extends ProviderV2 {
|
|||
|
||||
$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';
|
||||
}
|
||||
|
||||
$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) {
|
||||
$operations = [
|
||||
[
|
||||
'operation' => 'convert',
|
||||
'params' => [
|
||||
'type' => 'png',
|
||||
]
|
||||
],
|
||||
[
|
||||
'operation' => ($crop ? 'smartcrop' : 'fit'),
|
||||
'params' => [
|
||||
'width' => $maxX,
|
||||
'height' => $maxY,
|
||||
'type' => 'png',
|
||||
'norotation' => 'true',
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
];
|
||||
} 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,
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $httpClient->post(
|
||||
|
|
|
|||
Loading…
Reference in a new issue