Passed
Push — master ( d85193...35e32d )
by smiley
02:17
created
src/ImagetilerOptionsTrait.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 
15 15
 use Imagick;
16 16
 
17
-trait ImagetilerOptionsTrait{
17
+trait ImagetilerOptionsTrait {
18 18
 
19 19
 	/**
20 20
 	 * width/height of a single tile
Please login to merge, or discard this patch.
src/ImagetilerException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,6 +12,6 @@
 block discarded – undo
12 12
 
13 13
 namespace chillerlan\Imagetiler;
14 14
 
15
-class ImagetilerException extends \Exception{
15
+class ImagetilerException extends \Exception {
16 16
 
17 17
 }
Please login to merge, or discard this patch.
src/ImagetilerOptions.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,6 +35,6 @@
 block discarded – undo
35 35
  * @property bool $clean_up
36 36
  * @property bool $optimize_output
37 37
  */
38
-class ImagetilerOptions extends ContainerAbstract{
38
+class ImagetilerOptions extends ContainerAbstract {
39 39
 	use ImagetilerOptionsTrait;
40 40
 }
Please login to merge, or discard this patch.
src/Imagetiler.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 use Imagick;
18 18
 use Psr\Log\{LoggerAwareInterface, LoggerAwareTrait, LoggerInterface, NullLogger};
19 19
 
20
-class Imagetiler implements LoggerAwareInterface{
20
+class Imagetiler implements LoggerAwareInterface {
21 21
 	use LoggerAwareTrait;
22 22
 
23 23
 	/**
@@ -39,16 +39,16 @@  discard block
 block discarded – undo
39 39
 	 *
40 40
 	 * @throws \chillerlan\Imagetiler\ImagetilerException
41 41
 	 */
42
-	public function __construct(ContainerInterface $options = null, Optimizer $optimizer = null, LoggerInterface $logger = null){
42
+	public function __construct(ContainerInterface $options = null, Optimizer $optimizer = null, LoggerInterface $logger = null) {
43 43
 
44
-		if(!extension_loaded('imagick')){
44
+		if (!extension_loaded('imagick')) {
45 45
 			throw new ImagetilerException('Imagick extension is not available');
46 46
 		}
47 47
 
48 48
 		$this->setOptions($options ?? new ImagetilerOptions);
49 49
 		$this->setLogger($logger ?? new NullLogger);
50 50
 
51
-		if($optimizer instanceof Optimizer){
51
+		if ($optimizer instanceof Optimizer) {
52 52
 			$this->setOptimizer($optimizer);
53 53
 		}
54 54
 	}
@@ -63,25 +63,25 @@  discard block
 block discarded – undo
63 63
 		$options->zoom_min = max(0, $options->zoom_min);
64 64
 		$options->zoom_max = max(1, $options->zoom_max);
65 65
 
66
-		if($options->zoom_normalize === null || $options->zoom_max < $options->zoom_normalize){
66
+		if ($options->zoom_normalize === null || $options->zoom_max < $options->zoom_normalize) {
67 67
 			$options->zoom_normalize = $options->zoom_max;
68 68
 		}
69 69
 
70
-		if($options->tile_ext === null){
70
+		if ($options->tile_ext === null) {
71 71
 			$options->tile_ext = $this->getExtension($options->tile_format);
72 72
 		}
73 73
 
74 74
 		$this->options = $options;
75 75
 
76
-		if(ini_set('memory_limit', $this->options->memory_limit) === false){
76
+		if (ini_set('memory_limit', $this->options->memory_limit) === false) {
77 77
 			throw new ImagetilerException('could not alter ini settings');
78 78
 		}
79 79
 
80
-		if(ini_get('memory_limit') !== (string)$this->options->memory_limit){
80
+		if (ini_get('memory_limit') !== (string)$this->options->memory_limit) {
81 81
 			throw new ImagetilerException('ini settings differ from options');
82 82
 		}
83 83
 
84
-		if($this->options->imagick_tmp !== null && is_dir($this->options->imagick_tmp)){
84
+		if ($this->options->imagick_tmp !== null && is_dir($this->options->imagick_tmp)) {
85 85
 			apache_setenv('MAGICK_TEMPORARY_PATH', $this->options->imagick_tmp);
86 86
 			putenv('MAGICK_TEMPORARY_PATH='.$this->options->imagick_tmp);
87 87
 		}
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 	 */
111 111
 	public function process(string $image_path, string $out_path):Imagetiler{
112 112
 
113
-		if(!is_file($image_path) || !is_readable($image_path)){
113
+		if (!is_file($image_path) || !is_readable($image_path)) {
114 114
 			throw new ImagetilerException('cannot read image '.$image_path);
115 115
 		}
116 116
 
117
-		if(!is_dir($out_path)|| !is_writable($out_path)){
117
+		if (!is_dir($out_path) || !is_writable($out_path)) {
118 118
 
119
-			if(!mkdir($out_path, 0755, true)){
119
+			if (!mkdir($out_path, 0755, true)) {
120 120
 				throw new ImagetilerException('output path is not writable');
121 121
 			}
122 122
 
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
 		$this->prepareZoomBaseImages($image_path, $out_path);
127 127
 
128 128
 		// create the tiles
129
-		for($zoom = $this->options->zoom_min; $zoom <= $this->options->zoom_max; $zoom++){
129
+		for ($zoom = $this->options->zoom_min; $zoom <= $this->options->zoom_max; $zoom++) {
130 130
 
131 131
 			$base_image = $out_path.'/'.$zoom.'.'.$this->options->tile_ext;
132 132
 
133 133
 			//load image
134
-			if(!is_file($base_image) || !is_readable($base_image)){
134
+			if (!is_file($base_image) || !is_readable($base_image)) {
135 135
 				throw new ImagetilerException('cannot read base image '.$base_image.' for zoom '.$zoom);
136 136
 			}
137 137
 
@@ -139,13 +139,13 @@  discard block
 block discarded – undo
139 139
 		}
140 140
 
141 141
 		// clean up base images
142
-		if($this->options->clean_up){
142
+		if ($this->options->clean_up) {
143 143
 
144
-			for($zoom = $this->options->zoom_min; $zoom <= $this->options->zoom_max; $zoom++){
144
+			for ($zoom = $this->options->zoom_min; $zoom <= $this->options->zoom_max; $zoom++) {
145 145
 				$lvl_file = $out_path.'/'.$zoom.'.'.$this->options->tile_ext;
146 146
 
147
-				if(is_file($lvl_file)){
148
-					if(unlink($lvl_file)){
147
+				if (is_file($lvl_file)) {
148
+					if (unlink($lvl_file)) {
149 149
 						$this->logger->info('deleted base image for zoom level '.$zoom.': '.$lvl_file);
150 150
 					}
151 151
 				}
@@ -174,16 +174,16 @@  discard block
 block discarded – undo
174 174
 		$start = true;
175 175
 		$il    = null;
176 176
 
177
-		for($zoom = $this->options->zoom_max; $zoom >= $this->options->zoom_min; $zoom--){
177
+		for ($zoom = $this->options->zoom_max; $zoom >= $this->options->zoom_min; $zoom--) {
178 178
 			$base_image = $out_path.'/'.$zoom.'.'.$this->options->tile_ext;
179 179
 
180 180
 			// check if the base image already exists
181
-			if(!$this->options->overwrite_base_image && is_file($base_image)){
181
+			if (!$this->options->overwrite_base_image && is_file($base_image)) {
182 182
 				$this->logger->info('base image for zoom level '.$zoom.' already exists: '.$base_image);
183 183
 				continue;
184 184
 			}
185 185
 
186
-			[$w, $h] = $this->getSize($width, $height, $zoom);
186
+			[ $w, $h ] = $this->getSize($width, $height, $zoom);
187 187
 
188 188
 			// fit main image to current zoom level
189 189
 			$il = $start ? clone $im : $il;
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 			// save without optimizing
198 198
 			$this->saveImage($il, $base_image, false);
199 199
 
200
-			if($start){
200
+			if ($start) {
201 201
 				$this->clearImage($im);
202 202
 			}
203 203
 
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 		$y = (int)ceil($h / $ts);
229 229
 
230 230
 		// width
231
-		for($ix = 0; $ix < $x; $ix++){
231
+		for ($ix = 0; $ix < $x; $ix++) {
232 232
 			$cx = $ix * $ts;
233 233
 
234 234
 			// create a stripe tile_size * height
@@ -236,11 +236,11 @@  discard block
 block discarded – undo
236 236
 			$ci->cropImage($ts, $h, $cx, 0);
237 237
 
238 238
 			// height
239
-			for($iy = 0; $iy < $y; $iy++){
239
+			for ($iy = 0; $iy < $y; $iy++) {
240 240
 				$tile = $out_path.'/'.sprintf($this->options->store_structure, $zoom, $ix, $iy).'.'.$this->options->tile_ext;
241 241
 
242 242
 				// check if tile already exists
243
-				if(!$this->options->overwrite_tile_image && is_file($tile)){
243
+				if (!$this->options->overwrite_tile_image && is_file($tile)) {
244 244
 					$this->logger->info('tile '.$zoom.'/'.$x.'/'.$y.' already exists: '.$tile);
245 245
 
246 246
 					continue;
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 				$ti->cropImage($ts, $ts, 0, $cy);
257 257
 
258 258
 				// check if the current tile is smaller than the tile size (leftover edges on the input image)
259
-				if($ti->getImageWidth() < $ts || $ti->getimageheight() < $ts){
259
+				if ($ti->getImageWidth() < $ts || $ti->getimageheight() < $ts) {
260 260
 
261 261
 					$th = $this->options->tms
262 262
 						? $im->getImageHeight() - $ts
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 			}
272 272
 
273 273
 			$this->clearImage($ci);
274
-			$this->logger->info('created column '.($ix+1).', x = '.$cx);
274
+			$this->logger->info('created column '.($ix + 1).', x = '.$cx);
275 275
 		}
276 276
 
277 277
 		$this->clearImage($im);
@@ -291,22 +291,22 @@  discard block
 block discarded – undo
291 291
 	protected function saveImage(Imagick $image, string $dest, bool $optimize):void{
292 292
 		$dir = dirname($dest);
293 293
 
294
-		if(!is_dir($dir)){
295
-			if(!mkdir($dir, 0755, true)){
294
+		if (!is_dir($dir)) {
295
+			if (!mkdir($dir, 0755, true)) {
296 296
 				throw new ImagetilerException('cannot crate folder '.$dir);
297 297
 			}
298 298
 		}
299 299
 
300
-		if($this->options->tile_format === 'jpeg'){
300
+		if ($this->options->tile_format === 'jpeg') {
301 301
 			$image->setCompression(Imagick::COMPRESSION_JPEG);
302 302
 			$image->setCompressionQuality($this->options->quality_jpeg);
303 303
 		}
304 304
 
305
-		if(!$image->writeImage($dest)){
305
+		if (!$image->writeImage($dest)) {
306 306
 			throw new ImagetilerException('cannot save image '.$dest);
307 307
 		}
308 308
 
309
-		if($this->options->optimize_output && $optimize && $this->optimizer instanceof Optimizer){
309
+		if ($this->options->optimize_output && $optimize && $this->optimizer instanceof Optimizer) {
310 310
 			$this->optimizer->optimize($dest);
311 311
 		}
312 312
 
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 	 */
322 322
 	protected function clearImage(Imagick $image = null):bool{
323 323
 
324
-		if($image instanceof Imagick){
324
+		if ($image instanceof Imagick) {
325 325
 			$image->clear();
326 326
 
327 327
 			return $image->destroy();
@@ -341,19 +341,19 @@  discard block
 block discarded – undo
341 341
 	 */
342 342
 	protected function getSize(int $width, int $height, int $zoom):array{
343 343
 
344
-		if($this->options->zoom_max > $this->options->zoom_normalize && $zoom > $this->options->zoom_normalize){
344
+		if ($this->options->zoom_max > $this->options->zoom_normalize && $zoom > $this->options->zoom_normalize) {
345 345
 			$zd = 2 ** ($zoom - $this->options->zoom_normalize);
346 346
 
347
-			return [$zd * $width, $zd * $height];
347
+			return [ $zd * $width, $zd * $height ];
348 348
 		}
349 349
 
350
-		if($zoom < $this->options->zoom_normalize){
350
+		if ($zoom < $this->options->zoom_normalize) {
351 351
 			$zd = 2 ** ($this->options->zoom_normalize - $zoom);
352 352
 
353
-			return [(int)round($width / $zd), (int)round($height / $zd)];
353
+			return [ (int)round($width / $zd), (int)round($height / $zd) ];
354 354
 		}
355 355
 
356
-		return [$width, $height];
356
+		return [ $width, $height ];
357 357
 	}
358 358
 
359 359
 	/**
@@ -366,11 +366,11 @@  discard block
 block discarded – undo
366 366
 	 */
367 367
 	protected function getExtension(string $format):string{
368 368
 
369
-		if(in_array($format, ['jpeg', 'jp2', 'jpc', 'jxr',], true)){
369
+		if (in_array($format, [ 'jpeg', 'jp2', 'jpc', 'jxr', ], true)) {
370 370
 			return 'jpg';
371 371
 		}
372 372
 
373
-		if(in_array($format, ['png', 'png00', 'png8', 'png24', 'png32', 'png64',], true)){
373
+		if (in_array($format, [ 'png', 'png00', 'png8', 'png24', 'png32', 'png64', ], true)) {
374 374
 			return 'png';
375 375
 		}
376 376
 
Please login to merge, or discard this patch.