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