Skip to content

Commit c3e3738

Browse files
committed
feat(preview): introducing new class ImaginaryPDF
Signed-off-by: ernolf <[email protected]>
1 parent 4b296c7 commit c3e3738

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

config/config.sample.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,13 @@
12961296

12971297
/**
12981298
* Set the URL of the Imaginary service to send image previews to.
1299-
* Also requires the ``OC\Preview\Imaginary`` provider to be enabled.
1299+
* Also requires the
1300+
* - ``OC\Preview\Imaginary``
1301+
* provider to be enabled in the 'enabledPreviewProviders' array, to create previews for these mimetypes:
1302+
* bmp, x-bitmap, png, jpeg, gif, heic, heif, svg+xml, tiff, webp and illustrator.
1303+
* If you want Imaginary to also create preview images from PDF Documents, you have to add
1304+
* - ``OC\Preview\ImaginaryPDF``
1305+
* provider as well.
13001306
*
13011307
* See https://github.com/h2non/imaginary
13021308
*/

lib/private/Preview/Imaginary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function getMimeType(): string {
4040
}
4141

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

4646
public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop): ?IImage {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
namespace OC\Preview;
9+
10+
class ImaginaryPDF extends Imaginary {
11+
public function getMimeType(): string {
12+
return '/application\/pdf/';
13+
}
14+
}

lib/private/PreviewManager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ protected function registerCoreProviders() {
346346
$this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg/');
347347
$this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/');
348348
$this->registerCoreProvider(Preview\Imaginary::class, Preview\Imaginary::supportedMimeTypes());
349+
$this->registerCoreProvider(Preview\ImaginaryPDF::class, '/application\/pdf/');
349350

350351
// SVG and Bitmap require imagick
351352
if ($this->imagickSupport->hasExtension()) {

0 commit comments

Comments
 (0)