Completed
Pull Request — master (#7600)
by John
18:34
created
lib/public/IImage.php 1 patch
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -29,164 +29,164 @@
 block discarded – undo
29 29
  * @since 8.1.0
30 30
  */
31 31
 interface IImage {
32
-	/**
33
-	 * Determine whether the object contains an image resource.
34
-	 *
35
-	 * @return bool
36
-	 * @since 8.1.0
37
-	 */
38
-	public function valid();
39
-
40
-	/**
41
-	 * Returns the MIME type of the image or an empty string if no image is loaded.
42
-	 *
43
-	 * @return string
44
-	 * @since 8.1.0
45
-	 */
46
-	public function mimeType();
47
-
48
-	/**
49
-	 * Returns the width of the image or -1 if no image is loaded.
50
-	 *
51
-	 * @return int
52
-	 * @since 8.1.0
53
-	 */
54
-	public function width();
55
-
56
-	/**
57
-	 * Returns the height of the image or -1 if no image is loaded.
58
-	 *
59
-	 * @return int
60
-	 * @since 8.1.0
61
-	 */
62
-	public function height();
63
-
64
-	/**
65
-	 * Returns the width when the image orientation is top-left.
66
-	 *
67
-	 * @return int
68
-	 * @since 8.1.0
69
-	 */
70
-	public function widthTopLeft();
71
-
72
-	/**
73
-	 * Returns the height when the image orientation is top-left.
74
-	 *
75
-	 * @return int
76
-	 * @since 8.1.0
77
-	 */
78
-	public function heightTopLeft();
79
-
80
-	/**
81
-	 * Outputs the image.
82
-	 *
83
-	 * @param string $mimeType
84
-	 * @return bool
85
-	 * @since 8.1.0
86
-	 */
87
-	public function show($mimeType = null);
88
-
89
-	/**
90
-	 * Saves the image.
91
-	 *
92
-	 * @param string $filePath
93
-	 * @param string $mimeType
94
-	 * @return bool
95
-	 * @since 8.1.0
96
-	 */
97
-	public function save($filePath = null, $mimeType = null);
98
-
99
-	/**
100
-	 * @return resource Returns the image resource in any.
101
-	 * @since 8.1.0
102
-	 */
103
-	public function resource();
104
-
105
-	/**
106
-	 * @return string Returns the raw data mimetype
107
-	 * @since 13.0.0
108
-	 */
109
-	public function dataMimeType();
110
-
111
-	/**
112
-	 * @return string Returns the raw image data.
113
-	 * @since 8.1.0
114
-	 */
115
-	public function data();
116
-
117
-	/**
118
-	 * (I'm open for suggestions on better method name ;)
119
-	 * Get the orientation based on EXIF data.
120
-	 *
121
-	 * @return int The orientation or -1 if no EXIF data is available.
122
-	 * @since 8.1.0
123
-	 */
124
-	public function getOrientation();
125
-
126
-	/**
127
-	 * (I'm open for suggestions on better method name ;)
128
-	 * Fixes orientation based on EXIF data.
129
-	 *
130
-	 * @return bool
131
-	 * @since 8.1.0
132
-	 */
133
-	public function fixOrientation();
134
-
135
-	/**
136
-	 * Resizes the image preserving ratio.
137
-	 *
138
-	 * @param integer $maxSize The maximum size of either the width or height.
139
-	 * @return bool
140
-	 * @since 8.1.0
141
-	 */
142
-	public function resize($maxSize);
143
-
144
-	/**
145
-	 * @param int $width
146
-	 * @param int $height
147
-	 * @return bool
148
-	 * @since 8.1.0
149
-	 */
150
-	public function preciseResize($width, $height);
151
-
152
-	/**
153
-	 * Crops the image to the middle square. If the image is already square it just returns.
154
-	 *
155
-	 * @param int $size maximum size for the result (optional)
156
-	 * @return bool for success or failure
157
-	 * @since 8.1.0
158
-	 */
159
-	public function centerCrop($size = 0);
160
-
161
-	/**
162
-	 * Crops the image from point $x$y with dimension $wx$h.
163
-	 *
164
-	 * @param int $x Horizontal position
165
-	 * @param int $y Vertical position
166
-	 * @param int $w Width
167
-	 * @param int $h Height
168
-	 * @return bool for success or failure
169
-	 * @since 8.1.0
170
-	 */
171
-	public function crop($x, $y, $w, $h);
172
-
173
-	/**
174
-	 * Resizes the image to fit within a boundary while preserving ratio.
175
-	 *
176
-	 * @param integer $maxWidth
177
-	 * @param integer $maxHeight
178
-	 * @return bool
179
-	 * @since 8.1.0
180
-	 */
181
-	public function fitIn($maxWidth, $maxHeight);
182
-
183
-	/**
184
-	 * Shrinks the image to fit within a boundary while preserving ratio.
185
-	 *
186
-	 * @param integer $maxWidth
187
-	 * @param integer $maxHeight
188
-	 * @return bool
189
-	 * @since 8.1.0
190
-	 */
191
-	public function scaleDownToFit($maxWidth, $maxHeight);
32
+    /**
33
+     * Determine whether the object contains an image resource.
34
+     *
35
+     * @return bool
36
+     * @since 8.1.0
37
+     */
38
+    public function valid();
39
+
40
+    /**
41
+     * Returns the MIME type of the image or an empty string if no image is loaded.
42
+     *
43
+     * @return string
44
+     * @since 8.1.0
45
+     */
46
+    public function mimeType();
47
+
48
+    /**
49
+     * Returns the width of the image or -1 if no image is loaded.
50
+     *
51
+     * @return int
52
+     * @since 8.1.0
53
+     */
54
+    public function width();
55
+
56
+    /**
57
+     * Returns the height of the image or -1 if no image is loaded.
58
+     *
59
+     * @return int
60
+     * @since 8.1.0
61
+     */
62
+    public function height();
63
+
64
+    /**
65
+     * Returns the width when the image orientation is top-left.
66
+     *
67
+     * @return int
68
+     * @since 8.1.0
69
+     */
70
+    public function widthTopLeft();
71
+
72
+    /**
73
+     * Returns the height when the image orientation is top-left.
74
+     *
75
+     * @return int
76
+     * @since 8.1.0
77
+     */
78
+    public function heightTopLeft();
79
+
80
+    /**
81
+     * Outputs the image.
82
+     *
83
+     * @param string $mimeType
84
+     * @return bool
85
+     * @since 8.1.0
86
+     */
87
+    public function show($mimeType = null);
88
+
89
+    /**
90
+     * Saves the image.
91
+     *
92
+     * @param string $filePath
93
+     * @param string $mimeType
94
+     * @return bool
95
+     * @since 8.1.0
96
+     */
97
+    public function save($filePath = null, $mimeType = null);
98
+
99
+    /**
100
+     * @return resource Returns the image resource in any.
101
+     * @since 8.1.0
102
+     */
103
+    public function resource();
104
+
105
+    /**
106
+     * @return string Returns the raw data mimetype
107
+     * @since 13.0.0
108
+     */
109
+    public function dataMimeType();
110
+
111
+    /**
112
+     * @return string Returns the raw image data.
113
+     * @since 8.1.0
114
+     */
115
+    public function data();
116
+
117
+    /**
118
+     * (I'm open for suggestions on better method name ;)
119
+     * Get the orientation based on EXIF data.
120
+     *
121
+     * @return int The orientation or -1 if no EXIF data is available.
122
+     * @since 8.1.0
123
+     */
124
+    public function getOrientation();
125
+
126
+    /**
127
+     * (I'm open for suggestions on better method name ;)
128
+     * Fixes orientation based on EXIF data.
129
+     *
130
+     * @return bool
131
+     * @since 8.1.0
132
+     */
133
+    public function fixOrientation();
134
+
135
+    /**
136
+     * Resizes the image preserving ratio.
137
+     *
138
+     * @param integer $maxSize The maximum size of either the width or height.
139
+     * @return bool
140
+     * @since 8.1.0
141
+     */
142
+    public function resize($maxSize);
143
+
144
+    /**
145
+     * @param int $width
146
+     * @param int $height
147
+     * @return bool
148
+     * @since 8.1.0
149
+     */
150
+    public function preciseResize($width, $height);
151
+
152
+    /**
153
+     * Crops the image to the middle square. If the image is already square it just returns.
154
+     *
155
+     * @param int $size maximum size for the result (optional)
156
+     * @return bool for success or failure
157
+     * @since 8.1.0
158
+     */
159
+    public function centerCrop($size = 0);
160
+
161
+    /**
162
+     * Crops the image from point $x$y with dimension $wx$h.
163
+     *
164
+     * @param int $x Horizontal position
165
+     * @param int $y Vertical position
166
+     * @param int $w Width
167
+     * @param int $h Height
168
+     * @return bool for success or failure
169
+     * @since 8.1.0
170
+     */
171
+    public function crop($x, $y, $w, $h);
172
+
173
+    /**
174
+     * Resizes the image to fit within a boundary while preserving ratio.
175
+     *
176
+     * @param integer $maxWidth
177
+     * @param integer $maxHeight
178
+     * @return bool
179
+     * @since 8.1.0
180
+     */
181
+    public function fitIn($maxWidth, $maxHeight);
182
+
183
+    /**
184
+     * Shrinks the image to fit within a boundary while preserving ratio.
185
+     *
186
+     * @param integer $maxWidth
187
+     * @param integer $maxHeight
188
+     * @return bool
189
+     * @since 8.1.0
190
+     */
191
+    public function scaleDownToFit($maxWidth, $maxHeight);
192 192
 }
Please login to merge, or discard this patch.
lib/private/legacy/image.php 1 patch
Indentation   +1074 added lines, -1074 removed lines patch added patch discarded remove patch
@@ -43,568 +43,568 @@  discard block
 block discarded – undo
43 43
  * Class for basic image manipulation
44 44
  */
45 45
 class OC_Image implements \OCP\IImage {
46
-	/** @var false|resource */
47
-	protected $resource = false; // tmp resource.
48
-	/** @var int */
49
-	protected $imageType = IMAGETYPE_PNG; // Default to png if file type isn't evident.
50
-	/** @var string */
51
-	protected $mimeType = 'image/png'; // Default to png
52
-	/** @var int */
53
-	protected $bitDepth = 24;
54
-	/** @var null|string */
55
-	protected $filePath = null;
56
-	/** @var finfo */
57
-	private $fileInfo;
58
-	/** @var \OCP\ILogger */
59
-	private $logger;
60
-	/** @var \OCP\IConfig */
61
-	private $config;
62
-	/** @var array */
63
-	private $exif;
46
+    /** @var false|resource */
47
+    protected $resource = false; // tmp resource.
48
+    /** @var int */
49
+    protected $imageType = IMAGETYPE_PNG; // Default to png if file type isn't evident.
50
+    /** @var string */
51
+    protected $mimeType = 'image/png'; // Default to png
52
+    /** @var int */
53
+    protected $bitDepth = 24;
54
+    /** @var null|string */
55
+    protected $filePath = null;
56
+    /** @var finfo */
57
+    private $fileInfo;
58
+    /** @var \OCP\ILogger */
59
+    private $logger;
60
+    /** @var \OCP\IConfig */
61
+    private $config;
62
+    /** @var array */
63
+    private $exif;
64 64
 
65
-	/**
66
-	 * Constructor.
67
-	 *
68
-	 * @param resource|string $imageRef The path to a local file, a base64 encoded string or a resource created by
69
-	 * an imagecreate* function.
70
-	 * @param \OCP\ILogger $logger
71
-	 * @param \OCP\IConfig $config
72
-	 */
73
-	public function __construct($imageRef = null, \OCP\ILogger $logger = null, \OCP\IConfig $config = null) {
74
-		$this->logger = $logger;
75
-		if ($logger === null) {
76
-			$this->logger = \OC::$server->getLogger();
77
-		}
78
-		$this->config = $config;
79
-		if ($config === null) {
80
-			$this->config = \OC::$server->getConfig();
81
-		}
65
+    /**
66
+     * Constructor.
67
+     *
68
+     * @param resource|string $imageRef The path to a local file, a base64 encoded string or a resource created by
69
+     * an imagecreate* function.
70
+     * @param \OCP\ILogger $logger
71
+     * @param \OCP\IConfig $config
72
+     */
73
+    public function __construct($imageRef = null, \OCP\ILogger $logger = null, \OCP\IConfig $config = null) {
74
+        $this->logger = $logger;
75
+        if ($logger === null) {
76
+            $this->logger = \OC::$server->getLogger();
77
+        }
78
+        $this->config = $config;
79
+        if ($config === null) {
80
+            $this->config = \OC::$server->getConfig();
81
+        }
82 82
 
83
-		if (\OC_Util::fileInfoLoaded()) {
84
-			$this->fileInfo = new finfo(FILEINFO_MIME_TYPE);
85
-		}
83
+        if (\OC_Util::fileInfoLoaded()) {
84
+            $this->fileInfo = new finfo(FILEINFO_MIME_TYPE);
85
+        }
86 86
 
87
-		if ($imageRef !== null) {
88
-			$this->load($imageRef);
89
-		}
90
-	}
87
+        if ($imageRef !== null) {
88
+            $this->load($imageRef);
89
+        }
90
+    }
91 91
 
92
-	/**
93
-	 * Determine whether the object contains an image resource.
94
-	 *
95
-	 * @return bool
96
-	 */
97
-	public function valid() { // apparently you can't name a method 'empty'...
98
-		return is_resource($this->resource);
99
-	}
92
+    /**
93
+     * Determine whether the object contains an image resource.
94
+     *
95
+     * @return bool
96
+     */
97
+    public function valid() { // apparently you can't name a method 'empty'...
98
+        return is_resource($this->resource);
99
+    }
100 100
 
101
-	/**
102
-	 * Returns the MIME type of the image or an empty string if no image is loaded.
103
-	 *
104
-	 * @return string
105
-	 */
106
-	public function mimeType() {
107
-		return $this->valid() ? $this->mimeType : '';
108
-	}
101
+    /**
102
+     * Returns the MIME type of the image or an empty string if no image is loaded.
103
+     *
104
+     * @return string
105
+     */
106
+    public function mimeType() {
107
+        return $this->valid() ? $this->mimeType : '';
108
+    }
109 109
 
110
-	/**
111
-	 * Returns the width of the image or -1 if no image is loaded.
112
-	 *
113
-	 * @return int
114
-	 */
115
-	public function width() {
116
-		return $this->valid() ? imagesx($this->resource) : -1;
117
-	}
110
+    /**
111
+     * Returns the width of the image or -1 if no image is loaded.
112
+     *
113
+     * @return int
114
+     */
115
+    public function width() {
116
+        return $this->valid() ? imagesx($this->resource) : -1;
117
+    }
118 118
 
119
-	/**
120
-	 * Returns the height of the image or -1 if no image is loaded.
121
-	 *
122
-	 * @return int
123
-	 */
124
-	public function height() {
125
-		return $this->valid() ? imagesy($this->resource) : -1;
126
-	}
119
+    /**
120
+     * Returns the height of the image or -1 if no image is loaded.
121
+     *
122
+     * @return int
123
+     */
124
+    public function height() {
125
+        return $this->valid() ? imagesy($this->resource) : -1;
126
+    }
127 127
 
128
-	/**
129
-	 * Returns the width when the image orientation is top-left.
130
-	 *
131
-	 * @return int
132
-	 */
133
-	public function widthTopLeft() {
134
-		$o = $this->getOrientation();
135
-		$this->logger->debug('OC_Image->widthTopLeft() Orientation: ' . $o, array('app' => 'core'));
136
-		switch ($o) {
137
-			case -1:
138
-			case 1:
139
-			case 2: // Not tested
140
-			case 3:
141
-			case 4: // Not tested
142
-				return $this->width();
143
-			case 5: // Not tested
144
-			case 6:
145
-			case 7: // Not tested
146
-			case 8:
147
-				return $this->height();
148
-		}
149
-		return $this->width();
150
-	}
128
+    /**
129
+     * Returns the width when the image orientation is top-left.
130
+     *
131
+     * @return int
132
+     */
133
+    public function widthTopLeft() {
134
+        $o = $this->getOrientation();
135
+        $this->logger->debug('OC_Image->widthTopLeft() Orientation: ' . $o, array('app' => 'core'));
136
+        switch ($o) {
137
+            case -1:
138
+            case 1:
139
+            case 2: // Not tested
140
+            case 3:
141
+            case 4: // Not tested
142
+                return $this->width();
143
+            case 5: // Not tested
144
+            case 6:
145
+            case 7: // Not tested
146
+            case 8:
147
+                return $this->height();
148
+        }
149
+        return $this->width();
150
+    }
151 151
 
152
-	/**
153
-	 * Returns the height when the image orientation is top-left.
154
-	 *
155
-	 * @return int
156
-	 */
157
-	public function heightTopLeft() {
158
-		$o = $this->getOrientation();
159
-		$this->logger->debug('OC_Image->heightTopLeft() Orientation: ' . $o, array('app' => 'core'));
160
-		switch ($o) {
161
-			case -1:
162
-			case 1:
163
-			case 2: // Not tested
164
-			case 3:
165
-			case 4: // Not tested
166
-				return $this->height();
167
-			case 5: // Not tested
168
-			case 6:
169
-			case 7: // Not tested
170
-			case 8:
171
-				return $this->width();
172
-		}
173
-		return $this->height();
174
-	}
152
+    /**
153
+     * Returns the height when the image orientation is top-left.
154
+     *
155
+     * @return int
156
+     */
157
+    public function heightTopLeft() {
158
+        $o = $this->getOrientation();
159
+        $this->logger->debug('OC_Image->heightTopLeft() Orientation: ' . $o, array('app' => 'core'));
160
+        switch ($o) {
161
+            case -1:
162
+            case 1:
163
+            case 2: // Not tested
164
+            case 3:
165
+            case 4: // Not tested
166
+                return $this->height();
167
+            case 5: // Not tested
168
+            case 6:
169
+            case 7: // Not tested
170
+            case 8:
171
+                return $this->width();
172
+        }
173
+        return $this->height();
174
+    }
175 175
 
176
-	/**
177
-	 * Outputs the image.
178
-	 *
179
-	 * @param string $mimeType
180
-	 * @return bool
181
-	 */
182
-	public function show($mimeType = null) {
183
-		if ($mimeType === null) {
184
-			$mimeType = $this->mimeType();
185
-		}
186
-		header('Content-Type: ' . $mimeType);
187
-		return $this->_output(null, $mimeType);
188
-	}
176
+    /**
177
+     * Outputs the image.
178
+     *
179
+     * @param string $mimeType
180
+     * @return bool
181
+     */
182
+    public function show($mimeType = null) {
183
+        if ($mimeType === null) {
184
+            $mimeType = $this->mimeType();
185
+        }
186
+        header('Content-Type: ' . $mimeType);
187
+        return $this->_output(null, $mimeType);
188
+    }
189 189
 
190
-	/**
191
-	 * Saves the image.
192
-	 *
193
-	 * @param string $filePath
194
-	 * @param string $mimeType
195
-	 * @return bool
196
-	 */
190
+    /**
191
+     * Saves the image.
192
+     *
193
+     * @param string $filePath
194
+     * @param string $mimeType
195
+     * @return bool
196
+     */
197 197
 
198
-	public function save($filePath = null, $mimeType = null) {
199
-		if ($mimeType === null) {
200
-			$mimeType = $this->mimeType();
201
-		}
202
-		if ($filePath === null) {
203
-			if ($this->filePath === null) {
204
-				$this->logger->error(__METHOD__ . '(): called with no path.', array('app' => 'core'));
205
-				return false;
206
-			} else {
207
-				$filePath = $this->filePath;
208
-			}
209
-		}
210
-		return $this->_output($filePath, $mimeType);
211
-	}
198
+    public function save($filePath = null, $mimeType = null) {
199
+        if ($mimeType === null) {
200
+            $mimeType = $this->mimeType();
201
+        }
202
+        if ($filePath === null) {
203
+            if ($this->filePath === null) {
204
+                $this->logger->error(__METHOD__ . '(): called with no path.', array('app' => 'core'));
205
+                return false;
206
+            } else {
207
+                $filePath = $this->filePath;
208
+            }
209
+        }
210
+        return $this->_output($filePath, $mimeType);
211
+    }
212 212
 
213
-	/**
214
-	 * Outputs/saves the image.
215
-	 *
216
-	 * @param string $filePath
217
-	 * @param string $mimeType
218
-	 * @return bool
219
-	 * @throws Exception
220
-	 */
221
-	private function _output($filePath = null, $mimeType = null) {
222
-		if ($filePath) {
223
-			if (!file_exists(dirname($filePath))) {
224
-				mkdir(dirname($filePath), 0777, true);
225
-			}
226
-			$isWritable = is_writable(dirname($filePath));
227
-			if (!$isWritable) {
228
-				$this->logger->error(__METHOD__ . '(): Directory \'' . dirname($filePath) . '\' is not writable.', array('app' => 'core'));
229
-				return false;
230
-			} elseif ($isWritable && file_exists($filePath) && !is_writable($filePath)) {
231
-				$this->logger->error(__METHOD__ . '(): File \'' . $filePath . '\' is not writable.', array('app' => 'core'));
232
-				return false;
233
-			}
234
-		}
235
-		if (!$this->valid()) {
236
-			return false;
237
-		}
213
+    /**
214
+     * Outputs/saves the image.
215
+     *
216
+     * @param string $filePath
217
+     * @param string $mimeType
218
+     * @return bool
219
+     * @throws Exception
220
+     */
221
+    private function _output($filePath = null, $mimeType = null) {
222
+        if ($filePath) {
223
+            if (!file_exists(dirname($filePath))) {
224
+                mkdir(dirname($filePath), 0777, true);
225
+            }
226
+            $isWritable = is_writable(dirname($filePath));
227
+            if (!$isWritable) {
228
+                $this->logger->error(__METHOD__ . '(): Directory \'' . dirname($filePath) . '\' is not writable.', array('app' => 'core'));
229
+                return false;
230
+            } elseif ($isWritable && file_exists($filePath) && !is_writable($filePath)) {
231
+                $this->logger->error(__METHOD__ . '(): File \'' . $filePath . '\' is not writable.', array('app' => 'core'));
232
+                return false;
233
+            }
234
+        }
235
+        if (!$this->valid()) {
236
+            return false;
237
+        }
238 238
 
239
-		$imageType = $this->imageType;
240
-		if ($mimeType !== null) {
241
-			switch ($mimeType) {
242
-				case 'image/gif':
243
-					$imageType = IMAGETYPE_GIF;
244
-					break;
245
-				case 'image/jpeg':
246
-					$imageType = IMAGETYPE_JPEG;
247
-					break;
248
-				case 'image/png':
249
-					$imageType = IMAGETYPE_PNG;
250
-					break;
251
-				case 'image/x-xbitmap':
252
-					$imageType = IMAGETYPE_XBM;
253
-					break;
254
-				case 'image/bmp':
255
-				case 'image/x-ms-bmp':
256
-					$imageType = IMAGETYPE_BMP;
257
-					break;
258
-				default:
259
-					throw new Exception('\OC_Image::_output(): "' . $mimeType . '" is not supported when forcing a specific output format');
260
-			}
261
-		}
239
+        $imageType = $this->imageType;
240
+        if ($mimeType !== null) {
241
+            switch ($mimeType) {
242
+                case 'image/gif':
243
+                    $imageType = IMAGETYPE_GIF;
244
+                    break;
245
+                case 'image/jpeg':
246
+                    $imageType = IMAGETYPE_JPEG;
247
+                    break;
248
+                case 'image/png':
249
+                    $imageType = IMAGETYPE_PNG;
250
+                    break;
251
+                case 'image/x-xbitmap':
252
+                    $imageType = IMAGETYPE_XBM;
253
+                    break;
254
+                case 'image/bmp':
255
+                case 'image/x-ms-bmp':
256
+                    $imageType = IMAGETYPE_BMP;
257
+                    break;
258
+                default:
259
+                    throw new Exception('\OC_Image::_output(): "' . $mimeType . '" is not supported when forcing a specific output format');
260
+            }
261
+        }
262 262
 
263
-		switch ($imageType) {
264
-			case IMAGETYPE_GIF:
265
-				$retVal = imagegif($this->resource, $filePath);
266
-				break;
267
-			case IMAGETYPE_JPEG:
268
-				$retVal = imagejpeg($this->resource, $filePath, $this->getJpegQuality());
269
-				break;
270
-			case IMAGETYPE_PNG:
271
-				$retVal = imagepng($this->resource, $filePath);
272
-				break;
273
-			case IMAGETYPE_XBM:
274
-				if (function_exists('imagexbm')) {
275
-					$retVal = imagexbm($this->resource, $filePath);
276
-				} else {
277
-					throw new Exception('\OC_Image::_output(): imagexbm() is not supported.');
278
-				}
263
+        switch ($imageType) {
264
+            case IMAGETYPE_GIF:
265
+                $retVal = imagegif($this->resource, $filePath);
266
+                break;
267
+            case IMAGETYPE_JPEG:
268
+                $retVal = imagejpeg($this->resource, $filePath, $this->getJpegQuality());
269
+                break;
270
+            case IMAGETYPE_PNG:
271
+                $retVal = imagepng($this->resource, $filePath);
272
+                break;
273
+            case IMAGETYPE_XBM:
274
+                if (function_exists('imagexbm')) {
275
+                    $retVal = imagexbm($this->resource, $filePath);
276
+                } else {
277
+                    throw new Exception('\OC_Image::_output(): imagexbm() is not supported.');
278
+                }
279 279
 
280
-				break;
281
-			case IMAGETYPE_WBMP:
282
-				$retVal = imagewbmp($this->resource, $filePath);
283
-				break;
284
-			case IMAGETYPE_BMP:
285
-				$retVal = imagebmp($this->resource, $filePath, $this->bitDepth);
286
-				break;
287
-			default:
288
-				$retVal = imagepng($this->resource, $filePath);
289
-		}
290
-		return $retVal;
291
-	}
280
+                break;
281
+            case IMAGETYPE_WBMP:
282
+                $retVal = imagewbmp($this->resource, $filePath);
283
+                break;
284
+            case IMAGETYPE_BMP:
285
+                $retVal = imagebmp($this->resource, $filePath, $this->bitDepth);
286
+                break;
287
+            default:
288
+                $retVal = imagepng($this->resource, $filePath);
289
+        }
290
+        return $retVal;
291
+    }
292 292
 
293
-	/**
294
-	 * Prints the image when called as $image().
295
-	 */
296
-	public function __invoke() {
297
-		return $this->show();
298
-	}
293
+    /**
294
+     * Prints the image when called as $image().
295
+     */
296
+    public function __invoke() {
297
+        return $this->show();
298
+    }
299 299
 
300
-	/**
301
-	 * @return resource Returns the image resource in any.
302
-	 */
303
-	public function resource() {
304
-		return $this->resource;
305
-	}
300
+    /**
301
+     * @return resource Returns the image resource in any.
302
+     */
303
+    public function resource() {
304
+        return $this->resource;
305
+    }
306 306
 
307
-	/**
308
-	 * @return string Returns the mimetype of the data. Returns the empty string
309
-	 * if the data is not valid.
310
-	 */
311
-	public function dataMimeType() {
312
-		if (!$this->valid()) {
313
-			return '';
314
-		}
307
+    /**
308
+     * @return string Returns the mimetype of the data. Returns the empty string
309
+     * if the data is not valid.
310
+     */
311
+    public function dataMimeType() {
312
+        if (!$this->valid()) {
313
+            return '';
314
+        }
315 315
 
316
-		switch ($this->mimeType) {
317
-			case 'image/png':
318
-			case 'image/jpeg':
319
-			case 'image/gif':
320
-				return $this->mimeType;
321
-			default:
322
-				return 'image/png';
323
-		}
324
-	}
316
+        switch ($this->mimeType) {
317
+            case 'image/png':
318
+            case 'image/jpeg':
319
+            case 'image/gif':
320
+                return $this->mimeType;
321
+            default:
322
+                return 'image/png';
323
+        }
324
+    }
325 325
 
326
-	/**
327
-	 * @return null|string Returns the raw image data.
328
-	 */
329
-	public function data() {
330
-		if (!$this->valid()) {
331
-			return null;
332
-		}
333
-		ob_start();
334
-		switch ($this->mimeType) {
335
-			case "image/png":
336
-				$res = imagepng($this->resource);
337
-				break;
338
-			case "image/jpeg":
339
-				$quality = $this->getJpegQuality();
340
-				if ($quality !== null) {
341
-					$res = imagejpeg($this->resource, null, $quality);
342
-				} else {
343
-					$res = imagejpeg($this->resource);
344
-				}
345
-				break;
346
-			case "image/gif":
347
-				$res = imagegif($this->resource);
348
-				break;
349
-			default:
350
-				$res = imagepng($this->resource);
351
-				$this->logger->info('OC_Image->data. Could not guess mime-type, defaulting to png', array('app' => 'core'));
352
-				break;
353
-		}
354
-		if (!$res) {
355
-			$this->logger->error('OC_Image->data. Error getting image data.', array('app' => 'core'));
356
-		}
357
-		return ob_get_clean();
358
-	}
326
+    /**
327
+     * @return null|string Returns the raw image data.
328
+     */
329
+    public function data() {
330
+        if (!$this->valid()) {
331
+            return null;
332
+        }
333
+        ob_start();
334
+        switch ($this->mimeType) {
335
+            case "image/png":
336
+                $res = imagepng($this->resource);
337
+                break;
338
+            case "image/jpeg":
339
+                $quality = $this->getJpegQuality();
340
+                if ($quality !== null) {
341
+                    $res = imagejpeg($this->resource, null, $quality);
342
+                } else {
343
+                    $res = imagejpeg($this->resource);
344
+                }
345
+                break;
346
+            case "image/gif":
347
+                $res = imagegif($this->resource);
348
+                break;
349
+            default:
350
+                $res = imagepng($this->resource);
351
+                $this->logger->info('OC_Image->data. Could not guess mime-type, defaulting to png', array('app' => 'core'));
352
+                break;
353
+        }
354
+        if (!$res) {
355
+            $this->logger->error('OC_Image->data. Error getting image data.', array('app' => 'core'));
356
+        }
357
+        return ob_get_clean();
358
+    }
359 359
 
360
-	/**
361
-	 * @return string - base64 encoded, which is suitable for embedding in a VCard.
362
-	 */
363
-	public function __toString() {
364
-		return base64_encode($this->data());
365
-	}
360
+    /**
361
+     * @return string - base64 encoded, which is suitable for embedding in a VCard.
362
+     */
363
+    public function __toString() {
364
+        return base64_encode($this->data());
365
+    }
366 366
 
367
-	/**
368
-	 * @return int|null
369
-	 */
370
-	protected function getJpegQuality() {
371
-		$quality = $this->config->getAppValue('preview', 'jpeg_quality', 90);
372
-		if ($quality !== null) {
373
-			$quality = min(100, max(10, (int) $quality));
374
-		}
375
-		return $quality;
376
-	}
367
+    /**
368
+     * @return int|null
369
+     */
370
+    protected function getJpegQuality() {
371
+        $quality = $this->config->getAppValue('preview', 'jpeg_quality', 90);
372
+        if ($quality !== null) {
373
+            $quality = min(100, max(10, (int) $quality));
374
+        }
375
+        return $quality;
376
+    }
377 377
 
378
-	/**
379
-	 * (I'm open for suggestions on better method name ;)
380
-	 * Get the orientation based on EXIF data.
381
-	 *
382
-	 * @return int The orientation or -1 if no EXIF data is available.
383
-	 */
384
-	public function getOrientation() {
385
-		if ($this->exif !== null) {
386
-			return $this->exif['Orientation'];
387
-		}
378
+    /**
379
+     * (I'm open for suggestions on better method name ;)
380
+     * Get the orientation based on EXIF data.
381
+     *
382
+     * @return int The orientation or -1 if no EXIF data is available.
383
+     */
384
+    public function getOrientation() {
385
+        if ($this->exif !== null) {
386
+            return $this->exif['Orientation'];
387
+        }
388 388
 
389
-		if ($this->imageType !== IMAGETYPE_JPEG) {
390
-			$this->logger->debug('OC_Image->fixOrientation() Image is not a JPEG.', array('app' => 'core'));
391
-			return -1;
392
-		}
393
-		if (!is_callable('exif_read_data')) {
394
-			$this->logger->debug('OC_Image->fixOrientation() Exif module not enabled.', array('app' => 'core'));
395
-			return -1;
396
-		}
397
-		if (!$this->valid()) {
398
-			$this->logger->debug('OC_Image->fixOrientation() No image loaded.', array('app' => 'core'));
399
-			return -1;
400
-		}
401
-		if (is_null($this->filePath) || !is_readable($this->filePath)) {
402
-			$this->logger->debug('OC_Image->fixOrientation() No readable file path set.', array('app' => 'core'));
403
-			return -1;
404
-		}
405
-		$exif = @exif_read_data($this->filePath, 'IFD0');
406
-		if (!$exif) {
407
-			return -1;
408
-		}
409
-		if (!isset($exif['Orientation'])) {
410
-			return -1;
411
-		}
412
-		$this->exif = $exif;
413
-		return $exif['Orientation'];
414
-	}
389
+        if ($this->imageType !== IMAGETYPE_JPEG) {
390
+            $this->logger->debug('OC_Image->fixOrientation() Image is not a JPEG.', array('app' => 'core'));
391
+            return -1;
392
+        }
393
+        if (!is_callable('exif_read_data')) {
394
+            $this->logger->debug('OC_Image->fixOrientation() Exif module not enabled.', array('app' => 'core'));
395
+            return -1;
396
+        }
397
+        if (!$this->valid()) {
398
+            $this->logger->debug('OC_Image->fixOrientation() No image loaded.', array('app' => 'core'));
399
+            return -1;
400
+        }
401
+        if (is_null($this->filePath) || !is_readable($this->filePath)) {
402
+            $this->logger->debug('OC_Image->fixOrientation() No readable file path set.', array('app' => 'core'));
403
+            return -1;
404
+        }
405
+        $exif = @exif_read_data($this->filePath, 'IFD0');
406
+        if (!$exif) {
407
+            return -1;
408
+        }
409
+        if (!isset($exif['Orientation'])) {
410
+            return -1;
411
+        }
412
+        $this->exif = $exif;
413
+        return $exif['Orientation'];
414
+    }
415 415
 
416
-	public function readExif($data) {
417
-		if (!is_callable('exif_read_data')) {
418
-			$this->logger->debug('OC_Image->fixOrientation() Exif module not enabled.', array('app' => 'core'));
419
-			return;
420
-		}
421
-		if (!$this->valid()) {
422
-			$this->logger->debug('OC_Image->fixOrientation() No image loaded.', array('app' => 'core'));
423
-			return;
424
-		}
416
+    public function readExif($data) {
417
+        if (!is_callable('exif_read_data')) {
418
+            $this->logger->debug('OC_Image->fixOrientation() Exif module not enabled.', array('app' => 'core'));
419
+            return;
420
+        }
421
+        if (!$this->valid()) {
422
+            $this->logger->debug('OC_Image->fixOrientation() No image loaded.', array('app' => 'core'));
423
+            return;
424
+        }
425 425
 
426
-		$exif = @exif_read_data('data://image/jpeg;base64,' . base64_encode($data));
427
-		if (!$exif) {
428
-			return;
429
-		}
430
-		if (!isset($exif['Orientation'])) {
431
-			return;
432
-		}
433
-		$this->exif = $exif;
434
-	}
426
+        $exif = @exif_read_data('data://image/jpeg;base64,' . base64_encode($data));
427
+        if (!$exif) {
428
+            return;
429
+        }
430
+        if (!isset($exif['Orientation'])) {
431
+            return;
432
+        }
433
+        $this->exif = $exif;
434
+    }
435 435
 
436
-	/**
437
-	 * (I'm open for suggestions on better method name ;)
438
-	 * Fixes orientation based on EXIF data.
439
-	 *
440
-	 * @return bool
441
-	 */
442
-	public function fixOrientation() {
443
-		$o = $this->getOrientation();
444
-		$this->logger->debug('OC_Image->fixOrientation() Orientation: ' . $o, array('app' => 'core'));
445
-		$rotate = 0;
446
-		$flip = false;
447
-		switch ($o) {
448
-			case -1:
449
-				return false; //Nothing to fix
450
-			case 1:
451
-				$rotate = 0;
452
-				break;
453
-			case 2:
454
-				$rotate = 0;
455
-				$flip = true;
456
-				break;
457
-			case 3:
458
-				$rotate = 180;
459
-				break;
460
-			case 4:
461
-				$rotate = 180;
462
-				$flip = true;
463
-				break;
464
-			case 5:
465
-				$rotate = 90;
466
-				$flip = true;
467
-				break;
468
-			case 6:
469
-				$rotate = 270;
470
-				break;
471
-			case 7:
472
-				$rotate = 270;
473
-				$flip = true;
474
-				break;
475
-			case 8:
476
-				$rotate = 90;
477
-				break;
478
-		}
479
-		if($flip && function_exists('imageflip')) {
480
-			imageflip($this->resource, IMG_FLIP_HORIZONTAL);
481
-		}
482
-		if ($rotate) {
483
-			$res = imagerotate($this->resource, $rotate, 0);
484
-			if ($res) {
485
-				if (imagealphablending($res, true)) {
486
-					if (imagesavealpha($res, true)) {
487
-						imagedestroy($this->resource);
488
-						$this->resource = $res;
489
-						return true;
490
-					} else {
491
-						$this->logger->debug('OC_Image->fixOrientation() Error during alpha-saving', array('app' => 'core'));
492
-						return false;
493
-					}
494
-				} else {
495
-					$this->logger->debug('OC_Image->fixOrientation() Error during alpha-blending', array('app' => 'core'));
496
-					return false;
497
-				}
498
-			} else {
499
-				$this->logger->debug('OC_Image->fixOrientation() Error during orientation fixing', array('app' => 'core'));
500
-				return false;
501
-			}
502
-		}
503
-		return false;
504
-	}
436
+    /**
437
+     * (I'm open for suggestions on better method name ;)
438
+     * Fixes orientation based on EXIF data.
439
+     *
440
+     * @return bool
441
+     */
442
+    public function fixOrientation() {
443
+        $o = $this->getOrientation();
444
+        $this->logger->debug('OC_Image->fixOrientation() Orientation: ' . $o, array('app' => 'core'));
445
+        $rotate = 0;
446
+        $flip = false;
447
+        switch ($o) {
448
+            case -1:
449
+                return false; //Nothing to fix
450
+            case 1:
451
+                $rotate = 0;
452
+                break;
453
+            case 2:
454
+                $rotate = 0;
455
+                $flip = true;
456
+                break;
457
+            case 3:
458
+                $rotate = 180;
459
+                break;
460
+            case 4:
461
+                $rotate = 180;
462
+                $flip = true;
463
+                break;
464
+            case 5:
465
+                $rotate = 90;
466
+                $flip = true;
467
+                break;
468
+            case 6:
469
+                $rotate = 270;
470
+                break;
471
+            case 7:
472
+                $rotate = 270;
473
+                $flip = true;
474
+                break;
475
+            case 8:
476
+                $rotate = 90;
477
+                break;
478
+        }
479
+        if($flip && function_exists('imageflip')) {
480
+            imageflip($this->resource, IMG_FLIP_HORIZONTAL);
481
+        }
482
+        if ($rotate) {
483
+            $res = imagerotate($this->resource, $rotate, 0);
484
+            if ($res) {
485
+                if (imagealphablending($res, true)) {
486
+                    if (imagesavealpha($res, true)) {
487
+                        imagedestroy($this->resource);
488
+                        $this->resource = $res;
489
+                        return true;
490
+                    } else {
491
+                        $this->logger->debug('OC_Image->fixOrientation() Error during alpha-saving', array('app' => 'core'));
492
+                        return false;
493
+                    }
494
+                } else {
495
+                    $this->logger->debug('OC_Image->fixOrientation() Error during alpha-blending', array('app' => 'core'));
496
+                    return false;
497
+                }
498
+            } else {
499
+                $this->logger->debug('OC_Image->fixOrientation() Error during orientation fixing', array('app' => 'core'));
500
+                return false;
501
+            }
502
+        }
503
+        return false;
504
+    }
505 505
 
506
-	/**
507
-	 * Loads an image from a local file, a base64 encoded string or a resource created by an imagecreate* function.
508
-	 *
509
-	 * @param resource|string $imageRef The path to a local file, a base64 encoded string or a resource created by an imagecreate* function or a file resource (file handle    ).
510
-	 * @return resource|false An image resource or false on error
511
-	 */
512
-	public function load($imageRef) {
513
-		if (is_resource($imageRef)) {
514
-			if (get_resource_type($imageRef) === 'gd') {
515
-				$this->resource = $imageRef;
516
-				return $this->resource;
517
-			} elseif (in_array(get_resource_type($imageRef), array('file', 'stream'))) {
518
-				return $this->loadFromFileHandle($imageRef);
519
-			}
520
-		} elseif ($this->loadFromBase64($imageRef) !== false) {
521
-			return $this->resource;
522
-		} elseif ($this->loadFromFile($imageRef) !== false) {
523
-			return $this->resource;
524
-		} elseif ($this->loadFromData($imageRef) !== false) {
525
-			return $this->resource;
526
-		}
527
-		$this->logger->debug(__METHOD__ . '(): could not load anything. Giving up!', array('app' => 'core'));
528
-		return false;
529
-	}
506
+    /**
507
+     * Loads an image from a local file, a base64 encoded string or a resource created by an imagecreate* function.
508
+     *
509
+     * @param resource|string $imageRef The path to a local file, a base64 encoded string or a resource created by an imagecreate* function or a file resource (file handle    ).
510
+     * @return resource|false An image resource or false on error
511
+     */
512
+    public function load($imageRef) {
513
+        if (is_resource($imageRef)) {
514
+            if (get_resource_type($imageRef) === 'gd') {
515
+                $this->resource = $imageRef;
516
+                return $this->resource;
517
+            } elseif (in_array(get_resource_type($imageRef), array('file', 'stream'))) {
518
+                return $this->loadFromFileHandle($imageRef);
519
+            }
520
+        } elseif ($this->loadFromBase64($imageRef) !== false) {
521
+            return $this->resource;
522
+        } elseif ($this->loadFromFile($imageRef) !== false) {
523
+            return $this->resource;
524
+        } elseif ($this->loadFromData($imageRef) !== false) {
525
+            return $this->resource;
526
+        }
527
+        $this->logger->debug(__METHOD__ . '(): could not load anything. Giving up!', array('app' => 'core'));
528
+        return false;
529
+    }
530 530
 
531
-	/**
532
-	 * Loads an image from an open file handle.
533
-	 * It is the responsibility of the caller to position the pointer at the correct place and to close the handle again.
534
-	 *
535
-	 * @param resource $handle
536
-	 * @return resource|false An image resource or false on error
537
-	 */
538
-	public function loadFromFileHandle($handle) {
539
-		$contents = stream_get_contents($handle);
540
-		if ($this->loadFromData($contents)) {
541
-			return $this->resource;
542
-		}
543
-		return false;
544
-	}
531
+    /**
532
+     * Loads an image from an open file handle.
533
+     * It is the responsibility of the caller to position the pointer at the correct place and to close the handle again.
534
+     *
535
+     * @param resource $handle
536
+     * @return resource|false An image resource or false on error
537
+     */
538
+    public function loadFromFileHandle($handle) {
539
+        $contents = stream_get_contents($handle);
540
+        if ($this->loadFromData($contents)) {
541
+            return $this->resource;
542
+        }
543
+        return false;
544
+    }
545 545
 
546
-	/**
547
-	 * Loads an image from a local file.
548
-	 *
549
-	 * @param bool|string $imagePath The path to a local file.
550
-	 * @return bool|resource An image resource or false on error
551
-	 */
552
-	public function loadFromFile($imagePath = false) {
553
-		// exif_imagetype throws "read error!" if file is less than 12 byte
554
-		if (!@is_file($imagePath) || !file_exists($imagePath) || filesize($imagePath) < 12 || !is_readable($imagePath)) {
555
-			return false;
556
-		}
557
-		$iType = exif_imagetype($imagePath);
558
-		switch ($iType) {
559
-			case IMAGETYPE_GIF:
560
-				if (imagetypes() & IMG_GIF) {
561
-					$this->resource = imagecreatefromgif($imagePath);
562
-					// Preserve transparency
563
-					imagealphablending($this->resource, true);
564
-					imagesavealpha($this->resource, true);
565
-				} else {
566
-					$this->logger->debug('OC_Image->loadFromFile, GIF images not supported: ' . $imagePath, array('app' => 'core'));
567
-				}
568
-				break;
569
-			case IMAGETYPE_JPEG:
570
-				if (imagetypes() & IMG_JPG) {
571
-					if (getimagesize($imagePath) !== false) {
572
-						$this->resource = @imagecreatefromjpeg($imagePath);
573
-					} else {
574
-						$this->logger->debug('OC_Image->loadFromFile, JPG image not valid: ' . $imagePath, array('app' => 'core'));
575
-					}
576
-				} else {
577
-					$this->logger->debug('OC_Image->loadFromFile, JPG images not supported: ' . $imagePath, array('app' => 'core'));
578
-				}
579
-				break;
580
-			case IMAGETYPE_PNG:
581
-				if (imagetypes() & IMG_PNG) {
582
-					$this->resource = @imagecreatefrompng($imagePath);
583
-					// Preserve transparency
584
-					imagealphablending($this->resource, true);
585
-					imagesavealpha($this->resource, true);
586
-				} else {
587
-					$this->logger->debug('OC_Image->loadFromFile, PNG images not supported: ' . $imagePath, array('app' => 'core'));
588
-				}
589
-				break;
590
-			case IMAGETYPE_XBM:
591
-				if (imagetypes() & IMG_XPM) {
592
-					$this->resource = @imagecreatefromxbm($imagePath);
593
-				} else {
594
-					$this->logger->debug('OC_Image->loadFromFile, XBM/XPM images not supported: ' . $imagePath, array('app' => 'core'));
595
-				}
596
-				break;
597
-			case IMAGETYPE_WBMP:
598
-				if (imagetypes() & IMG_WBMP) {
599
-					$this->resource = @imagecreatefromwbmp($imagePath);
600
-				} else {
601
-					$this->logger->debug('OC_Image->loadFromFile, WBMP images not supported: ' . $imagePath, array('app' => 'core'));
602
-				}
603
-				break;
604
-			case IMAGETYPE_BMP:
605
-				$this->resource = $this->imagecreatefrombmp($imagePath);
606
-				break;
607
-			/*
546
+    /**
547
+     * Loads an image from a local file.
548
+     *
549
+     * @param bool|string $imagePath The path to a local file.
550
+     * @return bool|resource An image resource or false on error
551
+     */
552
+    public function loadFromFile($imagePath = false) {
553
+        // exif_imagetype throws "read error!" if file is less than 12 byte
554
+        if (!@is_file($imagePath) || !file_exists($imagePath) || filesize($imagePath) < 12 || !is_readable($imagePath)) {
555
+            return false;
556
+        }
557
+        $iType = exif_imagetype($imagePath);
558
+        switch ($iType) {
559
+            case IMAGETYPE_GIF:
560
+                if (imagetypes() & IMG_GIF) {
561
+                    $this->resource = imagecreatefromgif($imagePath);
562
+                    // Preserve transparency
563
+                    imagealphablending($this->resource, true);
564
+                    imagesavealpha($this->resource, true);
565
+                } else {
566
+                    $this->logger->debug('OC_Image->loadFromFile, GIF images not supported: ' . $imagePath, array('app' => 'core'));
567
+                }
568
+                break;
569
+            case IMAGETYPE_JPEG:
570
+                if (imagetypes() & IMG_JPG) {
571
+                    if (getimagesize($imagePath) !== false) {
572
+                        $this->resource = @imagecreatefromjpeg($imagePath);
573
+                    } else {
574
+                        $this->logger->debug('OC_Image->loadFromFile, JPG image not valid: ' . $imagePath, array('app' => 'core'));
575
+                    }
576
+                } else {
577
+                    $this->logger->debug('OC_Image->loadFromFile, JPG images not supported: ' . $imagePath, array('app' => 'core'));
578
+                }
579
+                break;
580
+            case IMAGETYPE_PNG:
581
+                if (imagetypes() & IMG_PNG) {
582
+                    $this->resource = @imagecreatefrompng($imagePath);
583
+                    // Preserve transparency
584
+                    imagealphablending($this->resource, true);
585
+                    imagesavealpha($this->resource, true);
586
+                } else {
587
+                    $this->logger->debug('OC_Image->loadFromFile, PNG images not supported: ' . $imagePath, array('app' => 'core'));
588
+                }
589
+                break;
590
+            case IMAGETYPE_XBM:
591
+                if (imagetypes() & IMG_XPM) {
592
+                    $this->resource = @imagecreatefromxbm($imagePath);
593
+                } else {
594
+                    $this->logger->debug('OC_Image->loadFromFile, XBM/XPM images not supported: ' . $imagePath, array('app' => 'core'));
595
+                }
596
+                break;
597
+            case IMAGETYPE_WBMP:
598
+                if (imagetypes() & IMG_WBMP) {
599
+                    $this->resource = @imagecreatefromwbmp($imagePath);
600
+                } else {
601
+                    $this->logger->debug('OC_Image->loadFromFile, WBMP images not supported: ' . $imagePath, array('app' => 'core'));
602
+                }
603
+                break;
604
+            case IMAGETYPE_BMP:
605
+                $this->resource = $this->imagecreatefrombmp($imagePath);
606
+                break;
607
+            /*
608 608
 			case IMAGETYPE_TIFF_II: // (intel byte order)
609 609
 				break;
610 610
 			case IMAGETYPE_TIFF_MM: // (motorola byte order)
@@ -628,581 +628,581 @@  discard block
 block discarded – undo
628 628
 			case IMAGETYPE_PSD:
629 629
 				break;
630 630
 			*/
631
-			default:
631
+            default:
632 632
 
633
-				// this is mostly file created from encrypted file
634
-				$this->resource = imagecreatefromstring(\OC\Files\Filesystem::file_get_contents(\OC\Files\Filesystem::getLocalPath($imagePath)));
635
-				$iType = IMAGETYPE_PNG;
636
-				$this->logger->debug('OC_Image->loadFromFile, Default', array('app' => 'core'));
637
-				break;
638
-		}
639
-		if ($this->valid()) {
640
-			$this->imageType = $iType;
641
-			$this->mimeType = image_type_to_mime_type($iType);
642
-			$this->filePath = $imagePath;
643
-		}
644
-		return $this->resource;
645
-	}
633
+                // this is mostly file created from encrypted file
634
+                $this->resource = imagecreatefromstring(\OC\Files\Filesystem::file_get_contents(\OC\Files\Filesystem::getLocalPath($imagePath)));
635
+                $iType = IMAGETYPE_PNG;
636
+                $this->logger->debug('OC_Image->loadFromFile, Default', array('app' => 'core'));
637
+                break;
638
+        }
639
+        if ($this->valid()) {
640
+            $this->imageType = $iType;
641
+            $this->mimeType = image_type_to_mime_type($iType);
642
+            $this->filePath = $imagePath;
643
+        }
644
+        return $this->resource;
645
+    }
646 646
 
647
-	/**
648
-	 * Loads an image from a string of data.
649
-	 *
650
-	 * @param string $str A string of image data as read from a file.
651
-	 * @return bool|resource An image resource or false on error
652
-	 */
653
-	public function loadFromData($str) {
654
-		if (is_resource($str)) {
655
-			return false;
656
-		}
657
-		$this->resource = @imagecreatefromstring($str);
658
-		if ($this->fileInfo) {
659
-			$this->mimeType = $this->fileInfo->buffer($str);
660
-		}
661
-		if (is_resource($this->resource)) {
662
-			imagealphablending($this->resource, false);
663
-			imagesavealpha($this->resource, true);
664
-		}
647
+    /**
648
+     * Loads an image from a string of data.
649
+     *
650
+     * @param string $str A string of image data as read from a file.
651
+     * @return bool|resource An image resource or false on error
652
+     */
653
+    public function loadFromData($str) {
654
+        if (is_resource($str)) {
655
+            return false;
656
+        }
657
+        $this->resource = @imagecreatefromstring($str);
658
+        if ($this->fileInfo) {
659
+            $this->mimeType = $this->fileInfo->buffer($str);
660
+        }
661
+        if (is_resource($this->resource)) {
662
+            imagealphablending($this->resource, false);
663
+            imagesavealpha($this->resource, true);
664
+        }
665 665
 
666
-		if (!$this->resource) {
667
-			$this->logger->debug('OC_Image->loadFromFile, could not load', array('app' => 'core'));
668
-			return false;
669
-		}
670
-		return $this->resource;
671
-	}
666
+        if (!$this->resource) {
667
+            $this->logger->debug('OC_Image->loadFromFile, could not load', array('app' => 'core'));
668
+            return false;
669
+        }
670
+        return $this->resource;
671
+    }
672 672
 
673
-	/**
674
-	 * Loads an image from a base64 encoded string.
675
-	 *
676
-	 * @param string $str A string base64 encoded string of image data.
677
-	 * @return bool|resource An image resource or false on error
678
-	 */
679
-	public function loadFromBase64($str) {
680
-		if (!is_string($str)) {
681
-			return false;
682
-		}
683
-		$data = base64_decode($str);
684
-		if ($data) { // try to load from string data
685
-			$this->resource = @imagecreatefromstring($data);
686
-			if ($this->fileInfo) {
687
-				$this->mimeType = $this->fileInfo->buffer($data);
688
-			}
689
-			if (!$this->resource) {
690
-				$this->logger->debug('OC_Image->loadFromBase64, could not load', array('app' => 'core'));
691
-				return false;
692
-			}
693
-			return $this->resource;
694
-		} else {
695
-			return false;
696
-		}
697
-	}
673
+    /**
674
+     * Loads an image from a base64 encoded string.
675
+     *
676
+     * @param string $str A string base64 encoded string of image data.
677
+     * @return bool|resource An image resource or false on error
678
+     */
679
+    public function loadFromBase64($str) {
680
+        if (!is_string($str)) {
681
+            return false;
682
+        }
683
+        $data = base64_decode($str);
684
+        if ($data) { // try to load from string data
685
+            $this->resource = @imagecreatefromstring($data);
686
+            if ($this->fileInfo) {
687
+                $this->mimeType = $this->fileInfo->buffer($data);
688
+            }
689
+            if (!$this->resource) {
690
+                $this->logger->debug('OC_Image->loadFromBase64, could not load', array('app' => 'core'));
691
+                return false;
692
+            }
693
+            return $this->resource;
694
+        } else {
695
+            return false;
696
+        }
697
+    }
698 698
 
699
-	/**
700
-	 * Create a new image from file or URL
701
-	 *
702
-	 * @link http://www.programmierer-forum.de/function-imagecreatefrombmp-laeuft-mit-allen-bitraten-t143137.htm
703
-	 * @version 1.00
704
-	 * @param string $fileName <p>
705
-	 * Path to the BMP image.
706
-	 * </p>
707
-	 * @return bool|resource an image resource identifier on success, <b>FALSE</b> on errors.
708
-	 */
709
-	private function imagecreatefrombmp($fileName) {
710
-		if (!($fh = fopen($fileName, 'rb'))) {
711
-			$this->logger->warning('imagecreatefrombmp: Can not open ' . $fileName, array('app' => 'core'));
712
-			return false;
713
-		}
714
-		// read file header
715
-		$meta = unpack('vtype/Vfilesize/Vreserved/Voffset', fread($fh, 14));
716
-		// check for bitmap
717
-		if ($meta['type'] != 19778) {
718
-			fclose($fh);
719
-			$this->logger->warning('imagecreatefrombmp: Can not open ' . $fileName . ' is not a bitmap!', array('app' => 'core'));
720
-			return false;
721
-		}
722
-		// read image header
723
-		$meta += unpack('Vheadersize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vcolors/Vimportant', fread($fh, 40));
724
-		// read additional 16bit header
725
-		if ($meta['bits'] == 16) {
726
-			$meta += unpack('VrMask/VgMask/VbMask', fread($fh, 12));
727
-		}
728
-		// set bytes and padding
729
-		$meta['bytes'] = $meta['bits'] / 8;
730
-		$this->bitDepth = $meta['bits']; //remember the bit depth for the imagebmp call
731
-		$meta['decal'] = 4 - (4 * (($meta['width'] * $meta['bytes'] / 4) - floor($meta['width'] * $meta['bytes'] / 4)));
732
-		if ($meta['decal'] == 4) {
733
-			$meta['decal'] = 0;
734
-		}
735
-		// obtain imagesize
736
-		if ($meta['imagesize'] < 1) {
737
-			$meta['imagesize'] = $meta['filesize'] - $meta['offset'];
738
-			// in rare cases filesize is equal to offset so we need to read physical size
739
-			if ($meta['imagesize'] < 1) {
740
-				$meta['imagesize'] = @filesize($fileName) - $meta['offset'];
741
-				if ($meta['imagesize'] < 1) {
742
-					fclose($fh);
743
-					$this->logger->warning('imagecreatefrombmp: Can not obtain file size of ' . $fileName . ' is not a bitmap!', array('app' => 'core'));
744
-					return false;
745
-				}
746
-			}
747
-		}
748
-		// calculate colors
749
-		$meta['colors'] = !$meta['colors'] ? pow(2, $meta['bits']) : $meta['colors'];
750
-		// read color palette
751
-		$palette = array();
752
-		if ($meta['bits'] < 16) {
753
-			$palette = unpack('l' . $meta['colors'], fread($fh, $meta['colors'] * 4));
754
-			// in rare cases the color value is signed
755
-			if ($palette[1] < 0) {
756
-				foreach ($palette as $i => $color) {
757
-					$palette[$i] = $color + 16777216;
758
-				}
759
-			}
760
-		}
761
-		// create gd image
762
-		$im = imagecreatetruecolor($meta['width'], $meta['height']);
763
-		if ($im == false) {
764
-			fclose($fh);
765
-			$this->logger->warning(
766
-				'imagecreatefrombmp: imagecreatetruecolor failed for file "' . $fileName . '" with dimensions ' . $meta['width'] . 'x' . $meta['height'],
767
-				array('app' => 'core'));
768
-			return false;
769
-		}
699
+    /**
700
+     * Create a new image from file or URL
701
+     *
702
+     * @link http://www.programmierer-forum.de/function-imagecreatefrombmp-laeuft-mit-allen-bitraten-t143137.htm
703
+     * @version 1.00
704
+     * @param string $fileName <p>
705
+     * Path to the BMP image.
706
+     * </p>
707
+     * @return bool|resource an image resource identifier on success, <b>FALSE</b> on errors.
708
+     */
709
+    private function imagecreatefrombmp($fileName) {
710
+        if (!($fh = fopen($fileName, 'rb'))) {
711
+            $this->logger->warning('imagecreatefrombmp: Can not open ' . $fileName, array('app' => 'core'));
712
+            return false;
713
+        }
714
+        // read file header
715
+        $meta = unpack('vtype/Vfilesize/Vreserved/Voffset', fread($fh, 14));
716
+        // check for bitmap
717
+        if ($meta['type'] != 19778) {
718
+            fclose($fh);
719
+            $this->logger->warning('imagecreatefrombmp: Can not open ' . $fileName . ' is not a bitmap!', array('app' => 'core'));
720
+            return false;
721
+        }
722
+        // read image header
723
+        $meta += unpack('Vheadersize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vcolors/Vimportant', fread($fh, 40));
724
+        // read additional 16bit header
725
+        if ($meta['bits'] == 16) {
726
+            $meta += unpack('VrMask/VgMask/VbMask', fread($fh, 12));
727
+        }
728
+        // set bytes and padding
729
+        $meta['bytes'] = $meta['bits'] / 8;
730
+        $this->bitDepth = $meta['bits']; //remember the bit depth for the imagebmp call
731
+        $meta['decal'] = 4 - (4 * (($meta['width'] * $meta['bytes'] / 4) - floor($meta['width'] * $meta['bytes'] / 4)));
732
+        if ($meta['decal'] == 4) {
733
+            $meta['decal'] = 0;
734
+        }
735
+        // obtain imagesize
736
+        if ($meta['imagesize'] < 1) {
737
+            $meta['imagesize'] = $meta['filesize'] - $meta['offset'];
738
+            // in rare cases filesize is equal to offset so we need to read physical size
739
+            if ($meta['imagesize'] < 1) {
740
+                $meta['imagesize'] = @filesize($fileName) - $meta['offset'];
741
+                if ($meta['imagesize'] < 1) {
742
+                    fclose($fh);
743
+                    $this->logger->warning('imagecreatefrombmp: Can not obtain file size of ' . $fileName . ' is not a bitmap!', array('app' => 'core'));
744
+                    return false;
745
+                }
746
+            }
747
+        }
748
+        // calculate colors
749
+        $meta['colors'] = !$meta['colors'] ? pow(2, $meta['bits']) : $meta['colors'];
750
+        // read color palette
751
+        $palette = array();
752
+        if ($meta['bits'] < 16) {
753
+            $palette = unpack('l' . $meta['colors'], fread($fh, $meta['colors'] * 4));
754
+            // in rare cases the color value is signed
755
+            if ($palette[1] < 0) {
756
+                foreach ($palette as $i => $color) {
757
+                    $palette[$i] = $color + 16777216;
758
+                }
759
+            }
760
+        }
761
+        // create gd image
762
+        $im = imagecreatetruecolor($meta['width'], $meta['height']);
763
+        if ($im == false) {
764
+            fclose($fh);
765
+            $this->logger->warning(
766
+                'imagecreatefrombmp: imagecreatetruecolor failed for file "' . $fileName . '" with dimensions ' . $meta['width'] . 'x' . $meta['height'],
767
+                array('app' => 'core'));
768
+            return false;
769
+        }
770 770
 
771
-		$data = fread($fh, $meta['imagesize']);
772
-		$p = 0;
773
-		$vide = chr(0);
774
-		$y = $meta['height'] - 1;
775
-		$error = 'imagecreatefrombmp: ' . $fileName . ' has not enough data!';
776
-		// loop through the image data beginning with the lower left corner
777
-		while ($y >= 0) {
778
-			$x = 0;
779
-			while ($x < $meta['width']) {
780
-				switch ($meta['bits']) {
781
-					case 32:
782
-					case 24:
783
-						if (!($part = substr($data, $p, 3))) {
784
-							$this->logger->warning($error, array('app' => 'core'));
785
-							return $im;
786
-						}
787
-						$color = @unpack('V', $part . $vide);
788
-						break;
789
-					case 16:
790
-						if (!($part = substr($data, $p, 2))) {
791
-							fclose($fh);
792
-							$this->logger->warning($error, array('app' => 'core'));
793
-							return $im;
794
-						}
795
-						$color = @unpack('v', $part);
796
-						$color[1] = (($color[1] & 0xf800) >> 8) * 65536 + (($color[1] & 0x07e0) >> 3) * 256 + (($color[1] & 0x001f) << 3);
797
-						break;
798
-					case 8:
799
-						$color = @unpack('n', $vide . substr($data, $p, 1));
800
-						$color[1] = (isset($palette[$color[1] + 1])) ? $palette[$color[1] + 1] : $palette[1];
801
-						break;
802
-					case 4:
803
-						$color = @unpack('n', $vide . substr($data, floor($p), 1));
804
-						$color[1] = ($p * 2) % 2 == 0 ? $color[1] >> 4 : $color[1] & 0x0F;
805
-						$color[1] = (isset($palette[$color[1] + 1])) ? $palette[$color[1] + 1] : $palette[1];
806
-						break;
807
-					case 1:
808
-						$color = @unpack('n', $vide . substr($data, floor($p), 1));
809
-						switch (($p * 8) % 8) {
810
-							case 0:
811
-								$color[1] = $color[1] >> 7;
812
-								break;
813
-							case 1:
814
-								$color[1] = ($color[1] & 0x40) >> 6;
815
-								break;
816
-							case 2:
817
-								$color[1] = ($color[1] & 0x20) >> 5;
818
-								break;
819
-							case 3:
820
-								$color[1] = ($color[1] & 0x10) >> 4;
821
-								break;
822
-							case 4:
823
-								$color[1] = ($color[1] & 0x8) >> 3;
824
-								break;
825
-							case 5:
826
-								$color[1] = ($color[1] & 0x4) >> 2;
827
-								break;
828
-							case 6:
829
-								$color[1] = ($color[1] & 0x2) >> 1;
830
-								break;
831
-							case 7:
832
-								$color[1] = ($color[1] & 0x1);
833
-								break;
834
-						}
835
-						$color[1] = (isset($palette[$color[1] + 1])) ? $palette[$color[1] + 1] : $palette[1];
836
-						break;
837
-					default:
838
-						fclose($fh);
839
-						$this->logger->warning('imagecreatefrombmp: ' . $fileName . ' has ' . $meta['bits'] . ' bits and this is not supported!', array('app' => 'core'));
840
-						return false;
841
-				}
842
-				imagesetpixel($im, $x, $y, $color[1]);
843
-				$x++;
844
-				$p += $meta['bytes'];
845
-			}
846
-			$y--;
847
-			$p += $meta['decal'];
848
-		}
849
-		fclose($fh);
850
-		return $im;
851
-	}
771
+        $data = fread($fh, $meta['imagesize']);
772
+        $p = 0;
773
+        $vide = chr(0);
774
+        $y = $meta['height'] - 1;
775
+        $error = 'imagecreatefrombmp: ' . $fileName . ' has not enough data!';
776
+        // loop through the image data beginning with the lower left corner
777
+        while ($y >= 0) {
778
+            $x = 0;
779
+            while ($x < $meta['width']) {
780
+                switch ($meta['bits']) {
781
+                    case 32:
782
+                    case 24:
783
+                        if (!($part = substr($data, $p, 3))) {
784
+                            $this->logger->warning($error, array('app' => 'core'));
785
+                            return $im;
786
+                        }
787
+                        $color = @unpack('V', $part . $vide);
788
+                        break;
789
+                    case 16:
790
+                        if (!($part = substr($data, $p, 2))) {
791
+                            fclose($fh);
792
+                            $this->logger->warning($error, array('app' => 'core'));
793
+                            return $im;
794
+                        }
795
+                        $color = @unpack('v', $part);
796
+                        $color[1] = (($color[1] & 0xf800) >> 8) * 65536 + (($color[1] & 0x07e0) >> 3) * 256 + (($color[1] & 0x001f) << 3);
797
+                        break;
798
+                    case 8:
799
+                        $color = @unpack('n', $vide . substr($data, $p, 1));
800
+                        $color[1] = (isset($palette[$color[1] + 1])) ? $palette[$color[1] + 1] : $palette[1];
801
+                        break;
802
+                    case 4:
803
+                        $color = @unpack('n', $vide . substr($data, floor($p), 1));
804
+                        $color[1] = ($p * 2) % 2 == 0 ? $color[1] >> 4 : $color[1] & 0x0F;
805
+                        $color[1] = (isset($palette[$color[1] + 1])) ? $palette[$color[1] + 1] : $palette[1];
806
+                        break;
807
+                    case 1:
808
+                        $color = @unpack('n', $vide . substr($data, floor($p), 1));
809
+                        switch (($p * 8) % 8) {
810
+                            case 0:
811
+                                $color[1] = $color[1] >> 7;
812
+                                break;
813
+                            case 1:
814
+                                $color[1] = ($color[1] & 0x40) >> 6;
815
+                                break;
816
+                            case 2:
817
+                                $color[1] = ($color[1] & 0x20) >> 5;
818
+                                break;
819
+                            case 3:
820
+                                $color[1] = ($color[1] & 0x10) >> 4;
821
+                                break;
822
+                            case 4:
823
+                                $color[1] = ($color[1] & 0x8) >> 3;
824
+                                break;
825
+                            case 5:
826
+                                $color[1] = ($color[1] & 0x4) >> 2;
827
+                                break;
828
+                            case 6:
829
+                                $color[1] = ($color[1] & 0x2) >> 1;
830
+                                break;
831
+                            case 7:
832
+                                $color[1] = ($color[1] & 0x1);
833
+                                break;
834
+                        }
835
+                        $color[1] = (isset($palette[$color[1] + 1])) ? $palette[$color[1] + 1] : $palette[1];
836
+                        break;
837
+                    default:
838
+                        fclose($fh);
839
+                        $this->logger->warning('imagecreatefrombmp: ' . $fileName . ' has ' . $meta['bits'] . ' bits and this is not supported!', array('app' => 'core'));
840
+                        return false;
841
+                }
842
+                imagesetpixel($im, $x, $y, $color[1]);
843
+                $x++;
844
+                $p += $meta['bytes'];
845
+            }
846
+            $y--;
847
+            $p += $meta['decal'];
848
+        }
849
+        fclose($fh);
850
+        return $im;
851
+    }
852 852
 
853
-	/**
854
-	 * Resizes the image preserving ratio.
855
-	 *
856
-	 * @param integer $maxSize The maximum size of either the width or height.
857
-	 * @return bool
858
-	 */
859
-	public function resize($maxSize) {
860
-		if (!$this->valid()) {
861
-			$this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
862
-			return false;
863
-		}
864
-		$widthOrig = imagesx($this->resource);
865
-		$heightOrig = imagesy($this->resource);
866
-		$ratioOrig = $widthOrig / $heightOrig;
853
+    /**
854
+     * Resizes the image preserving ratio.
855
+     *
856
+     * @param integer $maxSize The maximum size of either the width or height.
857
+     * @return bool
858
+     */
859
+    public function resize($maxSize) {
860
+        if (!$this->valid()) {
861
+            $this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
862
+            return false;
863
+        }
864
+        $widthOrig = imagesx($this->resource);
865
+        $heightOrig = imagesy($this->resource);
866
+        $ratioOrig = $widthOrig / $heightOrig;
867 867
 
868
-		if ($ratioOrig > 1) {
869
-			$newHeight = round($maxSize / $ratioOrig);
870
-			$newWidth = $maxSize;
871
-		} else {
872
-			$newWidth = round($maxSize * $ratioOrig);
873
-			$newHeight = $maxSize;
874
-		}
868
+        if ($ratioOrig > 1) {
869
+            $newHeight = round($maxSize / $ratioOrig);
870
+            $newWidth = $maxSize;
871
+        } else {
872
+            $newWidth = round($maxSize * $ratioOrig);
873
+            $newHeight = $maxSize;
874
+        }
875 875
 
876
-		$this->preciseResize(round($newWidth), round($newHeight));
877
-		return true;
878
-	}
876
+        $this->preciseResize(round($newWidth), round($newHeight));
877
+        return true;
878
+    }
879 879
 
880
-	/**
881
-	 * @param int $width
882
-	 * @param int $height
883
-	 * @return bool
884
-	 */
885
-	public function preciseResize($width, $height) {
886
-		if (!$this->valid()) {
887
-			$this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
888
-			return false;
889
-		}
890
-		$widthOrig = imagesx($this->resource);
891
-		$heightOrig = imagesy($this->resource);
892
-		$process = imagecreatetruecolor($width, $height);
880
+    /**
881
+     * @param int $width
882
+     * @param int $height
883
+     * @return bool
884
+     */
885
+    public function preciseResize($width, $height) {
886
+        if (!$this->valid()) {
887
+            $this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
888
+            return false;
889
+        }
890
+        $widthOrig = imagesx($this->resource);
891
+        $heightOrig = imagesy($this->resource);
892
+        $process = imagecreatetruecolor($width, $height);
893 893
 
894
-		if ($process == false) {
895
-			$this->logger->error(__METHOD__ . '(): Error creating true color image', array('app' => 'core'));
896
-			imagedestroy($process);
897
-			return false;
898
-		}
894
+        if ($process == false) {
895
+            $this->logger->error(__METHOD__ . '(): Error creating true color image', array('app' => 'core'));
896
+            imagedestroy($process);
897
+            return false;
898
+        }
899 899
 
900
-		// preserve transparency
901
-		if ($this->imageType == IMAGETYPE_GIF or $this->imageType == IMAGETYPE_PNG) {
902
-			imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127));
903
-			imagealphablending($process, false);
904
-			imagesavealpha($process, true);
905
-		}
900
+        // preserve transparency
901
+        if ($this->imageType == IMAGETYPE_GIF or $this->imageType == IMAGETYPE_PNG) {
902
+            imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127));
903
+            imagealphablending($process, false);
904
+            imagesavealpha($process, true);
905
+        }
906 906
 
