@@ 138-156 (lines=19) @@ | ||
135 | $targetHeight = null; |
|
136 | $targetX = null; |
|
137 | $targetY = null; |
|
138 | if ($width < $boxWidth && $height < $boxHeight && !$upsize) { |
|
139 | $targetWidth = $width; |
|
140 | $targetHeight = $height; |
|
141 | $targetX = ($boxWidth - $width) / 2; |
|
142 | $targetY = ($boxHeight - $height) / 2; |
|
143 | } else { |
|
144 | //if box is more vertical than original |
|
145 | if ($boxRatio < $originalRatio) { |
|
146 | $targetWidth = $boxWidth; |
|
147 | $targetHeight = (int)((double)$boxWidth / $originalRatio); |
|
148 | $targetX = 0; |
|
149 | $targetY = ($boxHeight - $targetHeight) / 2; |
|
150 | } else { |
|
151 | $targetWidth = (int)((double)$boxHeight * $originalRatio); |
|
152 | $targetHeight = $boxHeight; |
|
153 | $targetX = ($boxWidth - $targetWidth) / 2; |
|
154 | $targetY = 0; |
|
155 | } |
|
156 | } |
|
157 | ||
158 | $widthReduced = false; |
|
159 | if ($width > $targetWidth) { |
|
@@ 313-331 (lines=19) @@ | ||
310 | $targetHeight = null; |
|
311 | $targetX = null; |
|
312 | $targetY = null; |
|
313 | if ($width < $boxWidth && $height < $boxHeight && !$upsize) { |
|
314 | $targetWidth = $width; |
|
315 | $targetHeight = $height; |
|
316 | $targetX = ($boxWidth - $width) / 2; |
|
317 | $targetY = ($boxHeight - $height) / 2; |
|
318 | } else { |
|
319 | //if box is more vertical than original |
|
320 | if ($boxRatio < $originalRatio) { |
|
321 | $targetWidth = $boxWidth; |
|
322 | $targetHeight = (int)((double)$boxWidth / $originalRatio); |
|
323 | $targetX = 0; |
|
324 | $targetY = ($boxHeight - $targetHeight) / 2; |
|
325 | } else { |
|
326 | $targetWidth = (int)((double)$boxHeight * $originalRatio); |
|
327 | $targetHeight = $boxHeight; |
|
328 | $targetX = ($boxWidth - $targetWidth) / 2; |
|
329 | $targetY = 0; |
|
330 | } |
|
331 | } |
|
332 | ||
333 | //do iterative downsize by halfs (2x2 binning is a common name) on dimensions that are bigger than target |
|
334 | //width and height |