Passed
Push — master ( 335af0...d4a44d )
by Roeland
16:33 queued 10s
created
lib/private/Preview/GIF.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@
 block discarded – undo
23 23
 namespace OC\Preview;
24 24
 
25 25
 class GIF extends Image {
26
-	/**
27
-	 * {@inheritDoc}
28
-	 */
29
-	public function getMimeType(): string {
30
-		return '/image\/gif/';
31
-	}
26
+    /**
27
+     * {@inheritDoc}
28
+     */
29
+    public function getMimeType(): string {
30
+        return '/image\/gif/';
31
+    }
32 32
 }
Please login to merge, or discard this patch.
lib/private/Preview/Image.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -32,32 +32,32 @@
 block discarded – undo
32 32
 
33 33
 abstract class Image extends ProviderV2 {
34 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();
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 41
 
42
-		if ($maxSizeForImages !== -1 && $size > ($maxSizeForImages * 1024 * 1024)) {
43
-			return null;
44
-		}
42
+        if ($maxSizeForImages !== -1 && $size > ($maxSizeForImages * 1024 * 1024)) {
43
+            return null;
44
+        }
45 45
 
46
-		$image = new \OC_Image();
46
+        $image = new \OC_Image();
47 47
 
48
-		$fileName = $this->getLocalFile($file);
48
+        $fileName = $this->getLocalFile($file);
49 49
 
50
-		$image->loadFromFile($fileName);
51
-		$image->fixOrientation();
50
+        $image->loadFromFile($fileName);
51
+        $image->fixOrientation();
52 52
 
53
-		$this->cleanTmpFiles();
53
+        $this->cleanTmpFiles();
54 54
 
55
-		if ($image->valid()) {
56
-			$image->scaleDownToFit($maxX, $maxY);
55
+        if ($image->valid()) {
56
+            $image->scaleDownToFit($maxX, $maxY);
57 57
 
58
-			return $image;
59
-		}
60
-		return null;
61
-	}
58
+            return $image;
59
+        }
60
+        return null;
61
+    }
62 62
 
63 63
 }
Please login to merge, or discard this patch.
lib/private/Preview/GeneratorHelper.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -37,47 +37,47 @@
 block discarded – undo
37 37
  */
38 38
 class GeneratorHelper {
39 39
 
40
-	/** @var IRootFolder */
41
-	private $rootFolder;
40
+    /** @var IRootFolder */
41
+    private $rootFolder;
42 42
 
43
-	/** @var IConfig */
44
-	private $config;
43
+    /** @var IConfig */
44
+    private $config;
45 45
 
46
-	public function __construct(IRootFolder $rootFolder, IConfig $config) {
47
-		$this->rootFolder = $rootFolder;
48
-		$this->config = $config;
49
-	}
46
+    public function __construct(IRootFolder $rootFolder, IConfig $config) {
47
+        $this->rootFolder = $rootFolder;
48
+        $this->config = $config;
49
+    }
50 50
 
51
-	/**
52
-	 * @param IProvider $provider
53
-	 * @param File $file
54
-	 * @param int $maxWidth
55
-	 * @param int $maxHeight
56
-	 * @return bool|IImage
57
-	 */
58
-	public function getThumbnail(IProviderV2 $provider, File $file, $maxWidth, $maxHeight) {
59
-		return $provider->getThumbnail($file, $maxWidth, $maxHeight);
60
-	}
51
+    /**
52
+     * @param IProvider $provider
53
+     * @param File $file
54
+     * @param int $maxWidth
55
+     * @param int $maxHeight
56
+     * @return bool|IImage
57
+     */
58
+    public function getThumbnail(IProviderV2 $provider, File $file, $maxWidth, $maxHeight) {
59
+        return $provider->getThumbnail($file, $maxWidth, $maxHeight);
60
+    }
61 61
 
62
-	/**
63
-	 * @param ISimpleFile $maxPreview
64
-	 * @return IImage
65
-	 */
66
-	public function getImage(ISimpleFile $maxPreview) {
67
-		$image = new OCPImage();
68
-		$image->loadFromData($maxPreview->getContent());
69
-		return $image;
70
-	}
62
+    /**
63
+     * @param ISimpleFile $maxPreview
64
+     * @return IImage
65
+     */
66
+    public function getImage(ISimpleFile $maxPreview) {
67
+        $image = new OCPImage();
68
+        $image->loadFromData($maxPreview->getContent());
69
+        return $image;
70
+    }
71 71
 
72
-	/**
73
-	 * @param callable $providerClosure
74
-	 * @return IProviderV2
75
-	 */
76
-	public function getProvider($providerClosure) {
77
-		$provider = $providerClosure();
78
-		if ($provider instanceof IProvider) {
79
-			$provider = new ProviderV1Adapter($provider);
80
-		}
81
-		return $provider;
82
-	}
72
+    /**
73
+     * @param callable $providerClosure
74
+     * @return IProviderV2
75
+     */
76
+    public function getProvider($providerClosure) {
77
+        $provider = $providerClosure();
78
+        if ($provider instanceof IProvider) {
79
+            $provider = new ProviderV1Adapter($provider);
80
+        }
81
+        return $provider;
82
+    }
83 83
 }