907
-		imagecopyresampled($process, $this->resource, 0, 0, 0, 0, $width, $height, $widthOrig, $heightOrig);
908
-		if ($process == false) {
909
-			$this->logger->error(__METHOD__ . '(): Error re-sampling process image', array('app' => 'core'));
910
-			imagedestroy($process);
911
-			return false;
912
-		}
913
-		imagedestroy($this->resource);
914
-		$this->resource = $process;
915
-		return true;
916
-	}
907
+        imagecopyresampled($process, $this->resource, 0, 0, 0, 0, $width, $height, $widthOrig, $heightOrig);
908
+        if ($process == false) {
909
+            $this->logger->error(__METHOD__ . '(): Error re-sampling process image', array('app' => 'core'));
910
+            imagedestroy($process);
911
+            return false;
912
+        }
913
+        imagedestroy($this->resource);
914
+        $this->resource = $process;
915
+        return true;
916
+    }
917 917
 
918
-	/**
919
-	 * Crops the image to the middle square. If the image is already square it just returns.
920
-	 *
921
-	 * @param int $size maximum size for the result (optional)
922
-	 * @return bool for success or failure
923
-	 */
924
-	public function centerCrop($size = 0) {
925
-		if (!$this->valid()) {
926
-			$this->logger->error('OC_Image->centerCrop, No image loaded', array('app' => 'core'));
927
-			return false;
928
-		}
929
-		$widthOrig = imagesx($this->resource);
930
-		$heightOrig = imagesy($this->resource);
931
-		if ($widthOrig === $heightOrig and $size == 0) {
932
-			return true;
933
-		}
934
-		$ratioOrig = $widthOrig / $heightOrig;
935
-		$width = $height = min($widthOrig, $heightOrig);
918
+    /**
919
+     * Crops the image to the middle square. If the image is already square it just returns.
920
+     *
921
+     * @param int $size maximum size for the result (optional)
922
+     * @return bool for success or failure
923
+     */
924
+    public function centerCrop($size = 0) {
925
+        if (!$this->valid()) {
926
+            $this->logger->error('OC_Image->centerCrop, No image loaded', array('app' => 'core'));
927
+            return false;
928
+        }
929
+        $widthOrig = imagesx($this->resource);
930
+        $heightOrig = imagesy($this->resource);
931
+        if ($widthOrig === $heightOrig and $size == 0) {
932
+            return true;
933
+        }
934
+        $ratioOrig = $widthOrig / $heightOrig;
935
+        $width = $height = min($widthOrig, $heightOrig);
936 936
 
937
-		if ($ratioOrig > 1) {
938
-			$x = ($widthOrig / 2) - ($width / 2);
939
-			$y = 0;
940
-		} else {
941
-			$y = ($heightOrig / 2) - ($height / 2);
942
-			$x = 0;
943
-		}
944
-		if ($size > 0) {
945
-			$targetWidth = $size;
946
-			$targetHeight = $size;
947
-		} else {
948
-			$targetWidth = $width;
949
-			$targetHeight = $height;
950
-		}
951
-		$process = imagecreatetruecolor($targetWidth, $targetHeight);
952
-		if ($process == false) {
953
-			$this->logger->error('OC_Image->centerCrop, Error creating true color image', array('app' => 'core'));
954
-			imagedestroy($process);
955
-			return false;
956
-		}
937
+        if ($ratioOrig > 1) {
938
+            $x = ($widthOrig / 2) - ($width / 2);
939
+            $y = 0;
940
+        } else {
941
+            $y = ($heightOrig / 2) - ($height / 2);
942
+            $x = 0;
943
+        }
944
+        if ($size > 0) {
945
+            $targetWidth = $size;
946
+            $targetHeight = $size;
947
+        } else {
948
+            $targetWidth = $width;
949
+            $targetHeight = $height;
950
+        }
951
+        $process = imagecreatetruecolor($targetWidth, $targetHeight);
952
+        if ($process == false) {
953
+            $this->logger->error('OC_Image->centerCrop, Error creating true color image', array('app' => 'core'));
954
+            imagedestroy($process);
955
+            return false;
956
+        }
957 957
 
958
-		// preserve transparency
959
-		if ($this->imageType == IMAGETYPE_GIF or $this->imageType == IMAGETYPE_PNG) {
960
-			imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127));
961
-			imagealphablending($process, false);
962
-			imagesavealpha($process, true);
963
-		}
958
+        // preserve transparency
959
+        if ($this->imageType == IMAGETYPE_GIF or $this->imageType == IMAGETYPE_PNG) {
960
+            imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127));
961
+            imagealphablending($process, false);
962
+            imagesavealpha($process, true);
963
+        }
964 964
 
