Completed
Push — master ( 81153d...2a6722 )
by Thomas
52s
created

Image   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 5

2 Methods

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