diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-04-05 11:01:40 +0200 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2020-04-08 16:31:20 +0200 |
commit | 124b109bc8fbe76e7b4ed43b99f36c29022ade97 (patch) | |
tree | 2d8042030e470a094bfb69775a8d204a5354ac40 /lib/private/Preview | |
parent | a2e671c489528a935c7a4e186188f84ea2b3058e (diff) | |
download | nextcloud-server-124b109bc8fbe76e7b4ed43b99f36c29022ade97.tar.gz nextcloud-server-124b109bc8fbe76e7b4ed43b99f36c29022ade97.zip |
Add preview provider for Krita files
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/private/Preview')
-rw-r--r-- | lib/private/Preview/Bundled.php | 6 | ||||
-rw-r--r-- | lib/private/Preview/Krita.php | 52 |
2 files changed, 54 insertions, 4 deletions
diff --git a/lib/private/Preview/Bundled.php b/lib/private/Preview/Bundled.php index 6f3d811ca61..afd286d895b 100644 --- a/lib/private/Preview/Bundled.php +++ b/lib/private/Preview/Bundled.php @@ -23,10 +23,9 @@ namespace OC\Preview; +use OC\Archive\ZIP; use OCP\Files\File; -use OCP\Files\NotPermittedException; use OCP\IImage; -use OCP\Lock\LockedException; /** * Extracts a preview from files that embed them in an ZIP archive @@ -39,10 +38,9 @@ abstract class Bundled extends ProviderV2 { try { $content = $file->fopen('r'); - $content = stream_get_contents($content); file_put_contents($sourceTmp, $content); - $zip = new \OC\Archive\ZIP($sourceTmp); + $zip = new ZIP($sourceTmp); $zip->extractFile($path, $targetTmp); $image = new \OC_Image(); diff --git a/lib/private/Preview/Krita.php b/lib/private/Preview/Krita.php new file mode 100644 index 00000000000..39449145a14 --- /dev/null +++ b/lib/private/Preview/Krita.php @@ -0,0 +1,52 @@ +<?php +/** + * @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\Preview; + +use OCP\Files\File; +use OCP\IImage; + +class Krita extends Bundled { + /** + * {@inheritDoc} + */ + public function getMimeType(): string { + return '/application\/x-krita/'; + } + + + /** + * @inheritDoc + */ + public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { + $image = $this->extractThumbnail($file, 'mergedimage.png'); + if ($image->valid()) { + return $image; + } + $image = $this->extractThumbnail($file, 'preview.png'); + if ($image->valid()) { + return $image; + } + return null; + } +} |