@@ -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 | } |
@@ -35,6 +35,6 @@ |
||
35 | 35 | * @property bool $clean_up |
36 | 36 | * @property bool $optimize_output |
37 | 37 | */ |
38 | -class ImagetilerOptions extends SettingsContainerAbstract{ |
|
38 | +class ImagetilerOptions extends SettingsContainerAbstract { |
|
39 | 39 | use ImagetilerOptionsTrait; |
40 | 40 | } |
@@ -14,7 +14,7 @@ discard block |
||
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 |
@@ -155,15 +155,15 @@ discard block |
||
155 | 155 | /** |
156 | 156 | * "constructor" |
157 | 157 | */ |
158 | - public function ImagetilerOptionsTrait(){ |
|
158 | + public function ImagetilerOptionsTrait() { |
|
159 | 159 | $this->zoom_min = max(0, $this->zoom_min); |
160 | 160 | $this->zoom_max = max(1, $this->zoom_max); |
161 | 161 | |
162 | - if($this->zoom_normalize === null || $this->zoom_max < $this->zoom_normalize){ |
|
162 | + if ($this->zoom_normalize === null || $this->zoom_max < $this->zoom_normalize) { |
|
163 | 163 | $this->zoom_normalize = $this->zoom_max; |
164 | 164 | } |
165 | 165 | |
166 | - if($this->tile_ext === null){ |
|
166 | + if ($this->tile_ext === null) { |
|
167 | 167 | $this->tile_ext = $this->getExtension($this->tile_format); |
168 | 168 | } |
169 | 169 | |
@@ -179,11 +179,11 @@ discard block |
||
179 | 179 | */ |
180 | 180 | protected function getExtension(string $format):string{ |
181 | 181 | |
182 | - if(in_array($format, ['jpeg', 'jp2', 'jpc', 'jxr',], true)){ |
|
182 | + if (in_array($format, [ 'jpeg', 'jp2', 'jpc', 'jxr', ], true)) { |
|
183 | 183 | return 'jpg'; |
184 | 184 | } |
185 | 185 | |
186 | - if(in_array($format, ['png', 'png00', 'png8', 'png24', 'png32', 'png64',], true)){ |
|
186 | + if (in_array($format, [ 'png', 'png00', 'png8', 'png24', 'png32', 'png64', ], true)) { |
|
187 | 187 | return 'png'; |
188 | 188 | } |
189 | 189 |
@@ -17,7 +17,7 @@ discard block |
||
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 |
||
39 | 39 | * |
40 | 40 | * @throws \chillerlan\Imagetiler\ImagetilerException |
41 | 41 | */ |
42 | - public function __construct(SettingsContainerInterface $options = null, Optimizer $optimizer = null, LoggerInterface $logger = null){ |
|
42 | + public function __construct(SettingsContainerInterface $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 | } |
@@ -62,15 +62,15 @@ discard block |
||
62 | 62 | public function setOptions(SettingsContainerInterface $options):Imagetiler{ |
63 | 63 | $this->options = $options; |
64 | 64 | |
65 | - if(ini_set('memory_limit', $this->options->memory_limit) === false){ |
|
65 | + if (ini_set('memory_limit', $this->options->memory_limit) === false) { |
|
66 | 66 | throw new ImagetilerException('could not alter ini settings'); |
67 | 67 | } |
68 | 68 | |
69 | - if(ini_get('memory_limit') !== (string)$this->options->memory_limit){ |
|
69 | + if (ini_get('memory_limit') !== (string)$this->options->memory_limit) { |
|
70 | 70 | throw new ImagetilerException('ini settings differ from options'); |
71 | 71 | } |
72 | 72 | |
73 | - if($this->options->imagick_tmp !== null && is_dir($this->options->imagick_tmp)){ |
|
73 | + if ($this->options->imagick_tmp !== null && is_dir($this->options->imagick_tmp)) { |
|
74 | 74 | apache_setenv('MAGICK_TEMPORARY_PATH', $this->options->imagick_tmp); |
75 | 75 | putenv('MAGICK_TEMPORARY_PATH='.$this->options->imagick_tmp); |
76 | 76 | } |
@@ -98,13 +98,13 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function process(string $image_path, string $out_path):Imagetiler{ |
100 | 100 | |
101 | - if(!is_file($image_path) || !is_readable($image_path)){ |
|
101 | + if (!is_file($image_path) || !is_readable($image_path)) { |
|
102 | 102 | throw new ImagetilerException('cannot read image '.$image_path); |
103 | 103 | } |
104 | 104 | |
105 | - if(!is_dir($out_path)|| !is_writable($out_path)){ |
|
105 | + if (!is_dir($out_path) || !is_writable($out_path)) { |
|
106 | 106 | |
107 | - if(!mkdir($out_path, 0755, true)){ |
|
107 | + if (!mkdir($out_path, 0755, true)) { |
|
108 | 108 | throw new ImagetilerException('output path is not writable'); |
109 | 109 | } |
110 | 110 | |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | $this->prepareZoomBaseImages($image_path, $out_path); |
115 | 115 | |
116 | 116 | // create the tiles |
117 | - for($zoom = $this->options->zoom_min; $zoom <= $this->options->zoom_max; $zoom++){ |
|
117 | + for ($zoom = $this->options->zoom_min; $zoom <= $this->options->zoom_max; $zoom++) { |
|
118 | 118 | |
119 | 119 | $base_image = $out_path.'/'.$zoom.'.'.$this->options->tile_ext; |
120 | 120 | |
121 | 121 | //load image |
122 | - if(!is_file($base_image) || !is_readable($base_image)){ |
|
122 | + if (!is_file($base_image) || !is_readable($base_image)) { |
|
123 | 123 | throw new ImagetilerException('cannot read base image '.$base_image.' for zoom '.$zoom); |
124 | 124 | } |
125 | 125 | |
@@ -127,13 +127,13 @@ discard block |
||
127 | 127 | } |
128 | 128 | |
129 | 129 | // clean up base images |
130 | - if($this->options->clean_up){ |
|
130 | + if ($this->options->clean_up) { |
|
131 | 131 | |
132 | - for($zoom = $this->options->zoom_min; $zoom <= $this->options->zoom_max; $zoom++){ |
|
132 | + for ($zoom = $this->options->zoom_min; $zoom <= $this->options->zoom_max; $zoom++) { |
|
133 | 133 | $lvl_file = $out_path.'/'.$zoom.'.'.$this->options->tile_ext; |
134 | 134 | |
135 | - if(is_file($lvl_file)){ |
|
136 | - if(unlink($lvl_file)){ |
|
135 | + if (is_file($lvl_file)) { |
|
136 | + if (unlink($lvl_file)) { |
|
137 | 137 | $this->logger->info('deleted base image for zoom level '.$zoom.': '.$lvl_file); |
138 | 138 | } |
139 | 139 | } |
@@ -162,16 +162,16 @@ discard block |
||
162 | 162 | $start = true; |
163 | 163 | $il = null; |
164 | 164 | |
165 | - for($zoom = $this->options->zoom_max; $zoom >= $this->options->zoom_min; $zoom--){ |
|
165 | + for ($zoom = $this->options->zoom_max; $zoom >= $this->options->zoom_min; $zoom--) { |
|
166 | 166 | $base_image = $out_path.'/'.$zoom.'.'.$this->options->tile_ext; |
167 | 167 | |
168 | 168 | // check if the base image already exists |
169 | - if(!$this->options->overwrite_base_image && is_file($base_image)){ |
|
169 | + if (!$this->options->overwrite_base_image && is_file($base_image)) { |
|
170 | 170 | $this->logger->info('base image for zoom level '.$zoom.' already exists: '.$base_image); |
171 | 171 | continue; |
172 | 172 | } |
173 | 173 | |
174 | - [$w, $h] = $this->getSize($width, $height, $zoom); |
|
174 | + [ $w, $h ] = $this->getSize($width, $height, $zoom); |
|
175 | 175 | |
176 | 176 | // fit main image to current zoom level |
177 | 177 | $il = $start ? clone $im : $il; |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | // save without optimizing |
186 | 186 | $this->saveImage($il, $base_image, false); |
187 | 187 | |
188 | - if($start){ |
|
188 | + if ($start) { |
|
189 | 189 | $this->clearImage($im); |
190 | 190 | } |
191 | 191 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $y = (int)ceil($h / $ts); |
213 | 213 | |
214 | 214 | // width |
215 | - for($ix = 0; $ix < $x; $ix++){ |
|
215 | + for ($ix = 0; $ix < $x; $ix++) { |
|
216 | 216 | $cx = $ix * $ts; |
217 | 217 | |
218 | 218 | // create a stripe tile_size * height |
@@ -220,11 +220,11 @@ discard block |
||
220 | 220 | $ci->cropImage($ts, $h, $cx, 0); |
221 | 221 | |
222 | 222 | // height |
223 | - for($iy = 0; $iy < $y; $iy++){ |
|
223 | + for ($iy = 0; $iy < $y; $iy++) { |
|
224 | 224 | $tile = $out_path.'/'.sprintf($this->options->store_structure, $zoom, $ix, $iy).'.'.$this->options->tile_ext; |
225 | 225 | |
226 | 226 | // check if tile already exists |
227 | - if(!$this->options->overwrite_tile_image && is_file($tile)){ |
|
227 | + if (!$this->options->overwrite_tile_image && is_file($tile)) { |
|
228 | 228 | $this->logger->info('tile '.$zoom.'/'.$x.'/'.$y.' already exists: '.$tile); |
229 | 229 | |
230 | 230 | continue; |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | $ti->cropImage($ts, $ts, 0, $cy); |
241 | 241 | |
242 | 242 | // check if the current tile is smaller than the tile size (leftover edges on the input image) |
243 | - if($ti->getImageWidth() < $ts || $ti->getimageheight() < $ts){ |
|
243 | + if ($ti->getImageWidth() < $ts || $ti->getimageheight() < $ts) { |
|
244 | 244 | |
245 | 245 | $th = $this->options->tms ? $h - $ts : 0; |
246 | 246 | |
@@ -273,22 +273,22 @@ discard block |
||
273 | 273 | protected function saveImage(Imagick $image, string $dest, bool $optimize):void{ |
274 | 274 | $dir = dirname($dest); |
275 | 275 | |
276 | - if(!is_dir($dir)){ |
|
277 | - if(!mkdir($dir, 0755, true)){ |
|
276 | + if (!is_dir($dir)) { |
|
277 | + if (!mkdir($dir, 0755, true)) { |
|
278 | 278 | throw new ImagetilerException('cannot create folder '.$dir); |
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | - if($this->options->tile_format === 'jpeg'){ |
|
282 | + if ($this->options->tile_format === 'jpeg') { |
|
283 | 283 | $image->setCompression(Imagick::COMPRESSION_JPEG); |
284 | 284 | $image->setCompressionQuality($this->options->quality_jpeg); |
285 | 285 | } |
286 | 286 | |
287 | - if(!$image->writeImage($dest)){ |
|
287 | + if (!$image->writeImage($dest)) { |
|
288 | 288 | throw new ImagetilerException('cannot save image '.$dest); |
289 | 289 | } |
290 | 290 | |
291 | - if($this->options->optimize_output && $optimize && $this->optimizer instanceof Optimizer){ |
|
291 | + if ($this->options->optimize_output && $optimize && $this->optimizer instanceof Optimizer) { |
|
292 | 292 | $this->optimizer->optimize($dest); |
293 | 293 | } |
294 | 294 | |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | */ |
304 | 304 | protected function clearImage(Imagick $image = null):bool{ |
305 | 305 | |
306 | - if($image instanceof Imagick){ |
|
306 | + if ($image instanceof Imagick) { |
|
307 | 307 | $image->clear(); |
308 | 308 | |
309 | 309 | return $image->destroy(); |
@@ -323,19 +323,19 @@ discard block |
||
323 | 323 | */ |
324 | 324 | protected function getSize(int $width, int $height, int $zoom):array{ |
325 | 325 | |
326 | - if($this->options->zoom_max > $this->options->zoom_normalize && $zoom > $this->options->zoom_normalize){ |
|
326 | + if ($this->options->zoom_max > $this->options->zoom_normalize && $zoom > $this->options->zoom_normalize) { |
|
327 | 327 | $zd = 2 ** ($zoom - $this->options->zoom_normalize); |
328 | 328 | |
329 | - return [$zd * $width, $zd * $height]; |
|
329 | + return [ $zd * $width, $zd * $height ]; |
|
330 | 330 | } |
331 | 331 | |
332 | - if($zoom < $this->options->zoom_normalize){ |
|
332 | + if ($zoom < $this->options->zoom_normalize) { |
|
333 | 333 | $zd = 2 ** ($this->options->zoom_normalize - $zoom); |
334 | 334 | |
335 | - return [(int)round($width / $zd), (int)round($height / $zd)]; |
|
335 | + return [ (int)round($width / $zd), (int)round($height / $zd) ]; |
|
336 | 336 | } |
337 | 337 | |
338 | - return [$width, $height]; |
|
338 | + return [ $width, $height ]; |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | } |