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

feat(preview): introducing new class ImaginaryPDF #46508

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,13 @@

/**
* Set the URL of the Imaginary service to send image previews to.
* Also requires the ``OC\Preview\Imaginary`` provider to be enabled.
* Also requires the
* - ``OC\Preview\Imaginary``
* provider to be enabled in the 'enabledPreviewProviders' array, to create previews for these mimetypes:
* bmp, x-bitmap, png, jpeg, gif, heic, heif, svg+xml, tiff, webp and illustrator.
* If you want Imaginary to also create preview images from PDF Documents, you have to add
* - ``OC\Preview\ImaginaryPDF``
* provider as well.
*
* See https://github.com/h2non/imaginary
*/
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,7 @@
'OC\\Preview\\Illustrator' => $baseDir . '/lib/private/Preview/Illustrator.php',
'OC\\Preview\\Image' => $baseDir . '/lib/private/Preview/Image.php',
'OC\\Preview\\Imaginary' => $baseDir . '/lib/private/Preview/Imaginary.php',
'OC\\Preview\\ImaginaryPDF' => $baseDir . '/lib/private/Preview/ImaginaryPDF.php',
'OC\\Preview\\JPEG' => $baseDir . '/lib/private/Preview/JPEG.php',
'OC\\Preview\\Krita' => $baseDir . '/lib/private/Preview/Krita.php',
'OC\\Preview\\MP3' => $baseDir . '/lib/private/Preview/MP3.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Preview\\Illustrator' => __DIR__ . '/../../..' . '/lib/private/Preview/Illustrator.php',
'OC\\Preview\\Image' => __DIR__ . '/../../..' . '/lib/private/Preview/Image.php',
'OC\\Preview\\Imaginary' => __DIR__ . '/../../..' . '/lib/private/Preview/Imaginary.php',
'OC\\Preview\\ImaginaryPDF' => __DIR__ . '/../../..' . '/lib/private/Preview/ImaginaryPDF.php',
'OC\\Preview\\JPEG' => __DIR__ . '/../../..' . '/lib/private/Preview/JPEG.php',
'OC\\Preview\\Krita' => __DIR__ . '/../../..' . '/lib/private/Preview/Krita.php',
'OC\\Preview\\MP3' => __DIR__ . '/../../..' . '/lib/private/Preview/MP3.php',
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Preview/Imaginary.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getMimeType(): string {
}

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

Choose a reason for hiding this comment

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

Suggested change
return '/(image\/(bmp|x-bitmap|png|jpeg|gif|heic|heif|svg\+xml|tiff|webp)|application\/illustrator)/';
return '/(image\/(bmp|x-bitmap|png|jpeg|gif|heic|heif|svg\+xml|tiff|webp)/';

}

public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop): ?IImage {
Expand Down
14 changes: 14 additions & 0 deletions lib/private/Preview/ImaginaryPDF.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OC\Preview;

class ImaginaryPDF extends Imaginary {
public static function supportedMimeTypes(): string {
return '/application\/pdf/';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return '/application\/pdf/';
return '/application\/(illustrator|pdf)/';

}
}
1 change: 1 addition & 0 deletions lib/private/PreviewManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ protected function registerCoreProviders() {
$this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg/');
$this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/');
$this->registerCoreProvider(Preview\Imaginary::class, Preview\Imaginary::supportedMimeTypes());
$this->registerCoreProvider(Preview\ImaginaryPDF::class, Preview\ImaginaryPDF::supportedMimeTypes());

// SVG and Bitmap require imagick
if ($this->imagickSupport->hasExtension()) {
Expand Down
Loading