Please login to merge, or discard this patch.
lib/private/Preview/SVG.php 2 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -29,50 +29,50 @@
 block discarded – undo
29 29
 use OCP\Files\File;
30 30
 
31 31
 class SVG extends ProviderV2 {
32
-	/**
33
-	 * {@inheritDoc}
34
-	 */
35
-	public function getMimeType(): string {
36
-		return '/image\/svg\+xml/';
37
-	}
32
+    /**
33
+     * {@inheritDoc}
34
+     */
35
+    public function getMimeType(): string {
36
+        return '/image\/svg\+xml/';
37
+    }
38 38
 
39
-	/**
40
-	 * {@inheritDoc}
41
-	 */
42
-	public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
43
-		try {
44
-			$svg = new \Imagick();
45
-			$svg->setBackgroundColor(new \ImagickPixel('transparent'));
39
+    /**
40
+     * {@inheritDoc}
41
+     */
42
+    public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
43
+        try {
44
+            $svg = new \Imagick();
45
+            $svg->setBackgroundColor(new \ImagickPixel('transparent'));
46 46
 
47
-			$content = stream_get_contents($file->fopen('r'));
48
-			if (substr($content, 0, 5) !== '<?xml') {
49
-				$content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
50
-			}
47
+            $content = stream_get_contents($file->fopen('r'));
48
+            if (substr($content, 0, 5) !== '<?xml') {
49
+                $content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
50
+            }
51 51
 
52
-			// Do not parse SVG files with references
53
-			if (stripos($content, 'xlink:href') !== false) {
54
-				return null;
55
-			}
52
+            // Do not parse SVG files with references
53
+            if (stripos($content, 'xlink:href') !== false) {
54
+                return null;
55
+            }
56 56
 
57
-			$svg->readImageBlob($content);
58
-			$svg->setImageFormat('png32');
59
-		} catch (\Exception $e) {
60
-			\OC::$server->getLogger()->logException($e, [
61
-				'level' => ILogger::ERROR,
62
-				'app' => 'core',
63
-			]);
64
-			return null;
65
-		}
57
+            $svg->readImageBlob($content);
58
+            $svg->setImageFormat('png32');
59
+        } catch (\Exception $e) {
60
+            \OC::$server->getLogger()->logException($e, [
61
+                'level' => ILogger::ERROR,
62
+                'app' => 'core',
63
+            ]);
64
+            return null;
65
+        }
66 66
 
67
-		//new image object
68
-		$image = new \OC_Image();
69
-		$image->loadFromData($svg);
70
-		//check if image object is valid
71
-		if ($image->valid()) {
72
-			$image->scaleDownToFit($maxX, $maxY);
67
+        //new image object
68
+        $image = new \OC_Image();
69
+        $image->loadFromData($svg);
70
+        //check if image object is valid
71
+        if ($image->valid()) {
72
+            $image->scaleDownToFit($maxX, $maxY);
73 73
 
74
-			return $image;
75
-		}
76
-		return null;
77
-	}
74
+            return $image;
75
+        }
76
+        return null;
77
+    }
78 78
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@
 block discarded – undo
