@@ -14,7 +14,7 @@ |
||
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 |
@@ -33,6 +33,6 @@ |
||
33 | 33 | * @property bool $overwrite_tile_image |
34 | 34 | * @property bool $clean_up |
35 | 35 | */ |
36 | -class ImagetilerOptions extends ContainerAbstract{ |
|
36 | +class ImagetilerOptions extends ContainerAbstract { |
|
37 | 37 | use ImagetilerOptionsTrait; |
38 | 38 | } |
@@ -12,6 +12,6 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\Imagetiler; |
14 | 14 | |
15 | -class ImagetilerException extends \Exception{ |
|
15 | +class ImagetilerException extends \Exception { |
|
16 | 16 | |
17 | 17 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | use Imagick; |
17 | 17 | use Psr\Log\{LoggerAwareInterface, LoggerAwareTrait, LoggerInterface, NullLogger}; |
18 | 18 | |
19 | -class Imagetiler implements LoggerAwareInterface{ |
|
19 | +class Imagetiler implements LoggerAwareInterface { |
|
20 | 20 | use LoggerAwareTrait; |
21 | 21 | |
22 | 22 | /** |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @throws \chillerlan\Imagetiler\ImagetilerException |
39 | 39 | */ |
40 | - public function __construct(ContainerInterface $options = null, LoggerInterface $logger = null){ |
|
40 | + public function __construct(ContainerInterface $options = null, LoggerInterface $logger = null) { |
|
41 | 41 | |
42 | - if(!extension_loaded('imagick')){ |
|
42 | + if (!extension_loaded('imagick')) { |
|
43 | 43 | throw new ImagetilerException('Imagick extension is not available'); |
44 | 44 | } |
45 | 45 | |
@@ -58,21 +58,21 @@ discard block |
||
58 | 58 | $options->zoom_min = max(0, $options->zoom_min); |
59 | 59 | $options->zoom_max = max(1, $options->zoom_max); |
60 | 60 | |
61 | - if($options->zoom_normalize === null || $options->zoom_max < $options->zoom_normalize){ |
|
61 | + if ($options->zoom_normalize === null || $options->zoom_max < $options->zoom_normalize) { |
|
62 | 62 | $options->zoom_normalize = $options->zoom_max; |
63 | 63 | } |
64 | 64 | |
65 | 65 | $this->options = $options; |
66 | 66 | |
67 | - if(ini_set('memory_limit', $this->options->memory_limit) === false){ |
|
67 | + if (ini_set('memory_limit', $this->options->memory_limit) === false) { |
|
68 | 68 | throw new ImagetilerException('could not alter ini settings'); |
69 | 69 | } |
70 | 70 | |
71 | - if(ini_get('memory_limit') !== (string)$this->options->memory_limit){ |
|
71 | + if (ini_get('memory_limit') !== (string)$this->options->memory_limit) { |
|
72 | 72 | throw new ImagetilerException('ini settings differ from options'); |
73 | 73 | } |
74 | 74 | |
75 | - if($this->options->imagick_tmp !== null && is_dir($this->options->imagick_tmp)){ |
|
75 | + if ($this->options->imagick_tmp !== null && is_dir($this->options->imagick_tmp)) { |
|
76 | 76 | apache_setenv('MAGICK_TEMPORARY_PATH', $this->options->imagick_tmp); |
77 | 77 | putenv('MAGICK_TEMPORARY_PATH='.$this->options->imagick_tmp); |
78 | 78 | } |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function process(string $image_path, string $out_path):Imagetiler{ |
93 | 93 | |
94 | - if(!is_file($image_path) || !is_readable($image_path)){ |
|
94 | + if (!is_file($image_path) || !is_readable($image_path)) { |
|
95 | 95 | throw new ImagetilerException('cannot read image '.$image_path); |
96 | 96 | } |
97 | 97 | |
98 | - if(!is_dir($out_path)|| !is_writable($out_path)){ |
|
98 | + if (!is_dir($out_path) || !is_writable($out_path)) { |
|
99 | 99 | |
100 | - if(!mkdir($out_path, 0755, true)){ |
|
100 | + if (!mkdir($out_path, 0755, true)) { |
|
101 | 101 | throw new ImagetilerException('output path is not writable'); |
102 | 102 | } |
103 | 103 | |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | $this->prepareZoomBaseImages($image_path, $out_path); |
108 | 108 | |
109 | 109 | // create tiles for each zoom level |
110 | - for($i = $this->options->zoom_min; $i <= $this->options->zoom_max; $i++){ |
|
110 | + for ($i = $this->options->zoom_min; $i <= $this->options->zoom_max; $i++) { |
|
111 | 111 | $this->createTilesForZoom($out_path, $i); |
112 | 112 | } |
113 | 113 | |
114 | 114 | // clean up base images |
115 | - if($this->options->clean_up){ |
|
115 | + if ($this->options->clean_up) { |
|
116 | 116 | $this->removeZoomBaseImages($out_path); |
117 | 117 | } |
118 | 118 | |
@@ -141,16 +141,16 @@ discard block |
||
141 | 141 | $start = true; |
142 | 142 | $il = null; |
143 | 143 | |
144 | - for($zoom = $this->options->zoom_max; $zoom >= $this->options->zoom_min; $zoom--){ |
|
144 | + for ($zoom = $this->options->zoom_max; $zoom >= $this->options->zoom_min; $zoom--) { |
|
145 | 145 | $base_image = $out_path.'/'.$zoom.'.'.$this->ext; |
146 | 146 | |
147 | 147 | //check if already exist |
148 | - if(!$this->options->overwrite_base_image && is_file($base_image)){ |
|
148 | + if (!$this->options->overwrite_base_image && is_file($base_image)) { |
|
149 | 149 | $this->logger->info('base image for zoom level '.$zoom.' already exists: '.$base_image); |
150 | 150 | continue; |
151 | 151 | } |
152 | 152 | |
153 | - [$w, $h] = $this->getSize($width, $height, $zoom); |
|
153 | + [ $w, $h ] = $this->getSize($width, $height, $zoom); |
|
154 | 154 | |
155 | 155 | //fit main image to current zoom lvl |
156 | 156 | $il = $start ? clone $im : $il; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | $this->imageSave($il, $base_image); |
166 | 166 | |
167 | 167 | //clear |
168 | - if($start){ |
|
168 | + if ($start) { |
|
169 | 169 | $im->clear(); |
170 | 170 | $im->destroy(); |
171 | 171 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | //free resurce, destroy imagick object |
178 | - if($il instanceof Imagick){ |
|
178 | + if ($il instanceof Imagick) { |
|
179 | 179 | $il->clear(); |
180 | 180 | $il->destroy(); |
181 | 181 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | $base_image = $out_path.'/'.$zoom.'.'.$this->ext; |
193 | 193 | |
194 | 194 | //load image |
195 | - if(!is_file($base_image) || !is_readable($base_image)){ |
|
195 | + if (!is_file($base_image) || !is_readable($base_image)) { |
|
196 | 196 | throw new ImagetilerException('cannot read base image '.$base_image.' for zoom '.$zoom); |
197 | 197 | } |
198 | 198 | |
@@ -208,15 +208,15 @@ discard block |
||
208 | 208 | $y = (int)ceil($h / $ts); |
209 | 209 | |
210 | 210 | // width |
211 | - for($ix = 0; $ix < $x; $ix++){ |
|
211 | + for ($ix = 0; $ix < $x; $ix++) { |
|
212 | 212 | $cx = $ix * $ts; |
213 | 213 | |
214 | 214 | // height |
215 | - for($iy = 0; $iy < $y; $iy++){ |
|
215 | + for ($iy = 0; $iy < $y; $iy++) { |
|
216 | 216 | $tile = $out_path.'/'.sprintf($this->options->store_structure, $zoom, $ix, $iy).'.'.$this->ext; |
217 | 217 | |
218 | 218 | // check if tile already exists |
219 | - if(!$this->options->overwrite_tile_image && is_file($tile)){ |
|
219 | + if (!$this->options->overwrite_tile_image && is_file($tile)) { |
|
220 | 220 | $this->logger->info('tile '.$zoom.'/'.$x.'/'.$y.' already exists: '.$tile); |
221 | 221 | |
222 | 222 | continue; |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | $ti->cropImage($ts, $ts, $cx, $cy); |
232 | 232 | |
233 | 233 | // check if the current tile is smaller than the tile size (leftover edges on the input image) |
234 | - if($ti->getImageWidth() < $ts || $ti->getimageheight() < $ts){ |
|
234 | + if ($ti->getImageWidth() < $ts || $ti->getimageheight() < $ts) { |
|
235 | 235 | |
236 | 236 | $th = $this->options->tms |
237 | 237 | ? $im->getImageHeight() - $ts |
@@ -265,11 +265,11 @@ discard block |
||
265 | 265 | */ |
266 | 266 | protected function removeZoomBaseImages(string $out_path):void{ |
267 | 267 | |
268 | - for($i = $this->options->zoom_min; $i <= $this->options->zoom_max; $i++){ |
|
268 | + for ($i = $this->options->zoom_min; $i <= $this->options->zoom_max; $i++) { |
|
269 | 269 | $lvl_file = $out_path.'/'.$i.'.'.$this->ext; |
270 | 270 | |
271 | - if(is_file($lvl_file)){ |
|
272 | - if(unlink($lvl_file)){ |
|
271 | + if (is_file($lvl_file)) { |
|
272 | + if (unlink($lvl_file)) { |
|
273 | 273 | $this->logger->info('deleted base image for zoom level '.$i.': '.$lvl_file); |
274 | 274 | } |
275 | 275 | } |
@@ -291,20 +291,20 @@ discard block |
||
291 | 291 | //prepare folder |
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 | 300 | //prepare to save |
301 | - if($this->options->tile_format === 'jpeg'){ |
|
301 | + if ($this->options->tile_format === 'jpeg') { |
|
302 | 302 | $image->setCompression(Imagick::COMPRESSION_JPEG); |
303 | 303 | $image->setCompressionQuality($this->options->quality_jpeg); |
304 | 304 | } |
305 | 305 | |
306 | 306 | //save image |
307 | - if(!$image->writeImage($dest)){ |
|
307 | + if (!$image->writeImage($dest)) { |
|
308 | 308 | throw new ImagetilerException('cannot save image '.$dest); |
309 | 309 | } |
310 | 310 | |
@@ -320,19 +320,19 @@ discard block |
||
320 | 320 | */ |
321 | 321 | protected function getSize(int $width, int $height, int $zoom):array{ |
322 | 322 | |
323 | - if($this->options->zoom_max > $this->options->zoom_normalize && $zoom > $this->options->zoom_normalize){ |
|
323 | + if ($this->options->zoom_max > $this->options->zoom_normalize && $zoom > $this->options->zoom_normalize) { |
|
324 | 324 | $zd = 2 ** ($zoom - $this->options->zoom_normalize); |
325 | 325 | |
326 | - return [$zd * $width, $zd * $height]; |
|
326 | + return [ $zd * $width, $zd * $height ]; |
|
327 | 327 | } |
328 | 328 | |
329 | - if($zoom < $this->options->zoom_normalize){ |
|
329 | + if ($zoom < $this->options->zoom_normalize) { |
|
330 | 330 | $zd = 2 ** ($this->options->zoom_normalize - $zoom); |
331 | 331 | |
332 | - return [(int)round($width / $zd), (int)round($height / $zd)]; |
|
332 | + return [ (int)round($width / $zd), (int)round($height / $zd) ]; |
|
333 | 333 | } |
334 | 334 | |
335 | - return [$width, $height]; |
|
335 | + return [ $width, $height ]; |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
@@ -344,12 +344,12 @@ discard block |
||
344 | 344 | protected function getExtension():string{ |
345 | 345 | $fmt = strtolower($this->options->tile_format); |
346 | 346 | |
347 | - if(in_array($fmt, ['jpeg', 'jp2', 'jpc', 'jxr',], true)){ |
|
347 | + if (in_array($fmt, [ 'jpeg', 'jp2', 'jpc', 'jxr', ], true)) { |
|
348 | 348 | return 'jpg'; |
349 | 349 | } |
350 | 350 | |
351 | - if(in_array( |
|
352 | - $fmt, ['png', 'png00', 'png8', 'png24', 'png32', 'png64',], true)){ |
|
351 | + if (in_array( |
|
352 | + $fmt, [ 'png', 'png00', 'png8', 'png24', 'png32', 'png64', ], true)) { |
|
353 | 353 | return 'png'; |
354 | 354 | } |
355 | 355 |