Passed
Branch main (03e511)
by smiley
11:51
created
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
@@ -38,6 +38,6 @@
 block discarded – undo
38 38
  * @property bool $optimize_output
39 39
  * @property bool $no_temp_baseimages
40 40
  */
41
-class ImagetilerOptions extends SettingsContainerAbstract{
41
+class ImagetilerOptions extends SettingsContainerAbstract {
42 42
 	use ImagetilerOptionsTrait;
43 43
 }
Please login to merge, or discard this patch.
src/ImagetilerOptionsTrait.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
 use function in_array, max, strtolower;
18 18
 
19
-trait ImagetilerOptionsTrait{
19
+trait ImagetilerOptionsTrait {
20 20
 
21 21
 	/**
22 22
 	 * width/height of a single tile
@@ -213,11 +213,11 @@  discard block
 block discarded – undo
213 213
 	protected function getExtension(string $format):string{
214 214
 		$format = strtolower($format);
215 215
 
216
-		if(in_array($format, ['jpeg', 'jp2', 'jpc', 'jxr'], true)){
216
+		if (in_array($format, [ 'jpeg', 'jp2', 'jpc', 'jxr' ], true)) {
217 217
 			return 'jpg';
218 218
 		}
219 219
 
220
-		if(in_array($format, ['png', 'png00', 'png8', 'png24', 'png32', 'png64'], true)){
220
+		if (in_array($format, [ 'png', 'png00', 'png8', 'png24', 'png32', 'png64' ], true)) {
221 221
 			return 'png';
222 222
 		}
223 223
 
Please login to merge, or discard this patch.
src/Imagetiler.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -191,8 +191,7 @@
 block discarded – undo
191 191
 
192 192
 			if($zoom > $this->options->zoom_normalize){
193 193
 				$this->scale($il, $w, $h, $this->options->fast_resize_upsample, $this->options->resize_filter_upsample, $this->options->resize_blur_upsample);
194
-			}
195
-			elseif($zoom < $this->options->zoom_normalize){
194
+			} elseif($zoom < $this->options->zoom_normalize){
196 195
 				$this->scale($il, $w, $h, $this->options->fast_resize_downsample, $this->options->resize_filter_downsample, $this->options->resize_blur_downsample);
197 196
 			}
198 197
 
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 use function ceil, dirname, extension_loaded, file_exists, ini_get, ini_set, is_dir,
19 19
 	is_file, is_readable, is_writable, mkdir, round, sprintf, unlink;
20 20
 
21
-class Imagetiler implements LoggerAwareInterface{
21
+class Imagetiler implements LoggerAwareInterface {
22 22
 	use LoggerAwareTrait;
23 23
 
24 24
 	/** @var \chillerlan\Imagetiler\ImagetilerOptions */
@@ -30,16 +30,16 @@  discard block
 block discarded – undo
30 30
 	 *
31 31
 	 * @throws \chillerlan\Imagetiler\ImagetilerException
32 32
 	 */
33
-	public function __construct(SettingsContainerInterface $options = null, Optimizer $optimizer = null, LoggerInterface $logger = null){
33
+	public function __construct(SettingsContainerInterface $options = null, Optimizer $optimizer = null, LoggerInterface $logger = null) {
34 34
 
35
-		if(!extension_loaded('imagick')){
35
+		if (!extension_loaded('imagick')) {
36 36
 			throw new ImagetilerException('Imagick extension is not available');
37 37
 		}
38 38
 
39 39
 		$this->setOptions($options ?? new ImagetilerOptions);
40 40
 		$this->setLogger($logger ?? new NullLogger);
41 41
 
42
-		if($optimizer instanceof Optimizer){
42
+		if ($optimizer instanceof Optimizer) {
43 43
 			$this->setOptimizer($optimizer);
44 44
 		}
45 45
 	}
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 	public function setOptions(SettingsContainerInterface $options):Imagetiler{
51 51
 		$this->options = $options;
52 52
 
53
-		if(ini_set('memory_limit', $this->options->memory_limit) === false){
53
+		if (ini_set('memory_limit', $this->options->memory_limit) === false) {
54 54
 			throw new ImagetilerException('could not alter ini settings');
55 55
 		}
56 56
 
57
-		if(ini_get('memory_limit') !== $this->options->memory_limit){
57
+		if (ini_get('memory_limit') !== $this->options->memory_limit) {
58 58
 			throw new ImagetilerException('ini settings differ from options');
59 59
 		}
60 60
 
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
 	 */
75 75
 	public function process(string $image_path, string $out_path):Imagetiler{
76 76
 
77
-		if(!file_exists($image_path) || !is_file($image_path) || !is_readable($image_path)){
77
+		if (!file_exists($image_path) || !is_file($image_path) || !is_readable($image_path)) {
78 78
 			throw new ImagetilerException('cannot read image '.$image_path);
79 79
 		}
80 80
 
81
-		if(!file_exists($out_path) || !is_dir($out_path) || !is_writable($out_path)){
81
+		if (!file_exists($out_path) || !is_dir($out_path) || !is_writable($out_path)) {
82 82
 
83
-			if(!mkdir($out_path, 0755, true)){
83
+			if (!mkdir($out_path, 0755, true)) {
84 84
 				throw new ImagetilerException('output path is not writable');
85 85
 			}
86 86
 
@@ -92,15 +92,15 @@  discard block
 block discarded – undo
92 92
 		$base_images = $this->prepareZoomBaseImages($image_path, $out_path);
93 93
 
94 94
 		// if no temp images are requested, exit here as the processing was handled already
95
-		if($this->options->no_temp_baseimages === true){
95
+		if ($this->options->no_temp_baseimages === true) {
96 96
 			return $this;
97 97
 		}
98 98
 
99 99
 		// create the tiles
100
-		foreach($base_images as $zoom => $base_image){
100
+		foreach ($base_images as $zoom => $base_image) {
101 101
 
102 102
 			//load image
103
-			if(!is_file($base_image) || !is_readable($base_image)){
103
+			if (!is_file($base_image) || !is_readable($base_image)) {
104 104
 				throw new ImagetilerException('cannot read base image '.$base_image.' for zoom '.$zoom);
105 105
 			}
106 106
 
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
 		}
109 109
 
110 110
 		// clean up base images
111
-		if($this->options->clean_up){
111
+		if ($this->options->clean_up) {
112 112
 
113
-			for($zoom = $this->options->zoom_min; $zoom <= $this->options->zoom_max; $zoom++){
113
+			for ($zoom = $this->options->zoom_min; $zoom <= $this->options->zoom_max; $zoom++) {
114 114
 				$lvl_file = $out_path.'/'.$zoom.'.'.$this->options->tile_ext;
115 115
 
116
-				if(is_file($lvl_file)){
117
-					if(unlink($lvl_file)){
116
+				if (is_file($lvl_file)) {
117
+					if (unlink($lvl_file)) {
118 118
 						$this->logger->info('deleted base image for zoom level '.$zoom.': '.$lvl_file);
119 119
 					}
120 120
 				}
@@ -129,23 +129,23 @@  discard block
 block discarded – undo
129 129
 	 * prepare base images for each zoom level
130 130
 	 */
131 131
 	protected function prepareZoomBaseImages(string $image_path, string $out_path):array{
132
-		$base_images = [];
132
+		$base_images = [ ];
133 133
 
134 134
 		// create base image file names
135
-		for($zoom = $this->options->zoom_max; $zoom >= $this->options->zoom_min; $zoom--){
135
+		for ($zoom = $this->options->zoom_max; $zoom >= $this->options->zoom_min; $zoom--) {
136 136
 			$base_image = $out_path.'/'.$zoom.'.'.$this->options->tile_ext;
137 137
 			// check if the base image already exists
138
-			if(!$this->options->overwrite_base_image && is_file($base_image)){
138
+			if (!$this->options->overwrite_base_image && is_file($base_image)) {
139 139
 				$this->logger->info('base image for zoom level '.$zoom.' already exists: '.$base_image);
140 140
 
141 141
 				continue;
142 142
 			}
143 143
 
144
-			$base_images[$zoom] = $base_image;
144
+			$base_images[ $zoom ] = $base_image;
145 145
 		}
146 146
 
147
-		if(empty($base_images)){
148
-			return [];
147
+		if (empty($base_images)) {
148
+			return [ ];
149 149
 		}
150 150
 
151 151
 		$im = new Imagick($image_path);
@@ -157,16 +157,16 @@  discard block
 block discarded – undo
157 157
 
158 158
 		$this->logger->info('input image loaded: ['.$width.'x'.$height.'] '.$image_path);
159 159
 
160
-		foreach($base_images as $zoom => $base_image){
161
-			[$w, $h] = $this->getSize($width, $height, $zoom);
160
+		foreach ($base_images as $zoom => $base_image) {
161
+			[ $w, $h ] = $this->getSize($width, $height, $zoom);
162 162
 
163 163
 			// clone the original image and fit it to the current zoom level
164 164
 			$il = clone $im;
165 165
 
166
-			if($zoom > $this->options->zoom_normalize){
166
+			if ($zoom > $this->options->zoom_normalize) {
167 167
 				$this->scale($il, $w, $h, $this->options->fast_resize_upsample, $this->options->resize_filter_upsample, $this->options->resize_blur_upsample);
168 168
 			}
169
-			elseif($zoom < $this->options->zoom_normalize){
169
+			elseif ($zoom < $this->options->zoom_normalize) {
170 170
 				$this->scale($il, $w, $h, $this->options->fast_resize_downsample, $this->options->resize_filter_downsample, $this->options->resize_blur_downsample);
171 171
 			}
172 172
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 		$y  = (int)ceil($h / $ts);
207 207
 
208 208
 		// width
209
-		for($ix = 0; $ix < $x; $ix++){
209
+		for ($ix = 0; $ix < $x; $ix++) {
210 210
 			$cx = $ix * $ts;
211 211
 
212 212
 			// create a stripe tile_size * height
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
 			$ci->cropImage($ts, $h, $cx, 0);
215 215
 
216 216
 			// height
217
-			for($iy = 0; $iy < $y; $iy++){
217
+			for ($iy = 0; $iy < $y; $iy++) {
218 218
 				$tile = $out_path.'/'.sprintf($this->options->store_structure, $zoom, $ix, $iy).'.'.$this->options->tile_ext;
219 219
 
220 220
 				// check if tile already exists
221
-				if(!$this->options->overwrite_tile_image && is_file($tile)){
221
+				if (!$this->options->overwrite_tile_image && is_file($tile)) {
222 222
 					$this->logger->info('tile '.$zoom.'/'.$ix.'/'.$iy.' already exists: '.$tile);
223 223
 
224 224
 					continue;
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 				$ti->cropImage($ts, $ts, 0, $cy);
235 235
 
236 236
 				// check if the current tile is smaller than the tile size (leftover edges on the input image)
237
-				if($ti->getImageWidth() < $ts || $ti->getimageheight() < $ts){
237
+				if ($ti->getImageWidth() < $ts || $ti->getimageheight() < $ts) {
238 238
 
239 239
 					$th = $this->options->tms ? $h - $ts : 0;
240 240
 
@@ -262,22 +262,22 @@  discard block
 block discarded – undo
262 262
 	protected function saveImage(Imagick $image, string $dest, bool $optimize):void{
263 263
 		$dir = dirname($dest);
264 264
 
265
-		if(!file_exists($dir) || !is_dir($dir)){
266
-			if(!mkdir($dir, 0755, true)){
265
+		if (!file_exists($dir) || !is_dir($dir)) {
266
+			if (!mkdir($dir, 0755, true)) {
267 267
 				throw new ImagetilerException('cannot create folder '.$dir);
268 268
 			}
269 269
 		}
270 270
 
271
-		if($this->options->tile_format === 'jpeg'){
271
+		if ($this->options->tile_format === 'jpeg') {
272 272
 			$image->setCompression(Imagick::COMPRESSION_JPEG2000);
273 273
 			$image->setCompressionQuality($this->options->quality_jpeg);
274 274
 		}
275 275
 
276
-		if(!$image->writeImage($dest)){
276
+		if (!$image->writeImage($dest)) {
277 277
 			throw new ImagetilerException('cannot save image '.$dest);
278 278
 		}
279 279
 
280
-		if($this->options->optimize_output && $optimize && $this->optimizer instanceof Optimizer){
280
+		if ($this->options->optimize_output && $optimize && $this->optimizer instanceof Optimizer) {
281 281
 			$this->optimizer->optimize($dest);
282 282
 		}
283 283
 
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 	 */
289 289
 	protected function clearImage(Imagick $image = null):bool{
290 290
 
291
-		if($image instanceof Imagick){
291
+		if ($image instanceof Imagick) {
292 292
 			$image->clear();
293 293
 
294 294
 			return $image->destroy();
@@ -305,19 +305,19 @@  discard block
 block discarded – undo
305 305
 	protected function getSize(int $width, int $height, int $zoom):array{
306 306
 		$zoom_normalize = $this->options->zoom_normalize ?? $this->options->zoom_max;
307 307
 
308
-		if($this->options->zoom_max > $zoom_normalize && $zoom > $zoom_normalize){
308
+		if ($this->options->zoom_max > $zoom_normalize && $zoom > $zoom_normalize) {
309 309
 			$zd = 2 ** ($zoom - $zoom_normalize);
310 310
 
311
-			return [$zd * $width, $zd * $height];
311
+			return [ $zd * $width, $zd * $height ];
312 312
 		}
313 313
 
314
-		if($zoom < $zoom_normalize){
314
+		if ($zoom < $zoom_normalize) {
315 315
 			$zd = 2 ** ($zoom_normalize - $zoom);
316 316
 
317
-			return [(int)round($width / $zd), (int)round($height / $zd)];
317
+			return [ (int)round($width / $zd), (int)round($height / $zd) ];
318 318
 		}
319 319
 
320
-		return [$width, $height];
320
+		return [ $width, $height ];
321 321
 	}
322 322
 
323 323
 }
Please login to merge, or discard this patch.
examples/imagetiler.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 
51 51
 $options = new ImagetilerOptions($options);
52 52
 
53
-$logger = new class() extends AbstractLogger{
54
-	public function log($level, $message, array $context = []){
53
+$logger = new class() extends AbstractLogger {
54
+	public function log($level, $message, array $context = [ ]) {
55 55
 		echo sprintf('[%s][%s] %s', date('Y-m-d H:i:s'), substr($level, 0, 4), trim($message))."\n";
56 56
 	}
57 57
 };
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
 $optimizer = (new OptimizerFactory($optimizer_settings, $logger))->get($options->tile_format);
60 60
 $tiler     = new Imagetiler($options, $optimizer, $logger);
61 61
 
62
-try{
62
+try {
63 63
 	$tiler->process($input, __DIR__.'/tiles');
64 64
 }
65
-catch(ImagetilerException $e){
65
+catch (ImagetilerException $e) {
66 66
 	$logger->error($e->getMessage());
67 67
 	$logger->error($e->getTraceAsString());
68 68
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -61,8 +61,7 @@
 block discarded – undo
61 61
 
62 62
 try{
63 63
 	$tiler->process($input, __DIR__.'/tiles');
64
-}
65
-catch(ImagetilerException $e){
64
+} catch(ImagetilerException $e){
66 65
 	$logger->error($e->getMessage());
67 66
 	$logger->error($e->getTraceAsString());
68 67
 }
Please login to merge, or discard this patch.