Add preview provider for Krita files

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2020-04-05 11:01:40 +02:00
parent a2e671c489
commit 124b109bc8
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
4 changed files with 62 additions and 7 deletions

View File

@ -989,7 +989,6 @@ $CONFIG = [
* - OC\Preview\MSOffice2003
* - OC\Preview\MSOffice2007
* - OC\Preview\MSOfficeDoc
* - OC\Preview\OpenDocument
* - OC\Preview\PDF
* - OC\Preview\Photoshop
* - OC\Preview\Postscript
@ -1018,6 +1017,8 @@ $CONFIG = [
* - OC\Preview\PNG
* - OC\Preview\TXT
* - OC\Preview\XBitmap
* - OC\Preview\OpenDocument
* - OC\Preview\Krita
*/
'enabledPreviewProviders' => [
'OC\Preview\PNG',
@ -1028,7 +1029,9 @@ $CONFIG = [
'OC\Preview\XBitmap',
'OC\Preview\MP3',
'OC\Preview\TXT',
'OC\Preview\MarkDown'
'OC\Preview\MarkDown',
'OC\Preview\OpenDocument',
'OC\Preview\Krita',
],
/**

View File

@ -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();

View File

@ -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;
}
}

View File

@ -293,7 +293,8 @@ class PreviewManager implements IPreview {
Preview\GIF::class,
Preview\BMP::class,
Preview\HEIC::class,
Preview\XBitmap::class
Preview\XBitmap::class,
Preview\Krita::class,
];
$this->defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', array_merge([
@ -340,6 +341,7 @@ class PreviewManager implements IPreview {
$this->registerCoreProvider(Preview\GIF::class, '/image\/gif/');
$this->registerCoreProvider(Preview\BMP::class, '/image\/bmp/');
$this->registerCoreProvider(Preview\XBitmap::class, '/image\/x-xbitmap/');
$this->registerCoreProvider(Preview\Krita::class, '/application\/x-krita/');
$this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg/');
$this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/');