965
-		imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $targetWidth, $targetHeight, $width, $height);
966
-		if ($process == false) {
967
-			$this->logger->error('OC_Image->centerCrop, Error re-sampling process image ' . $width . 'x' . $height, array('app' => 'core'));
968
-			imagedestroy($process);
969
-			return false;
970
-		}
971
-		imagedestroy($this->resource);
972
-		$this->resource = $process;
973
-		return true;
974
-	}
965
+        imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $targetWidth, $targetHeight, $width, $height);
966
+        if ($process == false) {
967
+            $this->logger->error('OC_Image->centerCrop, Error re-sampling process image ' . $width . 'x' . $height, array('app' => 'core'));
968
+            imagedestroy($process);
969
+            return false;
970
+        }
971
+        imagedestroy($this->resource);
972
+        $this->resource = $process;
973
+        return true;
974
+    }
975 975
 
976
-	/**
977
-	 * Crops the image from point $x$y with dimension $wx$h.
978
-	 *
979
-	 * @param int $x Horizontal position
980
-	 * @param int $y Vertical position
981
-	 * @param int $w Width
982
-	 * @param int $h Height
983
-	 * @return bool for success or failure
984
-	 */
985
-	public function crop($x, $y, $w, $h) {
986
-		if (!$this->valid()) {
987
-			$this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
988
-			return false;
989
-		}
990
-		$process = imagecreatetruecolor($w, $h);
991
-		if ($process == false) {
992
-			$this->logger->error(__METHOD__ . '(): Error creating true color image', array('app' => 'core'));
993
-			imagedestroy($process);
994
-			return false;
995
-		}
976
+    /**
977
+     * Crops the image from point $x$y with dimension $wx$h.
978
+     *
979
+     * @param int $x Horizontal position
980
+     * @param int $y Vertical position
981
+     * @param int $w Width
982
+     * @param int $h Height
983
+     * @return bool for success or failure
984
+     */
985
+    public function crop($x, $y, $w, $h) {
986
+        if (!$this->valid()) {
987
+            $this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
988
+            return false;
989
+        }
990
+        $process = imagecreatetruecolor($w, $h);
991
+        if ($process == false) {
992
+            $this->logger->error(__METHOD__ . '(): Error creating true color image', array('app' => 'core'));
993
+            imagedestroy($process);
994
+            return false;
995
+        }
996 996
 
997
-		// preserve transparency
998
-		if ($this->imageType == IMAGETYPE_GIF or $this->imageType == IMAGETYPE_PNG) {
999
-			imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127));
1000
-			imagealphablending($process, false);
1001
-			imagesavealpha($process, true);
1002
-		}
997
+        // preserve transparency
998
+        if ($this->imageType == IMAGETYPE_GIF or $this->imageType == IMAGETYPE_PNG) {
999
+            imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127));
1000
+            imagealphablending($process, false);
1001
+            imagesavealpha($process, true);
1002
+        }
1003 1003
 
