2013-04-25 10:51:44 +00:00
|
|
|
<?php
|
2024-05-23 07:26:56 +00:00
|
|
|
|
2013-04-25 10:51:44 +00:00
|
|
|
/**
|
2024-05-23 07:26:56 +00:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2013-04-25 10:51:44 +00:00
|
|
|
*/
|
2013-05-29 10:33:24 +00:00
|
|
|
namespace OC\Preview;
|
|
|
|
|
2019-06-04 13:25:25 +00:00
|
|
|
use OCP\Files\File;
|
|
|
|
use OCP\IImage;
|
|
|
|
|
|
|
|
abstract class Image extends ProviderV2 {
|
2014-11-28 08:16:35 +00:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2019-06-04 13:25:25 +00:00
|
|
|
public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
|
2021-04-12 20:53:34 +00:00
|
|
|
$maxSizeForImages = \OC::$server->getConfig()->getSystemValueInt('preview_max_filesize_image', 50);
|
2019-06-04 13:25:25 +00:00
|
|
|
$size = $file->getSize();
|
2015-01-18 23:22:55 +00:00
|
|
|
|
|
|
|
if ($maxSizeForImages !== -1 && $size > ($maxSizeForImages * 1024 * 1024)) {
|
2019-06-04 13:25:25 +00:00
|
|
|
return null;
|
2015-01-18 23:22:55 +00:00
|
|
|
}
|
|
|
|
|
2022-06-02 00:37:36 +00:00
|
|
|
$image = new \OCP\Image();
|
2014-05-12 09:27:39 +00:00
|
|
|
|
2019-06-04 13:25:25 +00:00
|
|
|
$fileName = $this->getLocalFile($file);
|
|
|
|
|
2014-05-12 09:27:39 +00:00
|
|
|
$image->loadFromFile($fileName);
|
2016-04-11 12:04:57 +00:00
|
|
|
$image->fixOrientation();
|
2019-06-04 13:25:25 +00:00
|
|
|
|
|
|
|
$this->cleanTmpFiles();
|
|
|
|
|
2015-06-06 14:21:36 +00:00
|
|
|
if ($image->valid()) {
|
|
|
|
$image->scaleDownToFit($maxX, $maxY);
|
2013-05-28 08:21:02 +00:00
|
|
|
|
2015-06-06 14:21:36 +00:00
|
|
|
return $image;
|
|
|
|
}
|
2019-06-04 13:25:25 +00:00
|
|
|
return null;
|
2013-04-25 10:51:44 +00:00
|
|
|
}
|
|
|
|
}
|