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