1004
-		imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $w, $h, $w, $h);
1005
-		if ($process == false) {
1006
-			$this->logger->error(__METHOD__ . '(): Error re-sampling process image ' . $w . 'x' . $h, array('app' => 'core'));
1007
-			imagedestroy($process);
1008
-			return false;
1009
-		}
1010
-		imagedestroy($this->resource);
1011
-		$this->resource = $process;
1012
-		return true;
1013
-	}
1004
+        imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $w, $h, $w, $h);
1005
+        if ($process == false) {
1006
+            $this->logger->error(__METHOD__ . '(): Error re-sampling process image ' . $w . 'x' . $h, array('app' => 'core'));
1007
+            imagedestroy($process);
1008
+            return false;
1009
+        }
1010
+        imagedestroy($this->resource);
1011
+        $this->resource = $process;
1012
+        return true;
1013
+    }
1014 1014
 
1015
-	/**
1016
-	 * Resizes the image to fit within a boundary while preserving ratio.
1017
-	 *
1018
-	 * Warning: Images smaller than $maxWidth x $maxHeight will end up being scaled up
1019
-	 *
1020
-	 * @param integer $maxWidth
1021
-	 * @param integer $maxHeight
1022
-	 * @return bool
1023
-	 */
1024
-	public function fitIn($maxWidth, $maxHeight) {
1025
-		if (!$this->valid()) {
1026
-			$this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
1027
-			return false;
1028
-		}
1029
-		$widthOrig = imagesx($this->resource);
1030
-		$heightOrig = imagesy($this->resource);
1031
-		$ratio = $widthOrig / $heightOrig;
1015
+    /**
1016
+     * Resizes the image to fit within a boundary while preserving ratio.
1017
+     *
1018
+     * Warning: Images smaller than $maxWidth x $maxHeight will end up being scaled up
1019
+     *
1020
+     * @param integer $maxWidth
1021
+     * @param integer $maxHeight
1022
+     * @return bool
1023
+     */
1024
+    public function fitIn($maxWidth, $maxHeight) {
1025
+        if (!$this->valid()) {
1026
+            $this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
1027
+            return false;
1028
+        }
1029
+        $widthOrig = imagesx($this->resource);
1030
+        $heightOrig = imagesy($this->resource);
1031
+        $ratio = $widthOrig / $heightOrig;
1032 1032
 
1033
-		$newWidth = min($maxWidth, $ratio * $maxHeight);
1034
-		$newHeight = min($maxHeight, $maxWidth / $ratio);
1033
+        $newWidth = min($maxWidth, $ratio * $maxHeight);
1034
+        $newHeight = min($maxHeight, $maxWidth / $ratio);
1035 1035
 
1036
-		$this->preciseResize(round($newWidth), round($newHeight));
1037
-		return true;
1038
-	}
1036
+        $this->preciseResize(round($newWidth), round($newHeight));
1037
+        return true;
1038
+    }
1039 1039
 
