aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Preview/Image.php
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2019-06-04 15:25:25 +0200
committerRobin Appelman <robin@icewind.nl>2019-06-17 14:09:09 +0200
commit615061437422499025e038483504d4ef2004c8e1 (patch)
treebd8752decea5d8c10fea43bdcdd92c38c26ebf30 /lib/private/Preview/Image.php
parentf6ad353c7c1176bcaa167051c9f3e118e69f7a20 (diff)
downloadnextcloud-server-615061437422499025e038483504d4ef2004c8e1.tar.gz
nextcloud-server-615061437422499025e038483504d4ef2004c8e1.zip
Add new Provider interface for preview providers
the main difference is passing the `File` object to the provider instead of a `View` + path Old providers will still continue to work as before Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Preview/Image.php')
-rw-r--r--lib/private/Preview/Image.php33
1 files changed, 13 insertions, 20 deletions
diff --git a/lib/private/Preview/Image.php b/lib/private/Preview/Image.php
index 86ce3bcd071..6f82904a6a7 100644
--- a/lib/private/Preview/Image.php
+++ b/lib/private/Preview/Image.php
@@ -27,44 +27,37 @@
*/
namespace OC\Preview;
-abstract class Image extends Provider {
+use OCP\Files\File;
+use OCP\IImage;
+
+abstract class Image extends ProviderV2 {
/**
* {@inheritDoc}
*/
- public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
- //get fileinfo
- $fileInfo = $fileview->getFileInfo($path);
- if (!$fileInfo) {
- return false;
- }
-
+ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
$maxSizeForImages = \OC::$server->getConfig()->getSystemValue('preview_max_filesize_image', 50);
- $size = $fileInfo->getSize();
+ $size = $file->getSize();
if ($maxSizeForImages !== -1 && $size > ($maxSizeForImages * 1024 * 1024)) {
- return false;
+ return null;
}
$image = new \OC_Image();
- $useTempFile = $fileInfo->isEncrypted() || !$fileInfo->getStorage()->isLocal();
- if ($useTempFile) {
- $fileName = $fileview->toTmpFile($path);
- } else {
- $fileName = $fileview->getLocalFile($path);
- }
+ $fileName = $this->getLocalFile($file);
+
$image->loadFromFile($fileName);
$image->fixOrientation();
- if ($useTempFile) {
- unlink($fileName);
- }
+
+ $this->cleanTmpFiles();
+
if ($image->valid()) {
$image->scaleDownToFit($maxX, $maxY);
return $image;
}
- return false;
+ return null;
}
}