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