1040
-	/**
1041
-	 * Shrinks larger images to fit within specified boundaries while preserving ratio.
1042
-	 *
1043
-	 * @param integer $maxWidth
1044
-	 * @param integer $maxHeight
1045
-	 * @return bool
1046
-	 */
1047
-	public function scaleDownToFit($maxWidth, $maxHeight) {
1048
-		if (!$this->valid()) {
1049
-			$this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
1050
-			return false;
1051
-		}
1052
-		$widthOrig = imagesx($this->resource);
1053
-		$heightOrig = imagesy($this->resource);
1040
+    /**
1041
+     * Shrinks larger images to fit within specified boundaries while preserving ratio.
1042
+     *
1043
+     * @param integer $maxWidth
1044
+     * @param integer $maxHeight
1045
+     * @return bool
1046
+     */
1047
+    public function scaleDownToFit($maxWidth, $maxHeight) {
1048
+        if (!$this->valid()) {
1049
+            $this->logger->error(__METHOD__ . '(): No image loaded', array('app' => 'core'));
1050
+            return false;
1051
+        }
1052
+        $widthOrig = imagesx($this->resource);
1053
+        $heightOrig = imagesy($this->resource);
1054 1054
 
1055
-		if ($widthOrig > $maxWidth || $heightOrig > $maxHeight) {
1056
-			return $this->fitIn($maxWidth, $maxHeight);
1057
-		}
1055
+        if ($widthOrig > $maxWidth || $heightOrig > $maxHeight) {
1056
+            return $this->fitIn($maxWidth, $maxHeight);
1057
+        }
1058 1058
 
1059
-		return false;
1060
-	}
1059
+        return false;
1060
+    }
1061 1061
 