46 46
 
47 47
 			$content = stream_get_contents($file->fopen('r'));
48 48
 			if (substr($content, 0, 5) !== '<?xml') {
49
-				$content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
49
+				$content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.$content;
50 50
 			}
51 51
 
52 52
 			// Do not parse SVG files with references
Please login to merge, or discard this patch.
lib/private/Preview/XBitmap.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@
 block discarded – undo
23 23
 namespace OC\Preview;
24 24
 
25 25
 class XBitmap extends Image {
26
-	/**
27
-	 * {@inheritDoc}
28
-	 */
29
-	public function getMimeType(): string {
30
-		return '/image\/x-xbitmap/';
31
-	}
26
+    /**
27
+     * {@inheritDoc}
28
+     */
29
+    public function getMimeType(): string {
30
+        return '/image\/x-xbitmap/';
31
+    }
32 32
 }
Please login to merge, or discard this patch.
lib/private/Preview/PNG.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@
 block discarded – undo
23 23
 namespace OC\Preview;
24 24
 
25 25
 class PNG extends Image {
26
-	/**
27
-	 * {@inheritDoc}
28
-	 */
29
-	public function getMimeType(): string {
30
-		return '/image\/png/';
31
-	}
26
+    /**
27
+     * {@inheritDoc}
28
+     */
29
+    public function getMimeType(): string {
30
+        return '/image\/png/';
31
+    }
32 32
 }
Please login to merge, or discard this patch.
lib/private/Preview/HEIC.php 2 patches
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -33,107 +33,107 @@
 block discarded – undo
33 33
  * @package OC\Preview
34 34
  */
