Passed
Push — master ( 335af0...d4a44d )
by Roeland
16:33 queued 10s
created

Image::getThumbnail()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 3
nop 3
dl 0
loc 23
rs 9.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Georg Ehrke <[email protected]>
6
 * @author Joas Schilling <[email protected]>
7
 * @author josh4trunks <[email protected]>
8
 * @author Olivier Paroz <[email protected]>
9
 * @author Robin Appelman <[email protected]>
10
 * @author Thomas Müller <[email protected]>
11
 * @author Thomas Tanghus <[email protected]>
12
 *
13
 * @license AGPL-3.0
14
 *
15
 * This code is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License, version 3,
17
 * as published by the Free Software Foundation.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Affero General Public License, version 3,
25
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
26
 *
27
 */
28
namespace OC\Preview;
29
30
use OCP\Files\File;
31
use OCP\IImage;
32
33
abstract class Image extends ProviderV2 {
34
35
	/**
36
	 * {@inheritDoc}
37
	 */
38
	public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
39
		$maxSizeForImages = \OC::$server->getConfig()->getSystemValue('preview_max_filesize_image', 50);
40
		$size = $file->getSize();
41
42
		if ($maxSizeForImages !== -1 && $size > ($maxSizeForImages * 1024 * 1024)) {
43
			return null;
44
		}
45
46
		$image = new \OC_Image();
47
48
		$fileName = $this->getLocalFile($file);
49
50
		$image->loadFromFile($fileName);
51
		$image->fixOrientation();
52
53
		$this->cleanTmpFiles();
54
55
		if ($image->valid()) {
56
			$image->scaleDownToFit($maxX, $maxY);
57
58
			return $image;
59
		}
60
		return null;
61
	}
62
63
}
64