1062
-	/**
1063
-	 * Destroys the current image and resets the object
1064
-	 */
1065
-	public function destroy() {
1066
-		if ($this->valid()) {
1067
-			imagedestroy($this->resource);
1068
-		}
1069
-		$this->resource = null;
1070
-	}
1062
+    /**
1063
+     * Destroys the current image and resets the object
1064
+     */
1065
+    public function destroy() {
1066
+        if ($this->valid()) {
1067
+            imagedestroy($this->resource);
1068
+        }
1069
+        $this->resource = null;
1070
+    }
1071 1071
 
1072
-	public function __destruct() {
1073
-		$this->destroy();
1074
-	}
1072
+    public function __destruct() {
1073
+        $this->destroy();
1074
+    }
1075 1075
 }
1076 1076
 
1077 1077
 if (!function_exists('imagebmp')) {
1078
-	/**
1079
-	 * Output a BMP image to either the browser or a file
1080
-	 *
1081
-	 * @link http://www.ugia.cn/wp-data/imagebmp.php
1082
-	 * @author legend <[email protected]>
1083
-	 * @link http://www.programmierer-forum.de/imagebmp-gute-funktion-gefunden-t143716.htm
1084
-	 * @author mgutt <[email protected]>
1085
-	 * @version 1.00
1086
-	 * @param resource $im
1087
-	 * @param string $fileName [optional] <p>The path to save the file to.</p>
1088
-	 * @param int $bit [optional] <p>Bit depth, (default is 24).</p>
1089
-	 * @param int $compression [optional]
1090
-	 * @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
1091
-	 */
1092
-	function imagebmp($im, $fileName = '', $bit = 24, $compression = 0) {
1093
-		if (!in_array($bit, array(1, 4, 8, 16, 24, 32))) {
1094
-			$bit = 24;
1095
-		} else if ($bit == 32) {
1096
-			$bit = 24;
1097
-		}
1098
-		$bits = pow(2, $bit);
1099
-		imagetruecolortopalette($im, true, $bits);
1100
-		$width = imagesx($im);
1101
-		$height = imagesy($im);
1102
-		$colorsNum = imagecolorstotal($im);
1103
-		$rgbQuad = '';
1104
-		if ($bit <= 8) {
1105
-			for ($i = 0; $i < $colorsNum; $i++) {
1106
-				$colors = imagecolorsforindex($im, $i);
1107
-				$rgbQuad .= chr($colors['blue']) . chr($colors['green']) . chr($colors['red']) . "\0";
1108
-			}
1109
-			$bmpData = '';
1110
-			if ($compression == 0 || $bit < 8) {
1111
-				$compression = 0;
1112
-				$extra = '';
1113
-				$padding = 4 - ceil($width / (8 / $bit)) % 4;
1114
-				if ($padding % 4 != 0) {
1115
-					$extra = str_repeat("\0", $padding);
1116
-				}
1117
-				for ($j = $height - 1; $j >= 0; $j--) {
1118
-					$i = 0;
1119
-					while ($i < $width) {
1120
-						$bin = 0;
1121
-						$limit = $width - $i < 8 / $bit ? (8 / $bit - $width + $i) * $bit : 0;
1122
-						for ($k = 8 - $bit; $k >= $limit; $k -= $bit) {
1123
-							$index = imagecolorat($im, $i, $j);
1124
-							$bin |= $index << $k;
1125
-							$i++;
1126
-						}
1127
-						$bmpData .= chr($bin);
1128
-					}
1129
-					$bmpData .= $extra;
1130
-				}
1131
-			} // RLE8
1132
-			else if ($compression == 1 && $bit == 8) {
1133
-				for ($j = $height - 1; $j >= 0; $j--) {
1134
-					$lastIndex = "\0";
1135
-					$sameNum = 0;
1136
-					for ($i = 0; $i <= $width; $i++) {
1137
-						$index = imagecolorat($im, $i, $j);
1138
-						if ($index !== $lastIndex || $sameNum > 255) {
1139
-							if ($sameNum != 0) {
1140
-								$bmpData .= chr($sameNum) . chr($lastIndex);
1141
-							}
1142
-							$lastIndex = $index;
1143
-							$sameNum = 1;
1144
-						} else {
1145
-							$sameNum++;
1146
-						}
1147
-					}
1148
-					$bmpData .= "\0\0";
1149
-				}
1150
-				$bmpData .= "\0\1";
1151
-			}
1152
-			$sizeQuad = strlen($rgbQuad);
1153
-			$sizeData = strlen($bmpData);
1154
-		} else {
1155
-			$extra = '';
1156
-			$padding = 4 - ($width * ($bit / 8)) % 4;
1157
-			if ($padding % 4 != 0) {
1158
-				$extra = str_repeat("\0", $padding);
1159
-			}
1160
-			$bmpData = '';
1161
-			for ($j = $height - 1; $j >= 0; $j--) {
1162
-				for ($i = 0; $i < $width; $i++) {
1163
-					$index = imagecolorat($im, $i, $j);
1164
-					$colors = imagecolorsforindex($im, $index);
1165
-					if ($bit == 16) {
1166
-						$bin = 0 << $bit;
1167
-						$bin |= ($colors['red'] >> 3) << 10;
1168
-						$bin |= ($colors['green'] >> 3) << 5;
1169
-						$bin |= $colors['blue'] >> 3;
1170
-						$bmpData .= pack("v", $bin);
1171
-					} else {
1172
-						$bmpData .= pack("c*", $colors['blue'], $colors['green'], $colors['red']);
1173
-					}
1174
-				}
1175
-				$bmpData .= $extra;
1176
-			}
1177
-			$sizeQuad = 0;
1178
-			$sizeData = strlen($bmpData);
1179
-			$colorsNum = 0;
1180
-		}
1181
-		$fileHeader = 'BM' . pack('V3', 54 + $sizeQuad + $sizeData, 0, 54 + $sizeQuad);
1182
-		$infoHeader = pack('V3v2V*', 0x28, $width, $height, 1, $bit, $compression, $sizeData, 0, 0, $colorsNum, 0);
1183
-		if ($fileName != '') {
1184
-			$fp = fopen($fileName, 'wb');
1185
-			fwrite($fp, $fileHeader . $infoHeader . $rgbQuad . $bmpData);
1186
-			fclose($fp);
1187
-			return true;
1188
-		}
1189
-		echo $fileHeader . $infoHeader . $rgbQuad . $bmpData;
1190
-		return true;
1191
-	}
1078
+    /**
1079
+     * Output a BMP image to either the browser or a file
1080
+     *
1081
+     * @link http://www.ugia.cn/wp-data/imagebmp.php
1082
+     * @author legend <[email protected]>
1083
+     * @link http://www.programmierer-forum.de/imagebmp-gute-funktion-gefunden-t143716.htm
1084
+     * @author mgutt <[email protected]>
1085
+     * @version 1.00
1086
+     * @param resource $im
1087
+     * @param string $fileName [optional] <p>The path to save the file to.</p>
1088
+     * @param int $bit [optional] <p>Bit depth, (default is 24).</p>
1089
+     * @param int $compression [optional]
1090
+     * @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
1091
+     */
1092
+    function imagebmp($im, $fileName = '', $bit = 24, $compression = 0) {
1093
+        if (!in_array($bit, array(1, 4, 8, 16, 24, 32))) {
1094
+            $bit = 24;
1095
+        } else if ($bit == 32) {
1096
+            $bit = 24;
1097
+        }
1098
+        $bits = pow(2, $bit);
1099
+        imagetruecolortopalette($im, true, $bits);
1100
+        $width = imagesx($im);
1101
+        $height = imagesy($im);
1102
+        $colorsNum = imagecolorstotal($im);
1103
+        $rgbQuad = '';
1104
+        if ($bit <= 8) {
1105
+            for ($i = 0; $i < $colorsNum; $i++) {
1106
+                $colors = imagecolorsforindex($im, $i);
1107
+                $rgbQuad .= chr($colors['blue']) . chr($colors['green']) . chr($colors['red']) . "\0";
1108
+            }
1109
+            $bmpData = '';
1110
+            if ($compression == 0 || $bit < 8) {
1111
+                $compression = 0;
1112
+                $extra = '';
1113
+                $padding = 4 - ceil($width / (8 / $bit)) % 4;
1114
+                if ($padding % 4 != 0) {
1115
+                    $extra = str_repeat("\0", $padding);
1116
+                }
1117
+                for ($j = $height - 1; $j >= 0; $j--) {
1118
+                    $i = 0;
1119
+                    while ($i < $width) {
1120
+                        $bin = 0;
1121
+                        $limit = $width - $i < 8 / $bit ? (8 / $bit - $width + $i) * $bit : 0;
1122
+                        for ($k = 8 - $bit; $k >= $limit; $k -= $bit) {
1123
+                            $index = imagecolorat($im, $i, $j);
1124
+                            $bin |= $index << $k;
1125
+                            $i++;
1126
+                        }
1127
+                        $bmpData .= chr($bin);
1128
+                    }
1129
+                    $bmpData .= $extra;
1130
+                }
1131
+            } // RLE8
1132
+            else if ($compression == 1 && $bit == 8) {
1133
+                for ($j = $height - 1; $j >= 0; $j--) {
1134
+                    $lastIndex = "\0";
1135
+                    $sameNum = 0;
1136
+                    for ($i = 0; $i <= $width; $i++) {
1137
+                        $index = imagecolorat($im, $i, $j);
1138
+                        if ($index !== $lastIndex || $sameNum > 255) {
1139
+                            if ($sameNum != 0) {
1140
+                                $bmpData .= chr($sameNum) . chr($lastIndex);
1141
+                            }
1142
+                            $lastIndex = $index;
1143
+                            $sameNum = 1;
1144
+                        } else {
1145
+                            $sameNum++;
1146
+                        }
1147
+                    }
1148
+                    $bmpData .= "\0\0";
1149
+                }
1150
+                $bmpData .= "\0\1";
1151
+            }
1152
+            $sizeQuad = strlen($rgbQuad);
1153
+            $sizeData = strlen($bmpData);
1154
+        } else {
1155
+            $extra = '';
1156
+            $padding = 4 - ($width * ($bit / 8)) % 4;
1157
+            if ($padding % 4 != 0) {
1158
+                $extra = str_repeat("\0", $padding);
1159
+            }
1160
+            $bmpData = '';
1161
+            for ($j = $height - 1; $j >= 0; $j--) {
1162
+                for ($i = 0; $i < $width; $i++) {
1163
+                    $index = imagecolorat($im, $i, $j);
1164
+                    $colors = imagecolorsforindex($im, $index);
1165
+                    if ($bit == 16) {
1166
+                        $bin = 0 << $bit;
1167
+                        $bin |= ($colors['red'] >> 3) << 10;
1168
+                        $bin |= ($colors['green'] >> 3) << 5;
1169
+                        $bin |= $colors['blue'] >> 3;
1170
+                        $bmpData .= pack("v", $bin);
1171
+                    } else {
1172
+                        $bmpData .= pack("c*", $colors['blue'], $colors['green'], $colors['red']);
1173
+                    }
1174
+                }
1175
+                $bmpData .= $extra;
1176
+            }
1177
+            $sizeQuad = 0;
1178
+            $sizeData = strlen($bmpData);
1179
+            $colorsNum = 0;
1180
+        }
1181
+        $fileHeader = 'BM' . pack('V3', 54 + $sizeQuad + $sizeData, 0, 54 + $sizeQuad);
1182
+        $infoHeader = pack('V3v2V*', 0x28, $width, $height, 1, $bit, $compression, $sizeData, 0, 0, $colorsNum, 0);
1183
+        if ($fileName != '') {
1184
+            $fp = fopen($fileName, 'wb');
1185
+            fwrite($fp, $fileHeader . $infoHeader . $rgbQuad . $bmpData);
1186
+            fclose($fp);
1187
+            return true;
1188
+        }
1189
+        echo $fileHeader . $infoHeader . $rgbQuad . $bmpData;
1190
+        return true;
1191
+    }
1192 1192
 }
1193 1193
 
1194 1194
 if (!function_exists('exif_imagetype')) {
1195
-	/**
1196
-	 * Workaround if exif_imagetype does not exist
1197
-	 *
1198
-	 * @link http://www.php.net/manual/en/function.exif-imagetype.php#80383
1199
-	 * @param string $fileName
1200
-	 * @return string|boolean
1201
-	 */
1202
-	function exif_imagetype($fileName) {
1203
-		if (($info = getimagesize($fileName)) !== false) {
1204
-			return $info[2];
1205
-		}
1206
-		return false;
1207
-	}
1195
+    /**
1196
+     * Workaround if exif_imagetype does not exist
1197
+     *
1198
+     * @link http://www.php.net/manual/en/function.exif-imagetype.php#80383
1199
+     * @param string $fileName
1200
+     * @return string|boolean
1201
+     */
1202
+    function exif_imagetype($fileName) {
1203
+        if (($info = getimagesize($fileName)) !== false) {
1204
+            return $info[2];
1205
+        }
1206
+        return false;
1207
+    }
1208 1208
 }
Please login to merge, or discard this patch.
lib/private/Preview/Generator.php 2 patches
Indentation   +361 added lines, -361 removed lines patch added patch discarded remove patch
@@ -40,379 +40,379 @@
 block discarded – undo
40 40
 