35 35
 class HEIC extends ProviderV2 {
36
-	/**
37
-	 * {@inheritDoc}
38
-	 */
39
-	public function getMimeType(): string {
40
-		return '/image\/hei(f|c)/';
41
-	}
42
-
43
-	/**
44
-	 * {@inheritDoc}
45
-	 */
46
-	public function isAvailable(\OCP\Files\FileInfo $file): bool {
47
-		return in_array('HEIC', \Imagick::queryFormats("HEI*"));
48
-	}
49
-
50
-	/**
51
-	 * {@inheritDoc}
52
-	 */
53
-	public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
54
-		$tmpPath = $this->getLocalFile($file);
55
-
56
-		// Creates \Imagick object from the heic file
57
-		try {
58
-			$bp = $this->getResizedPreview($tmpPath, $maxX, $maxY);
59
-			$bp->setFormat('jpg');
60
-		} catch (\Exception $e) {
61
-			\OC::$server->getLogger()->logException($e, [
62
-				'message' => 'File: ' . $file->getPath() . ' Imagick says:',
63
-				'level' => ILogger::ERROR,
64
-				'app' => 'core',
65
-			]);
66
-			return null;
67
-		}
68
-
69
-		$this->cleanTmpFiles();
70
-
71
-		//new bitmap image object
72
-		$image = new \OC_Image();
73
-		$image->loadFromData($bp);
74
-		//check if image object is valid
75
-		return $image->valid() ? $image : null;
76
-	}
77
-
78
-	/**
79
-	 * Returns a preview of maxX times maxY dimensions in JPG format
80
-	 *
81
-	 *    * The default resolution is already 72dpi, no need to change it for a bitmap output
82
-	 *    * It's possible to have proper colour conversion using profileimage().
83
-	 *    ICC profiles are here: http://www.color.org/srgbprofiles.xalter
84
-	 *    * It's possible to Gamma-correct an image via gammaImage()
85
-	 *
86
-	 * @param string $tmpPath the location of the file to convert
87
-	 * @param int $maxX
88
-	 * @param int $maxY
89
-	 *
90
-	 * @return \Imagick
91
-	 */
92
-	private function getResizedPreview($tmpPath, $maxX, $maxY) {
93
-		$bp = new \Imagick();
94
-
95
-		// Layer 0 contains either the bitmap or a flat representation of all vector layers
96
-		$bp->readImage($tmpPath . '[0]');
97
-
98
-		$bp->setImageFormat('jpg');
99
-
100
-		$bp = $this->resize($bp, $maxX, $maxY);
36
+    /**
37
+     * {@inheritDoc}
38
+     */
39
+    public function getMimeType(): string {
40
+        return '/image\/hei(f|c)/';
41
+    }
42
+
43
+    /**
44
+     * {@inheritDoc}
45
+     */
46
+    public function isAvailable(\OCP\Files\FileInfo $file): bool {
47
+        return in_array('HEIC', \Imagick::queryFormats("HEI*"));
48
+    }
49
+
50
+    /**
51
+     * {@inheritDoc}
52
+     */
53
+    public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
54
+        $tmpPath = $this->getLocalFile($file);
55
+
56
+        // Creates \Imagick object from the heic file
57
+        try {
58
+            $bp = $this->getResizedPreview($tmpPath, $maxX, $maxY);
59
+            $bp->setFormat('jpg');
60
+        } catch (\Exception $e) {
61
+            \OC::$server->getLogger()->logException($e, [
62
+                'message' => 'File: ' . $file->getPath() . ' Imagick says:',
63
+                'level' => ILogger::ERROR,
64
+                'app' => 'core',
65
+            ]);
66
+            return null;
67
+        }
68
+
69
+        $this->cleanTmpFiles();
70
+
71
+        //new bitmap image object
72
+        $image = new \OC_Image();
73
+        $image->loadFromData($bp);
74
+        //check if image object is valid
75
+        return $image->valid() ? $image : null;
76
+    }
77
+
78
+    /**
79
+     * Returns a preview of maxX times maxY dimensions in JPG format
80
+     *
81
+     *    * The default resolution is already 72dpi, no need to change it for a bitmap output
82
+     *    * It's possible to have proper colour conversion using profileimage().
83
+     *    ICC profiles are here: http://www.color.org/srgbprofiles.xalter
84
+     *    * It's possible to Gamma-correct an image via gammaImage()
85
+     *
86
+     * @param string $tmpPath the location of the file to convert
87
+     * @param int $maxX
88
+     * @param int $maxY
89
+     *
90
+     * @return \Imagick
91
+     */
92
+    private function getResizedPreview($tmpPath, $maxX, $maxY) {
93
+        $bp = new \Imagick();
94
+
95
+        // Layer 0 contains either the bitmap or a flat representation of all vector layers
96
+        $bp->readImage($tmpPath . '[0]');
97
+
98
+        $bp->setImageFormat('jpg');
99
+
100
+        $bp = $this->resize($bp, $maxX, $maxY);
101 101
 		
102
-		return $bp;
103
-	}
104
-
105
-	/**
106
-	 * Returns a resized \Imagick object
107
-	 *
108
-	 * If you want to know more on the various methods available to resize an
109
-	 * image, check out this link : @link https://stackoverflow.com/questions/8517304/what-the-difference-of-sample-resample-scale-resize-adaptive-resize-thumbnail-im
110
-	 *
111
-	 * @param \Imagick $bp
112
-	 * @param int $maxX
113
-	 * @param int $maxY
114
-	 *
115
-	 * @return \Imagick
116
-	 */
117
-	private function resize($bp, $maxX, $maxY) {
118
-		list($previewWidth, $previewHeight) = array_values($bp->getImageGeometry());
119
-
120
-		// We only need to resize a preview which doesn't fit in the maximum dimensions
121
-		if ($previewWidth > $maxX || $previewHeight > $maxY) {
122
-			// If we want a small image (thumbnail) let's be most space- and time-efficient
123
-			if ($maxX <= 500 && $maxY <= 500) {
124
-				$bp->thumbnailImage($maxY, $maxX, true);
125
-				$bp->stripImage();
126
-			} else {
127
-				// A bigger image calls for some better resizing algorithm
128
-				// According to http://www.imagemagick.org/Usage/filter/#lanczos
129
-				// the catrom filter is almost identical to Lanczos2, but according
130
-				// to http://php.net/manual/en/imagick.resizeimage.php it is
131
-				// significantly faster
132
-				$bp->resizeImage($maxX, $maxY, \Imagick::FILTER_CATROM, 1, true);
133
-			}
134
-		}
135
-
136
-		return $bp;
137
-	}
102
+        return $bp;
103
+    }
104
+
105
+    /**
106
+     * Returns a resized \Imagick object
107
+     *
108
+     * If you want to know more on the various methods available to resize an
109
+     * image, check out this link : @link https://stackoverflow.com/questions/8517304/what-the-difference-of-sample-resample-scale-resize-adaptive-resize-thumbnail-im
110
+     *
111
+     * @param \Imagick $bp
112
+     * @param int $maxX
113
+     * @param int $maxY
114
+     *
115
+     * @return \Imagick
116
+     */
117
+    private function resize($bp, $maxX, $maxY) {
118
+        list($previewWidth, $previewHeight) = array_values($bp->getImageGeometry());
119
+
120
+        // We only need to resize a preview which doesn't fit in the maximum dimensions
121
+        if ($previewWidth > $maxX || $previewHeight > $maxY) {
122
+            // If we want a small image (thumbnail) let's be most space- and time-efficient
123
+            if ($maxX <= 500 && $maxY <= 500) {
124
+                $bp->thumbnailImage($maxY, $maxX, true);
125
+                $bp->stripImage();
126
+            } else {
127
+                // A bigger image calls for some better resizing algorithm
128
+                // According to http://www.imagemagick.org/Usage/filter/#lanczos
129
+                // the catrom filter is almost identical to Lanczos2, but according
130
+                // to http://php.net/manual/en/imagick.resizeimage.php it is
131
+                // significantly faster
132
+                $bp->resizeImage($maxX, $maxY, \Imagick::FILTER_CATROM, 1, true);
133
+            }
134
+        }
135
+
136
+        return $bp;
137
+    }
138 138
 
139 139
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 			$bp->setFormat('jpg');
60 60
 		} catch (\Exception $e) {
61 61
 			\OC::$server->getLogger()->logException($e, [
62
-				'message' => 'File: ' . $file->getPath() . ' Imagick says:',
62
+				'message' => 'File: '.$file->getPath().' Imagick says:',
63 63
 				'level' => ILogger::ERROR,
64 64
 				'app' => 'core',
65 65
 			]);
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		$bp = new \Imagick();
94 94
 
95 95
 		// Layer 0 contains either the bitmap or a flat representation of all vector layers
96
-		$bp->readImage($tmpPath . '[0]');
96
+		$bp->readImage($tmpPath.'[0]');
97 97
 
98 98
 		$bp->setImageFormat('jpg');
99 99
 
Please login to merge, or discard this patch.
lib/private/Preview/MSOffice2003.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@
 block discarded – undo
23 23
 
24 24
 //.docm, .dotm, .xls(m), .xlt(m), .xla(m), .ppt(m), .pot(m), .pps(m), .ppa(m)
25 25
 class MSOffice2003 extends Office {
26
-	/**
27
-	 * {@inheritDoc}
28
-	 */
29
-	public function getMimeType(): string {
30
-		return '/application\/vnd.ms-.*/';
31
-	}
26
+    /**
27
+     * {@inheritDoc}
28
+     */
29
+    public function getMimeType(): string {
30
+        return '/application\/vnd.ms-.*/';
31
+    }
32 32
 }
Please login to merge, or discard this patch.
lib/private/Preview/Bitmap.php 2 patches
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -37,83 +37,83 @@
 block discarded – undo
37 37
  */
38 38
 abstract class Bitmap extends ProviderV2 {
39 39
 
40
-	/**
41
-	 * {@inheritDoc}
42
-	 */
43
-	public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
44
-
45
-		$tmpPath = $this->getLocalFile($file);
46
-
47
-		// Creates \Imagick object from bitmap or vector file
48
-		try {
49
-			$bp = $this->getResizedPreview($tmpPath, $maxX, $maxY);
50
-		} catch (\Exception $e) {
51
-			\OC::$server->getLogger()->logException($e, [
52
-				'message' => 'File: ' . $file->getPath() . ' Imagick says:',
53
-				'level' => ILogger::ERROR,
54
-				'app' => 'core',
55
-			]);
56
-			return null;
57
-		}
58
-
59
-		$this->cleanTmpFiles();
60
-
61
-		//new bitmap image object
62
-		$image = new \OC_Image();
63
-		$image->loadFromData($bp);
64
-		//check if image object is valid
65
-		return $image->valid() ? $image : null;
66
-	}
67
-
68
-	/**
69
-	 * Returns a preview of maxX times maxY dimensions in PNG format
70
-	 *
71
-	 *    * The default resolution is already 72dpi, no need to change it for a bitmap output
72
-	 *    * It's possible to have proper colour conversion using profileimage().
73
-	 *    ICC profiles are here: http://www.color.org/srgbprofiles.xalter
74
-	 *    * It's possible to Gamma-correct an image via gammaImage()
75
-	 *
76
-	 * @param string $tmpPath the location of the file to convert
77
-	 * @param int $maxX
78
-	 * @param int $maxY
79
-	 *
80
-	 * @return \Imagick
81
-	 */
82
-	private function getResizedPreview($tmpPath, $maxX, $maxY) {
83
-		$bp = new Imagick();
84
-
85
-		// Layer 0 contains either the bitmap or a flat representation of all vector layers
86
-		$bp->readImage($tmpPath . '[0]');
87
-
88
-		$bp = $this->resize($bp, $maxX, $maxY);
89
-
90
-		$bp->setImageFormat('png');
91
-
92
-		return $bp;
93
-	}
94
-
95
-	/**
96
-	 * Returns a resized \Imagick object
97
-	 *
98
-	 * If you want to know more on the various methods available to resize an
99
-	 * image, check out this link : @link https://stackoverflow.com/questions/8517304/what-the-difference-of-sample-resample-scale-resize-adaptive-resize-thumbnail-im
100
-	 *
101
-	 * @param \Imagick $bp
102
-	 * @param int $maxX
103
-	 * @param int $maxY
104
-	 *
105
-	 * @return \Imagick
106
-	 */
107
-	private function resize($bp, $maxX, $maxY) {
108
-		list($previewWidth, $previewHeight) = array_values($bp->getImageGeometry());
109
-
110
-		// We only need to resize a preview which doesn't fit in the maximum dimensions
111
-		if ($previewWidth > $maxX || $previewHeight > $maxY) {
112
-			// TODO: LANCZOS is the default filter, CATROM could bring similar results faster
113
-			$bp->resizeImage($maxX, $maxY, imagick::FILTER_LANCZOS, 1, true);
114
-		}
115
-
116
-		return $bp;
117
-	}
40
+    /**
41
+     * {@inheritDoc}
42
+     */
43
+    public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
44
+
45
+        $tmpPath = $this->getLocalFile($file);
46
+
47
+        // Creates \Imagick object from bitmap or vector file
48
+        try {
49
+            $bp = $this->getResizedPreview($tmpPath, $maxX, $maxY);
50
+        } catch (\Exception $e) {
51
+            \OC::$server->getLogger()->logException($e, [
52
+                'message' => 'File: ' . $file->getPath() . ' Imagick says:',
53
+                'level' => ILogger::ERROR,
54
+                'app' => 'core',
55
+            ]);
56
+            return null;
57
+        }
58
+
59
+        $this->cleanTmpFiles();
60
+
61
+        //new bitmap image object
62
+        $image = new \OC_Image();
63
+        $image->loadFromData($bp);
64
+        //check if image object is valid
65
+        return $image->valid() ? $image : null;
66
+    }
67
+
68
+    /**
69
+     * Returns a preview of maxX times maxY dimensions in PNG format
70
+     *
71
+     *    * The default resolution is already 72dpi, no need to change it for a bitmap output
72
+     *    * It's possible to have proper colour conversion using profileimage().
73
+     *    ICC profiles are here: http://www.color.org/srgbprofiles.xalter
74
+     *    * It's possible to Gamma-correct an image via gammaImage()
75
+     *
76
+     * @param string $tmpPath the location of the file to convert
77
+     * @param int $maxX
78
+     * @param int $maxY
79
+     *
80
+     * @return \Imagick
81
+     */
82
+    private function getResizedPreview($tmpPath, $maxX, $maxY) {
83
+        $bp = new Imagick();
84
+
85
+        // Layer 0 contains either the bitmap or a flat representation of all vector layers
86
+        $bp->readImage($tmpPath . '[0]');
87
+
88
+        $bp = $this->resize($bp, $maxX, $maxY);
89
+
90
+        $bp->setImageFormat('png');
91
+
92
+        return $bp;
93
+    }
94
+
95
+    /**
96
+     * Returns a resized \Imagick object
97
+     *
98
+     * If you want to know more on the various methods available to resize an
99
+     * image, check out this link : @link https://stackoverflow.com/questions/8517304/what-the-difference-of-sample-resample-scale-resize-adaptive-resize-thumbnail-im
100
+     *
101
+     * @param \Imagick $bp
102
+     * @param int $maxX
103
+     * @param int $maxY
104
+     *
105
+     * @return \Imagick
106
+     */
107
+    private function resize($bp, $maxX, $maxY) {
108
+        list($previewWidth, $previewHeight) = array_values($bp->getImageGeometry());
109
+
110
+        // We only need to resize a preview which doesn't fit in the maximum dimensions
111
+        if ($previewWidth > $maxX || $previewHeight > $maxY) {
112
+            // TODO: LANCZOS is the default filter, CATROM could bring similar results faster
113
+            $bp->resizeImage($maxX, $maxY, imagick::FILTER_LANCZOS, 1, true);
114
+        }
115
+
116
+        return $bp;
117
+    }
118 118
 
119 119
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 			$bp = $this->getResizedPreview($tmpPath, $maxX, $maxY);
50 50
 		} catch (\Exception $e) {
51 51
 			\OC::$server->getLogger()->logException($e, [
52
-				'message' => 'File: ' . $file->getPath() . ' Imagick says:',
52
+				'message' => 'File: '.$file->getPath().' Imagick says:',
53 53
 				'level' => ILogger::ERROR,
54 54
 				'app' => 'core',
55 55
 			]);
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 		$bp = new Imagick();
84 84
 
85 85
 		// Layer 0 contains either the bitmap or a flat representation of all vector layers
86
-		$bp->readImage($tmpPath . '[0]');
86
+		$bp->readImage($tmpPath.'[0]');
87 87
 
88 88
 		$bp = $this->resize($bp, $maxX, $maxY);
89 89
 
Please login to merge, or discard this patch.