Passed
Push — master ( c546ba...2b43ba )
by smiley
04:05
created

ImagetilerOptionsTrait::ImagetilerOptionsTrait()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
c 0
b 0
f 0
rs 10
cc 4
nc 4
nop 0
1
<?php
2
/**
3
 * Trait ImagetilerOptionsTrait
4
 *
5
 * @filesource   ImagetilerOptionsTrait.php
6
 * @created      20.06.2018
7
 * @package      chillerlan\Imagetiler
8
 * @author       smiley <[email protected]>
9
 * @copyright    2018 smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\Imagetiler;
14
15
use Imagick;
16
17
trait ImagetilerOptionsTrait{
18
19
	/**
20
	 * width/height of a single tile
21
	 *
22
	 * @var int
23
	 */
24
	protected $tile_size = 256;
25
26
	/**
27
	 * minimum zoom level
28
	 *
29
	 * @var int
30
	 */
31
32
	protected $zoom_min = 0;
33
34
	/**
35
	 * maximum zoom level
36
	 *
37
	 * @var int
38
	 */
39
	protected $zoom_max = 8;
40
41
	/**
42
	 * normalize zoom level
43
	 *
44
	 * this zoom level represents the size of the original image.
45
	 * zoom levels higher than this will be upscaled, which may take
46
	 * some time and resources depending on the size of the input image.
47
	 *
48
	 * @var int
49
	 */
50
	protected $zoom_normalize = null;
51
52
	/**
53
	 * if set to true - the origin will be set to bottom left, +y upwards
54
	 * @see http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification#TileMap_Diagram
55
	 *
56
	 * otherwise the origin is on the top left, +y downwards (default)
57
	 * @see https://developers.google.com/maps/documentation/javascript/coordinates#tile-coordinates
58
	 *
59
	 * @var bool
60
	 */
61
	protected $tms = false;
62
63
	/**
64
	 * fill color can be transparent for png
65
	 *
66
	 * @var string
67
	 */
68
69
	protected $fill_color = '#000000';
70
71
	/**
72
	 * @see https://secure.php.net/manual/ini.core.php#ini.memory-limit
73
	 * @var string
74
	 */
75
	protected $memory_limit = '-1';
76
77
	/**
78
	 * %1$d - zoom
79
	 * %2$d - x
80
	 * %3$d - y
81
	 *
82
	 * @see https://secure.php.net/manual/function.sprintf.php
83
	 * @var string
84
	 */
85
	protected $store_structure = '%1$d/%2$d/%3$d';
86
87
	/**
88
	 * determines whether to use fast scaleImage (true) or slow resizeImage (false)
89
	 *
90
	 * @var bool
91
	 */
92
	protected $fast_resize = false;
93
94
	/**
95
	 * @see https://secure.php.net/manual/imagick.constants.php
96
	 * @var int
97
	 */
98
	protected $resize_filter = Imagick::FILTER_ROBIDOUXSHARP; //FILTER_LANCZOS2SHARP
99
100
	/**
101
	 * @var float
102
	 */
103
	protected $resize_blur = 1.0;
104
105
	/**
106
	 * image format used for storing the tiles: jpeg or png
107
	 * @see http://www.imagemagick.org/script/formats.php
108
	 *
109
	 * @var string
110
	 */
111
	protected $tile_format = 'png';
112
113
	/**
114
	 * tile image extension - autodetected from format if none given
115
	 *
116
	 * @var string
117
	 */
118
	protected $tile_ext = null;
119
120
	/**
121
	 * quality of the saved image in jpeg format
122
	 *
123
	 * @var int
124
	 */
125
	protected $quality_jpeg = 80;
126
127
	/**
128
	 * ImageMagick tmp folder,
129
	 * Can be changed in case if system /tmp have not enough free space
130
	 *
131
	 * @var string
132
	 */
133
	protected $imagick_tmp = null;
134
135
	/**
136
	 * @var bool
137
	 */
138
	protected $overwrite_base_image = false;
139
140
	/**
141
	 * @var bool
142
	 */
143
	protected $overwrite_tile_image = false;
144
145
	/**
146
	 * @var bool
147
	 */
148
	protected $clean_up = true;
149
150
	/**
151
	 * @var bool
152
	 */
153
	protected $optimize_output = false;
154
155
	/**
156
	 * "constructor"
157
	 */
158
	public function ImagetilerOptionsTrait(){
159
		$this->zoom_min = max(0, $this->zoom_min);
160
		$this->zoom_max = max(1, $this->zoom_max);
161
162
		if($this->zoom_normalize === null || $this->zoom_max < $this->zoom_normalize){
163
			$this->zoom_normalize = $this->zoom_max;
164
		}
165
166
		if($this->tile_ext === null){
167
			$this->tile_ext = $this->getExtension($this->tile_format);
168
		}
169
170
	}
171
172
	/**
173
	 * return file extension depend of given format
174
	 *
175
	 * @param string $format
176
	 *
177
	 * @return string
178
	 * @throws \chillerlan\Imagetiler\ImagetilerException
179
	 */
180
	protected function getExtension(string $format):string{
181
182
		if(in_array($format, ['jpeg', 'jp2', 'jpc', 'jxr',], true)){
183
			return 'jpg';
184
		}
185
186
		if(in_array($format, ['png', 'png00', 'png8', 'png24', 'png32', 'png64',], true)){
187
			return 'png';
188
		}
189
190
		throw new ImagetilerException('invalid file format');
191
	}
192
193
}
194