Completed
Pull Request — master (#10036)
by Morris
31:45 queued 05:08
created
lib/private/Preview/Bitmap.php 2 patches
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -35,86 +35,86 @@
 block discarded – undo
35 35
  */
36 36
 abstract class Bitmap extends Provider {
37 37
 
38
-	/**
39
-	 * {@inheritDoc}
40
-	 */
41
-	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
42
-
43
-		$tmpPath = $fileview->toTmpFile($path);
44
-		if (!$tmpPath) {
45
-			return false;
46
-		}
47
-
48
-		// Creates \Imagick object from bitmap or vector file
49
-		try {
50
-			$bp = $this->getResizedPreview($tmpPath, $maxX, $maxY);
51
-		} catch (\Exception $e) {
52
-			\OC::$server->getLogger()->logException($e, [
53
-				'message' => 'File: ' . $fileview->getAbsolutePath($path) . ' Imagick says:',
54
-				'level' => ILogger::ERROR,
55
-				'app' => 'core',
56
-			]);
57
-			return false;
58
-		}
59
-
60
-		unlink($tmpPath);
61
-
62
-		//new bitmap image object
63
-		$image = new \OC_Image();
64
-		$image->loadFromData($bp);
65
-		//check if image object is valid
66
-		return $image->valid() ? $image : false;
67
-	}
68
-
69
-	/**
70
-	 * Returns a preview of maxX times maxY dimensions in PNG format
71
-	 *
72
-	 *    * The default resolution is already 72dpi, no need to change it for a bitmap output
73
-	 *    * It's possible to have proper colour conversion using profileimage().
74
-	 *    ICC profiles are here: http://www.color.org/srgbprofiles.xalter
75
-	 *    * It's possible to Gamma-correct an image via gammaImage()
76
-	 *
77
-	 * @param string $tmpPath the location of the file to convert
78
-	 * @param int $maxX
79
-	 * @param int $maxY
80
-	 *
81
-	 * @return \Imagick
82
-	 */
83
-	private function getResizedPreview($tmpPath, $maxX, $maxY) {
84
-		$bp = new Imagick();
85
-
86
-		// Layer 0 contains either the bitmap or a flat representation of all vector layers
87
-		$bp->readImage($tmpPath . '[0]');
88
-
89
-		$bp = $this->resize($bp, $maxX, $maxY);
90
-
91
-		$bp->setImageFormat('png');
92
-
93
-		return $bp;
94
-	}
95
-
96
-	/**
97
-	 * Returns a resized \Imagick object
98
-	 *
99
-	 * If you want to know more on the various methods available to resize an
100
-	 * image, check out this link : @link https://stackoverflow.com/questions/8517304/what-the-difference-of-sample-resample-scale-resize-adaptive-resize-thumbnail-im
101
-	 *
102
-	 * @param \Imagick $bp
103
-	 * @param int $maxX
104
-	 * @param int $maxY
105
-	 *
106
-	 * @return \Imagick
107
-	 */
108
-	private function resize($bp, $maxX, $maxY) {
109
-		list($previewWidth, $previewHeight) = array_values($bp->getImageGeometry());
110
-
111
-		// We only need to resize a preview which doesn't fit in the maximum dimensions
112
-		if ($previewWidth > $maxX || $previewHeight > $maxY) {
113
-			// TODO: LANCZOS is the default filter, CATROM could bring similar results faster
114
-			$bp->resizeImage($maxX, $maxY, imagick::FILTER_LANCZOS, 1, true);
115
-		}
116
-
117
-		return $bp;
118
-	}
38
+    /**
39
+     * {@inheritDoc}
40
+     */
41
+    public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
42
+
43
+        $tmpPath = $fileview->toTmpFile($path);
44
+        if (!$tmpPath) {
45
+            return false;
46
+        }
47
+
48
+        // Creates \Imagick object from bitmap or vector file
49
+        try {
50
+            $bp = $this->getResizedPreview($tmpPath, $maxX, $maxY);
51
+        } catch (\Exception $e) {
52
+            \OC::$server->getLogger()->logException($e, [
53
+                'message' => 'File: ' . $fileview->getAbsolutePath($path) . ' Imagick says:',
54
+                'level' => ILogger::ERROR,
55
+                'app' => 'core',
56
+            ]);
57
+            return false;
58
+        }
59
+
60
+        unlink($tmpPath);
61
+
62
+        //new bitmap image object
63
+        $image = new \OC_Image();
64
+        $image->loadFromData($bp);
65
+        //check if image object is valid
66
+        return $image->valid() ? $image : false;
67
+    }
68
+
69
+    /**
70
+     * Returns a preview of maxX times maxY dimensions in PNG format
71
+     *
72
+     *    * The default resolution is already 72dpi, no need to change it for a bitmap output
73
+     *    * It's possible to have proper colour conversion using profileimage().
74
+     *    ICC profiles are here: http://www.color.org/srgbprofiles.xalter
75
+     *    * It's possible to Gamma-correct an image via gammaImage()
76
+     *
77
+     * @param string $tmpPath the location of the file to convert
78
+     * @param int $maxX
79
+     * @param int $maxY
80
+     *
81
+     * @return \Imagick
82
+     */
83
+    private function getResizedPreview($tmpPath, $maxX, $maxY) {
84
+        $bp = new Imagick();
85
+
86
+        // Layer 0 contains either the bitmap or a flat representation of all vector layers
87
+        $bp->readImage($tmpPath . '[0]');
88
+
89
+        $bp = $this->resize($bp, $maxX, $maxY);
90
+
91
+        $bp->setImageFormat('png');
92
+
93
+        return $bp;
94
+    }
95
+
96
+    /**
97
+     * Returns a resized \Imagick object
98
+     *
99
+     * If you want to know more on the various methods available to resize an
100
+     * image, check out this link : @link https://stackoverflow.com/questions/8517304/what-the-difference-of-sample-resample-scale-resize-adaptive-resize-thumbnail-im
101
+     *
102
+     * @param \Imagick $bp
103
+     * @param int $maxX
104
+     * @param int $maxY
105
+     *
106
+     * @return \Imagick
107
+     */
108
+    private function resize($bp, $maxX, $maxY) {
109
+        list($previewWidth, $previewHeight) = array_values($bp->getImageGeometry());
110
+
111
+        // We only need to resize a preview which doesn't fit in the maximum dimensions
112
+        if ($previewWidth > $maxX || $previewHeight > $maxY) {
113
+            // TODO: LANCZOS is the default filter, CATROM could bring similar results faster
114
+            $bp->resizeImage($maxX, $maxY, imagick::FILTER_LANCZOS, 1, true);
115
+        }
116
+
117
+        return $bp;
118
+    }
119 119
 
120 120
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 			$bp = $this->getResizedPreview($tmpPath, $maxX, $maxY);
51 51
 		} catch (\Exception $e) {
52 52
 			\OC::$server->getLogger()->logException($e, [
53
-				'message' => 'File: ' . $fileview->getAbsolutePath($path) . ' Imagick says:',
53
+				'message' => 'File: '.$fileview->getAbsolutePath($path).' Imagick says:',
54 54
 				'level' => ILogger::ERROR,
55 55
 				'app' => 'core',
56 56
 			]);
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 		$bp = new Imagick();
85 85
 
86 86
 		// Layer 0 contains either the bitmap or a flat representation of all vector layers
87
-		$bp->readImage($tmpPath . '[0]');
87
+		$bp->readImage($tmpPath.'[0]');
88 88
 
89 89
 		$bp = $this->resize($bp, $maxX, $maxY);
90 90
 
Please login to merge, or discard this patch.