41 41
 class Generator {
42 42
 
43
-	/** @var IPreview */
44
-	private $previewManager;
45
-	/** @var IConfig */
46
-	private $config;
47
-	/** @var IAppData */
48
-	private $appData;
49
-	/** @var GeneratorHelper */
50
-	private $helper;
51
-	/** @var EventDispatcherInterface */
52
-	private $eventDispatcher;
53
-
54
-	/**
55
-	 * @param IConfig $config
56
-	 * @param IPreview $previewManager
57
-	 * @param IAppData $appData
58
-	 * @param GeneratorHelper $helper
59
-	 * @param EventDispatcherInterface $eventDispatcher
60
-	 */
61
-	public function __construct(
62
-		IConfig $config,
63
-		IPreview $previewManager,
64
-		IAppData $appData,
65
-		GeneratorHelper $helper,
66
-		EventDispatcherInterface $eventDispatcher
67
-	) {
68
-		$this->config = $config;
69
-		$this->previewManager = $previewManager;
70
-		$this->appData = $appData;
71
-		$this->helper = $helper;
72
-		$this->eventDispatcher = $eventDispatcher;
73
-	}
74
-
75
-	/**
76
-	 * Returns a preview of a file
77
-	 *
78
-	 * The cache is searched first and if nothing usable was found then a preview is
79
-	 * generated by one of the providers
80
-	 *
81
-	 * @param File $file
82
-	 * @param int $width
83
-	 * @param int $height
84
-	 * @param bool $crop
85
-	 * @param string $mode
86
-	 * @param string $mimeType
87
-	 * @return ISimpleFile
88
-	 * @throws NotFoundException
89
-	 * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
90
-	 */
91
-	public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) {
92
-		$this->eventDispatcher->dispatch(
93
-			IPreview::EVENT,
94
-			new GenericEvent($file,[
95
-				'width' => $width,
96
-				'height' => $height,
97
-				'crop' => $crop,
98
-				'mode' => $mode
99
-			])
100
-		);
101
-
102
-		if ($mimeType === null) {
103
-			$mimeType = $file->getMimeType();
104
-		}
105
-		if (!$this->previewManager->isMimeSupported($mimeType)) {
106
-			throw new NotFoundException();
107
-		}
108
-
109
-		$previewFolder = $this->getPreviewFolder($file);
110
-
111
-		// Get the max preview and infer the max preview sizes from that
112
-		$maxPreview = $this->getMaxPreview($previewFolder, $file, $mimeType);
113
-		list($maxWidth, $maxHeight) = $this->getPreviewSize($maxPreview);
114
-
115
-		// If both width and heigth are -1 we just want the max preview
116
-		if ($width === -1 && $height === -1) {
117
-			$width = $maxWidth;
118
-			$height = $maxHeight;
119
-		}
120
-
121
-		// Calculate the preview size
122
-		list($width, $height) = $this->calculateSize($width, $height, $crop, $mode, $maxWidth, $maxHeight);
123
-
124
-		// No need to generate a preview that is just the max preview
125
-		if ($width === $maxWidth && $height === $maxHeight) {
126
-			return $maxPreview;
127
-		}
128
-
129
-		// Try to get a cached preview. Else generate (and store) one
130
-		try {
131
-			try {
132
-				$file = $this->getCachedPreview($previewFolder, $width, $height, $crop, $maxPreview->getMimeType());
133
-			} catch (NotFoundException $e) {
134
-				$file = $this->generatePreview($previewFolder, $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight);
135
-			}
136
-		} catch (\InvalidArgumentException $e) {
137
-			throw new NotFoundException();
138
-		}
139
-
140
-		return $file;
141
-	}
142
-
143
-	/**
144
-	 * @param ISimpleFolder $previewFolder
145
-	 * @param File $file
146
-	 * @param string $mimeType
147
-	 * @return ISimpleFile
148
-	 * @throws NotFoundException
149
-	 */
150
-	private function getMaxPreview(ISimpleFolder $previewFolder, File $file, $mimeType) {
151
-		$nodes = $previewFolder->getDirectoryListing();
152
-
153
-		foreach ($nodes as $node) {
154
-			if (strpos($node->getName(), 'max')) {
155
-				return $node;
156
-			}
157
-		}
158
-
159
-		$previewProviders = $this->previewManager->getProviders();
160
-		foreach ($previewProviders as $supportedMimeType => $providers) {
161
-			if (!preg_match($supportedMimeType, $mimeType)) {
162
-				continue;
163
-			}
164
-
165
-			foreach ($providers as $provider) {
166
-				$provider = $this->helper->getProvider($provider);
167
-				if (!($provider instanceof IProvider)) {
168
-					continue;
169
-				}
170
-
171
-				$maxWidth = (int)$this->config->getSystemValue('preview_max_x', 4096);
172
-				$maxHeight = (int)$this->config->getSystemValue('preview_max_y', 4096);
173
-
174
-				$preview = $this->helper->getThumbnail($provider, $file, $maxWidth, $maxHeight);
175
-
176
-				if (!($preview instanceof IImage)) {
177
-					continue;
178
-				}
179
-
180
-				// Try to get the extention.
181
-				try {
182
-					$ext = $this->getExtention($preview->dataMimeType());
183
-				} catch (\InvalidArgumentException $e) {
184
-					// Just continue to the next iteration if this preview doesn't have a valid mimetype
185
-					continue;
186
-				}
187
-
188
-				$path = (string)$preview->width() . '-' . (string)$preview->height() . '-max.' . $ext;
189
-				try {
190
-					$file = $previewFolder->newFile($path);
191
-					$file->putContent($preview->data());
192
-				} catch (NotPermittedException $e) {
193
-					throw new NotFoundException();
194
-				}
195
-
196
-				return $file;
197
-			}
198
-		}
199
-
200
-		throw new NotFoundException();
201
-	}
202
-
203
-	/**
204
-	 * @param ISimpleFile $file
205
-	 * @return int[]
206
-	 */
207
-	private function getPreviewSize(ISimpleFile $file) {
208
-		$size = explode('-', $file->getName());
209
-		return [(int)$size[0], (int)$size[1]];
210
-	}
211
-
212
-	/**
213
-	 * @param int $width
214
-	 * @param int $height
215
-	 * @param bool $crop
216
-	 * @param string $mimeType
217
-	 * @return string
218
-	 */
219
-	private function generatePath($width, $height, $crop, $mimeType) {
220
-		$path = (string)$width . '-' . (string)$height;
221
-		if ($crop) {
222
-			$path .= '-crop';
223
-		}
224
-
225
-		$ext = $this->getExtention($mimeType);
226
-		$path .= '.' . $ext;
227
-		return $path;
228
-	}
229
-
230
-
231
-
232
-	/**
233
-	 * @param int $width
234
-	 * @param int $height
235
-	 * @param bool $crop
236
-	 * @param string $mode
237
-	 * @param int $maxWidth
238
-	 * @param int $maxHeight
239
-	 * @return int[]
240
-	 */
241
-	private function calculateSize($width, $height, $crop, $mode, $maxWidth, $maxHeight) {
242
-
243
-		/*
43
+    /** @var IPreview */
44
+    private $previewManager;
45
+    /** @var IConfig */
46
+    private $config;
47
+    /** @var IAppData */
48
+    private $appData;
49
+    /** @var GeneratorHelper */
50
+    private $helper;
51
+    /** @var EventDispatcherInterface */
52
+    private $eventDispatcher;
53
+
54
+    /**
55
+     * @param IConfig $config
56
+     * @param IPreview $previewManager
57
+     * @param IAppData $appData
58
+     * @param GeneratorHelper $helper
59
+     * @param EventDispatcherInterface $eventDispatcher
60
+     */
61
+    public function __construct(
62
+        IConfig $config,
63
+        IPreview $previewManager,
64
+        IAppData $appData,
65
+        GeneratorHelper $helper,
66
+        EventDispatcherInterface $eventDispatcher
67
+    ) {
68
+        $this->config = $config;
69
+        $this->previewManager = $previewManager;
70
+        $this->appData = $appData;
71
+        $this->helper = $helper;
72
+        $this->eventDispatcher = $eventDispatcher;
73
+    }
74
+
75
+    /**
76
+     * Returns a preview of a file
77
+     *
78
+     * The cache is searched first and if nothing usable was found then a preview is
79
+     * generated by one of the providers
80
+     *
81
+     * @param File $file
82
+     * @param int $width
83
+     * @param int $height
84
+     * @param bool $crop
85
+     * @param string $mode
86
+     * @param string $mimeType
87
+     * @return ISimpleFile
88
+     * @throws NotFoundException
89
+     * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
90
+     */
91
+    public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) {
92
+        $this->eventDispatcher->dispatch(
93
+            IPreview::EVENT,
94
+            new GenericEvent($file,[
95
+                'width' => $width,
96
+                'height' => $height,
97
+                'crop' => $crop,
98
+                'mode' => $mode
99
+            ])
100
+        );
101
+
102
+        if ($mimeType === null) {
103
+            $mimeType = $file->getMimeType();
104
+        }
105
+        if (!$this->previewManager->isMimeSupported($mimeType)) {
106
+            throw new NotFoundException();
107
+        }
108
+
109
+        $previewFolder = $this->getPreviewFolder($file);
110
+
111
+        // Get the max preview and infer the max preview sizes from that
112
+        $maxPreview = $this->getMaxPreview($previewFolder, $file, $mimeType);
113
+        list($maxWidth, $maxHeight) = $this->getPreviewSize($maxPreview);
114
+
115
+        // If both width and heigth are -1 we just want the max preview
116
+        if ($width === -1 && $height === -1) {
117
+            $width = $maxWidth;
118
+            $height = $maxHeight;
119
+        }
120
+
121
+        // Calculate the preview size
122
+        list($width, $height) = $this->calculateSize($width, $height, $crop, $mode, $maxWidth, $maxHeight);
123
+
124
+        // No need to generate a preview that is just the max preview
125
+        if ($width === $maxWidth && $height === $maxHeight) {
126
+            return $maxPreview;
127
+        }
128
+
129
+        // Try to get a cached preview. Else generate (and store) one
130
+        try {
131
+            try {
132
+                $file = $this->getCachedPreview($previewFolder, $width, $height, $crop, $maxPreview->getMimeType());
133
+            } catch (NotFoundException $e) {
134
+                $file = $this->generatePreview($previewFolder, $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight);
135
+            }
136
+        } catch (\InvalidArgumentException $e) {
137
+            throw new NotFoundException();
138
+        }
139
+
140
+        return $file;
141
+    }
142
+
143
+    /**
144
+     * @param ISimpleFolder $previewFolder
145
+     * @param File $file
146
+     * @param string $mimeType
147
+     * @return ISimpleFile
148
+     * @throws NotFoundException
149
+     */
150
+    private function getMaxPreview(ISimpleFolder $previewFolder, File $file, $mimeType) {
151
+        $nodes = $previewFolder->getDirectoryListing();
152
+
153
+        foreach ($nodes as $node) {
154
+            if (strpos($node->getName(), 'max')) {
155
+                return $node;
156
+            }
157
+        }
158
+
159
+        $previewProviders = $this->previewManager->getProviders();
160
+        foreach ($previewProviders as $supportedMimeType => $providers) {
161
+            if (!preg_match($supportedMimeType, $mimeType)) {
162
+                continue;
163
+            }
164
+
165
+            foreach ($providers as $provider) {
166
+                $provider = $this->helper->getProvider($provider);
167
+                if (!($provider instanceof IProvider)) {
168
+                    continue;
169
+                }
170
+
171
+                $maxWidth = (int)$this->config->getSystemValue('preview_max_x', 4096);
172
+                $maxHeight = (int)$this->config->getSystemValue('preview_max_y', 4096);
173
+
174
+                $preview = $this->helper->getThumbnail($provider, $file, $maxWidth, $maxHeight);
175
+
176
+                if (!($preview instanceof IImage)) {
177
+                    continue;
178
+                }
179
+
180
+                // Try to get the extention.
181
+                try {
182
+                    $ext = $this->getExtention($preview->dataMimeType());
183
+                } catch (\InvalidArgumentException $e) {
184
+                    // Just continue to the next iteration if this preview doesn't have a valid mimetype
185
+                    continue;
186
+                }
187
+
188
+                $path = (string)$preview->width() . '-' . (string)$preview->height() . '-max.' . $ext;
189
+                try {
190
+                    $file = $previewFolder->newFile($path);
191
+                    $file->putContent($preview->data());
192
+                } catch (NotPermittedException $e) {
193
+                    throw new NotFoundException();
194
+                }
195
+
196
+                return $file;
197
+            }
198
+        }
199
+
200
+        throw new NotFoundException();
201
+    }
202
+
203
+    /**
204
+     * @param ISimpleFile $file
205
+     * @return int[]
206
+     */
207
+    private function getPreviewSize(ISimpleFile $file) {
208
+        $size = explode('-', $file->getName());
209
+        return [(int)$size[0], (int)$size[1]];
210
+    }
211
+
212
+    /**
213
+     * @param int $width
214
+     * @param int $height
215
+     * @param bool $crop
216
+     * @param string $mimeType
217
+     * @return string
218
+     */
219
+    private function generatePath($width, $height, $crop, $mimeType) {
220
+        $path = (string)$width . '-' . (string)$height;
221
+        if ($crop) {
222
+            $path .= '-crop';
223
+        }
224
+
225
+        $ext = $this->getExtention($mimeType);
226
+        $path .= '.' . $ext;
227
+        return $path;
228
+    }
229
+
230
+
231
+
232
+    /**
233
+     * @param int $width
234
+     * @param int $height
235
+     * @param bool $crop
236
+     * @param string $mode
237
+     * @param int $maxWidth
238
+     * @param int $maxHeight
239
+     * @return int[]
240
+     */
241
+    private function calculateSize($width, $height, $crop, $mode, $maxWidth, $maxHeight) {
242
+
243
+        /*
244 244
 		 * If we are not cropping we have to make sure the requested image
245 245
 		 * respects the aspect ratio of the original.
246 246
 		 */
247
-		if (!$crop) {
248
-			$ratio = $maxHeight / $maxWidth;
247
+        if (!$crop) {
248
+            $ratio = $maxHeight / $maxWidth;
249 249
 
250
-			if ($width === -1) {
251
-				$width = $height / $ratio;
252
-			}
253
-			if ($height === -1) {
254
-				$height = $width * $ratio;
255
-			}
250
+            if ($width === -1) {
251
+                $width = $height / $ratio;
252
+            }
253
+            if ($height === -1) {
254
+                $height = $width * $ratio;
255
+            }
256 256
 
257
-			$ratioH = $height / $maxHeight;
258
-			$ratioW = $width / $maxWidth;
257
+            $ratioH = $height / $maxHeight;
258
+            $ratioW = $width / $maxWidth;
259 259
 
260
-			/*
260
+            /*
261 261
 			 * Fill means that the $height and $width are the max
262 262
 			 * Cover means min.
263 263
 			 */
264
-			if ($mode === IPreview::MODE_FILL) {
265
-				if ($ratioH > $ratioW) {
266
-					$height = $width * $ratio;
267
-				} else {
268
-					$width = $height / $ratio;
269
-				}
270
-			} else if ($mode === IPreview::MODE_COVER) {
271
-				if ($ratioH > $ratioW) {
272
-					$width = $height / $ratio;
273
-				} else {
274
-					$height = $width * $ratio;
275
-				}
276
-			}
277
-		}
278
-
279
-		if ($height !== $maxHeight && $width !== $maxWidth) {
280
-			/*
264
+            if ($mode === IPreview::MODE_FILL) {
265
+                if ($ratioH > $ratioW) {
266
+                    $height = $width * $ratio;
267
+                } else {
268
+                    $width = $height / $ratio;
269
+                }
270
+            } else if ($mode === IPreview::MODE_COVER) {
271
+                if ($ratioH > $ratioW) {
272
+                    $width = $height / $ratio;
273
+                } else {
274
+                    $height = $width * $ratio;
275
+                }
276
+            }
277
+        }
278
+
279
+        if ($height !== $maxHeight && $width !== $maxWidth) {
280
+            /*
281 281
 			 * Scale to the nearest power of two
282 282
 			 */
283
-			$pow2height = 2 ** ceil(log($height) / log(2));
284
-			$pow2width = 2 ** ceil(log($width) / log(2));
285
-
286
-			$ratioH = $height / $pow2height;
287
-			$ratioW = $width / $pow2width;
288
-
289
-			if ($ratioH < $ratioW) {
290
-				$width = $pow2width;
291
-				$height /= $ratioW;
292
-			} else {
293
-				$height = $pow2height;
294
-				$width /= $ratioH;
295
-			}
296
-		}
297
-
298
-		/*
283
+            $pow2height = 2 ** ceil(log($height) / log(2));
284
+            $pow2width = 2 ** ceil(log($width) / log(2));
285
+
286
+            $ratioH = $height / $pow2height;
287
+            $ratioW = $width / $pow2width;
288
+
289
+            if ($ratioH < $ratioW) {
290
+                $width = $pow2width;
291
+                $height /= $ratioW;
292
+            } else {
293
+                $height = $pow2height;
294
+                $width /= $ratioH;
295
+            }
296
+        }
297
+
298
+        /*
299 299
  		 * Make sure the requested height and width fall within the max
300 300
  		 * of the preview.
301 301
  		 */
302
-		if ($height > $maxHeight) {
303
-			$ratio = $height / $maxHeight;
304
-			$height = $maxHeight;
305
-			$width /= $ratio;
306
-		}
307
-		if ($width > $maxWidth) {
308
-			$ratio = $width / $maxWidth;
309
-			$width = $maxWidth;
310
-			$height /= $ratio;
311
-		}
312
-
313
-		return [(int)round($width), (int)round($height)];
314
-	}
315
-
316
-	/**
317
-	 * @param ISimpleFolder $previewFolder
318
-	 * @param ISimpleFile $maxPreview
319
-	 * @param int $width
320
-	 * @param int $height
321
-	 * @param bool $crop
322
-	 * @param int $maxWidth
323
-	 * @param int $maxHeight
324
-	 * @return ISimpleFile
325
-	 * @throws NotFoundException
326
-	 * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
327
-	 */
328
-	private function generatePreview(ISimpleFolder $previewFolder, ISimpleFile $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight) {
329
-		$preview = $this->helper->getImage($maxPreview);
330
-
331
-		if (!$preview->valid()) {
332
-			throw new \InvalidArgumentException('Failed to generate preview, failed to load image');
333
-		}
334
-
335
-		if ($crop) {
336
-			if ($height !== $preview->height() && $width !== $preview->width()) {
337
-				//Resize
338
-				$widthR = $preview->width() / $width;
339
-				$heightR = $preview->height() / $height;
340
-
341
-				if ($widthR > $heightR) {
342
-					$scaleH = $height;
343
-					$scaleW = $maxWidth / $heightR;
344
-				} else {
345
-					$scaleH = $maxHeight / $widthR;
346
-					$scaleW = $width;
347
-				}
348
-				$preview->preciseResize(round($scaleW), round($scaleH));
349
-			}
350
-			$cropX = floor(abs($width - $preview->width()) * 0.5);
351
-			$cropY = 0;
352
-			$preview->crop($cropX, $cropY, $width, $height);
353
-		} else {
354
-			$preview->resize(max($width, $height));
355
-		}
356
-
357
-
358
-		$path = $this->generatePath($width, $height, $crop, $preview->dataMimeType());
359
-		try {
360
-			$file = $previewFolder->newFile($path);
361
-			$file->putContent($preview->data());
362
-		} catch (NotPermittedException $e) {
363
-			throw new NotFoundException();
364
-		}
365
-
366
-		return $file;
367
-	}
368
-
369
-	/**
370
-	 * @param ISimpleFolder $previewFolder
371
-	 * @param int $width
372
-	 * @param int $height
373
-	 * @param bool $crop
374
-	 * @param string $mimeType
375
-	 * @return ISimpleFile
376
-	 *
377
-	 * @throws NotFoundException
378
-	 */
379
-	private function getCachedPreview(ISimpleFolder $previewFolder, $width, $height, $crop, $mimeType) {
380
-		$path = $this->generatePath($width, $height, $crop, $mimeType);
381
-
382
-		return $previewFolder->getFile($path);
383
-	}
384
-
385
-	/**
386
-	 * Get the specific preview folder for this file
387
-	 *
388
-	 * @param File $file
389
-	 * @return ISimpleFolder
390
-	 */
391
-	private function getPreviewFolder(File $file) {
392
-		try {
393
-			$folder = $this->appData->getFolder($file->getId());
394
-		} catch (NotFoundException $e) {
395
-			$folder = $this->appData->newFolder($file->getId());
396
-		}
397
-
398
-		return $folder;
399
-	}
400
-
401
-	/**
402
-	 * @param string $mimeType
403
-	 * @return null|string
404
-	 * @throws \InvalidArgumentException
405
-	 */
406
-	private function getExtention($mimeType) {
407
-		switch ($mimeType) {
408
-			case 'image/png':
409
-				return 'png';
410
-			case 'image/jpeg':
411
-				return 'jpg';
412
-			case 'image/gif':
413
-				return 'gif';
414
-			default:
415
-				throw new \InvalidArgumentException('Not a valid mimetype');
416
-		}
417
-	}
302
+        if ($height > $maxHeight) {
303
+            $ratio = $height / $maxHeight;
304
+            $height = $maxHeight;
305
+            $width /= $ratio;
306
+        }
307
+        if ($width > $maxWidth) {
308
+            $ratio = $width / $maxWidth;
309
+            $width = $maxWidth;
310
+            $height /= $ratio;
311
+        }
312
+
313
+        return [(int)round($width), (int)round($height)];
314
+    }
315
+
316
+    /**
317
+     * @param ISimpleFolder $previewFolder
318
+     * @param ISimpleFile $maxPreview
319
+     * @param int $width
320
+     * @param int $height
321
+     * @param bool $crop
322
+     * @param int $maxWidth
323
+     * @param int $maxHeight
324
+     * @return ISimpleFile
325
+     * @throws NotFoundException
326
+     * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
327
+     */
328
+    private function generatePreview(ISimpleFolder $previewFolder, ISimpleFile $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight) {
329
+        $preview = $this->helper->getImage($maxPreview);
330
+
331
+        if (!$preview->valid()) {
332
+            throw new \InvalidArgumentException('Failed to generate preview, failed to load image');
333
+        }
334
+
335
+        if ($crop) {
336
+            if ($height !== $preview->height() && $width !== $preview->width()) {
337
+                //Resize
338
+                $widthR = $preview->width() / $width;
339
+                $heightR = $preview->height() / $height;
340
+
341
+                if ($widthR > $heightR) {
342
+                    $scaleH = $height;
343
+                    $scaleW = $maxWidth / $heightR;
344
+                } else {
345
+                    $scaleH = $maxHeight / $widthR;
346
+                    $scaleW = $width;
347
+                }
348
+                $preview->preciseResize(round($scaleW), round($scaleH));
349
+            }
350
+            $cropX = floor(abs($width - $preview->width()) * 0.5);
351
+            $cropY = 0;
352
+            $preview->crop($cropX, $cropY, $width, $height);
353
+        } else {
354
+            $preview->resize(max($width, $height));
355
+        }
356
+
357
+
358
+        $path = $this->generatePath($width, $height, $crop, $preview->dataMimeType());
359
+        try {
360
+            $file = $previewFolder->newFile($path);
361
+            $file->putContent($preview->data());
362
+        } catch (NotPermittedException $e) {
363
+            throw new NotFoundException();
364
+        }
365
+
366
+        return $file;
367
+    }
368
+
369
+    /**
370
+     * @param ISimpleFolder $previewFolder
371
+     * @param int $width
372
+     * @param int $height
373
+     * @param bool $crop
374
+     * @param string $mimeType
375
+     * @return ISimpleFile
376
+     *
377
+     * @throws NotFoundException
378
+     */
379
+    private function getCachedPreview(ISimpleFolder $previewFolder, $width, $height, $crop, $mimeType) {
380
+        $path = $this->generatePath($width, $height, $crop, $mimeType);
381
+
382
+        return $previewFolder->getFile($path);
383
+    }
384
+
385
+    /**
386
+     * Get the specific preview folder for this file
387
+     *
388
+     * @param File $file
389
+     * @return ISimpleFolder
390
+     */
391
+    private function getPreviewFolder(File $file) {
392
+        try {
393
+            $folder = $this->appData->getFolder($file->getId());
394
+        } catch (NotFoundException $e) {
395
+            $folder = $this->appData->newFolder($file->getId());
396
+        }
397
+
398
+        return $folder;
399
+    }
400
+
401
+    /**
402
+     * @param string $mimeType
403
+     * @return null|string
404
+     * @throws \InvalidArgumentException
405
+     */
406
+    private function getExtention($mimeType) {
407
+        switch ($mimeType) {
408
+            case 'image/png':
409
+                return 'png';
410
+            case 'image/jpeg':
411
+                return 'jpg';
412
+            case 'image/gif':
413
+                return 'gif';
414
+            default:
415
+                throw new \InvalidArgumentException('Not a valid mimetype');
416
+        }
417
+    }
418 418
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) {
92 92
 		$this->eventDispatcher->dispatch(
93 93
 			IPreview::EVENT,
94
-			new GenericEvent($file,[
94
+			new GenericEvent($file, [
95 95
 				'width' => $width,
96 96
 				'height' => $height,
97 97
 				'crop' => $crop,
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
 					continue;
169 169
 				}
170 170
 
171
-				$maxWidth = (int)$this->config->getSystemValue('preview_max_x', 4096);
172
-				$maxHeight = (int)$this->config->getSystemValue('preview_max_y', 4096);
171
+				$maxWidth = (int) $this->config->getSystemValue('preview_max_x', 4096);
172
+				$maxHeight = (int) $this->config->getSystemValue('preview_max_y', 4096);
173 173
 
174 174
 				$preview = $this->helper->getThumbnail($provider, $file, $maxWidth, $maxHeight);
175 175
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 					continue;
186 186
 				}
187 187
 
188
-				$path = (string)$preview->width() . '-' . (string)$preview->height() . '-max.' . $ext;
188
+				$path = (string) $preview->width().'-'.(string) $preview->height().'-max.'.$ext;
189 189
 				try {
190 190
 					$file = $previewFolder->newFile($path);
191 191
 					$file->putContent($preview->data());
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 	 */
207 207
 	private function getPreviewSize(ISimpleFile $file) {
208 208
 		$size = explode('-', $file->getName());
209
-		return [(int)$size[0], (int)$size[1]];
209
+		return [(int) $size[0], (int) $size[1]];
210 210
 	}
211 211
 
212 212
 	/**
@@ -217,13 +217,13 @@  discard block
 block discarded – undo
217 217
 	 * @return string
218 218
 	 */
219 219
 	private function generatePath($width, $height, $crop, $mimeType) {
220
-		$path = (string)$width . '-' . (string)$height;
220
+		$path = (string) $width.'-'.(string) $height;
221 221
 		if ($crop) {
222 222
 			$path .= '-crop';
223 223
 		}
224 224
 
225 225
 		$ext = $this->getExtention($mimeType);
226
-		$path .= '.' . $ext;
226
+		$path .= '.'.$ext;
227 227
 		return $path;
228 228
 	}
229 229
 
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 			$height /= $ratio;
311 311
 		}
312 312
 
313
-		return [(int)round($width), (int)round($height)];
313
+		return [(int) round($width), (int) round($height)];
314 314
 	}
315 315
 
316 316
 	/**
Please login to merge, or discard this patch.
settings/templates/users/part.userlist.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@  discard block
 block discarded – undo
1
-<table id="userlist" class="grid" data-groups="<?php p($_['allGroups']);?>">
1
+<table id="userlist" class="grid" data-groups="<?php p($_['allGroups']); ?>">
2 2
 	<thead>
3 3
 		<tr>
4 4
 			<th id="headerAvatar" scope="col"></th>
5 5
 			<th id="headerName" scope="col"><?php p($l->t('Username'))?></th>
6
-			<th id="headerDisplayName" scope="col"><?php p($l->t( 'Full name' )); ?></th>
7
-			<th id="headerPassword" scope="col"><?php p($l->t( 'Password' )); ?></th>
8
-			<th class="mailAddress" scope="col"><?php p($l->t( 'Email' )); ?></th>
9
-			<th id="headerGroups" scope="col"><?php p($l->t( 'Groups' )); ?></th>
10
-		<?php if(is_array($_['subadmins']) || $_['subadmins']): ?>
6
+			<th id="headerDisplayName" scope="col"><?php p($l->t('Full name')); ?></th>
7
+			<th id="headerPassword" scope="col"><?php p($l->t('Password')); ?></th>
8
+			<th class="mailAddress" scope="col"><?php p($l->t('Email')); ?></th>
9
+			<th id="headerGroups" scope="col"><?php p($l->t('Groups')); ?></th>
10
+		<?php if (is_array($_['subadmins']) || $_['subadmins']): ?>
11 11
 			<th id="headerSubAdmins" scope="col"><?php p($l->t('Group admin for')); ?></th>
12
-		<?php endif;?>
12
+		<?php endif; ?>
13 13
 			<th id="headerQuota" scope="col"><?php p($l->t('Quota')); ?></th>
14 14
 			<th class="storageLocation" scope="col"><?php p($l->t('Storage location')); ?></th>
15 15
 			<th class="userBackend" scope="col"><?php p($l->t('User backend')); ?></th>
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 						<span class="icon-triangle-s"></span>
46 46
 					</div>
47 47
 				</th>
48
-				<?php if((bool)$_['recoveryAdminEnabled']): ?>
48
+				<?php if ((bool) $_['recoveryAdminEnabled']): ?>
49 49
 				<th class="recoveryPassword">
50 50
 					<input id="recoveryPassword"
51 51
 						   type="password"
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 			<?php else: ?>
57 57
 				<th></th>
58 58
 			<?php endif; ?>
59
-			<?php if(is_array($_['subadmins']) || $_['subadmins']): ?>
59
+			<?php if (is_array($_['subadmins']) || $_['subadmins']): ?>
60 60
 				<th id="headerSubAdmins" scope="col"></th>
61
-			<?php endif;?>
61
+			<?php endif; ?>
62 62
 				<th class="headerQuota" scope="col"></th>
63 63
 				<th class="storageLocation" scope="col"></th>
64 64
 				<th class="userBackend" scope="col"></th>
@@ -90,26 +90,26 @@  discard block
 block discarded – undo
90 90
 			<td class="groups"><div class="groupsListContainer multiselect button"
91 91
 				><span class="title groupsList"></span><span class="icon-triangle-s"></span></div>
92 92
 			</td>
93
-		<?php if(is_array($_['subadmins']) || $_['subadmins']): ?>
93
+		<?php if (is_array($_['subadmins']) || $_['subadmins']): ?>
94 94
 			<td class="subadmins"><div class="groupsListContainer multiselect button"
95 95
 				><span class="title groupsList"></span><span class="icon-triangle-s"></span></div>
96 96
 			</td>
97
-		<?php endif;?>
97
+		<?php endif; ?>
98 98
 			<td class="quota">
99 99
 				<select class="quota-user" data-inputtitle="<?php p($l->t('Please enter storage quota (ex: "512 MB" or "12 GB")')) ?>">
100 100
 					<option	value='default'>
101
-						<?php p($l->t('Default'));?>
101
+						<?php p($l->t('Default')); ?>
102 102
 					</option>
103 103
 					<option value='none'>
104
-						<?php p($l->t('Unlimited'));?>
104
+						<?php p($l->t('Unlimited')); ?>
105 105
 					</option>
106
-					<?php foreach($_['quota_preset'] as $preset):?>
107
-						<option value='<?php p($preset);?>'>
108
-							<?php p($preset);?>
106
+					<?php foreach ($_['quota_preset'] as $preset):?>
107
+						<option value='<?php p($preset); ?>'>
108
+							<?php p($preset); ?>
109 109
 						</option>
110
-					<?php endforeach;?>
110
+					<?php endforeach; ?>
111 111
 					<option value='other' data-new>
112
-						<?php p($l->t('Other'));?> ...
112
+						<?php p($l->t('Other')); ?> ...
113 113
 					</option>
114 114
 				</select>
115 115
 				<progress class="quota-user-progress" value="" max="100"></progress>
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -53,9 +53,12 @@
 block discarded – undo
53 53
 						   title="<?php p($l->t('Enter the recovery password in order to recover the users files during password change'))?>"
54 54
 						   alt="<?php p($l->t('Enter the recovery password in order to recover the users files during password change'))?>"/>
55 55
 				</th>
56
-			<?php else: ?>
56
+			<?php else {
57
+    : ?>
57 58
 				<th></th>
58
-			<?php endif; ?>
59
+			<?php endif;
60
+}
61
+?>
59 62
 			<?php if(is_array($_['subadmins']) || $_['subadmins']): ?>
60 63
 				<th id="headerSubAdmins" scope="col"></th>
61 64
 			<?php endif;?>
Please login to merge, or discard this patch.