|
1 | 1 | <?php |
2 | 2 | /* |
3 | | - * jQuery File Upload Plugin PHP Class 6.2 |
| 3 | + * jQuery File Upload Plugin PHP Class 6.3 |
4 | 4 | * https://github.com/blueimp/jQuery-File-Upload |
5 | 5 | * |
6 | 6 | * Copyright 2010, Sebastian Tschan |
@@ -101,6 +101,9 @@ function __construct($options = null, $initialize = true, $error_messages = null |
101 | 101 | ), |
102 | 102 | */ |
103 | 103 | 'thumbnail' => array( |
| 104 | + // Uncomment the following to force the max |
| 105 | + // dimensions and e.g. create square thumbnails: |
| 106 | + //'crop' => true, |
104 | 107 | 'max_width' => 80, |
105 | 108 | 'max_height' => 80 |
106 | 109 | ) |
@@ -280,19 +283,36 @@ protected function create_scaled_image($file_name, $version, $options) { |
280 | 283 | if (!$img_width || !$img_height) { |
281 | 284 | return false; |
282 | 285 | } |
| 286 | + $max_width = $options['max_width']; |
| 287 | + $max_height = $options['max_height']; |
283 | 288 | $scale = min( |
284 | | - $options['max_width'] / $img_width, |
285 | | - $options['max_height'] / $img_height |
| 289 | + $max_width / $img_width, |
| 290 | + $max_height / $img_height |
286 | 291 | ); |
287 | 292 | if ($scale >= 1) { |
288 | 293 | if ($file_path !== $new_file_path) { |
289 | 294 | return copy($file_path, $new_file_path); |
290 | 295 | } |
291 | 296 | return true; |
292 | 297 | } |
293 | | - $new_width = $img_width * $scale; |
294 | | - $new_height = $img_height * $scale; |
295 | | - $new_img = @imagecreatetruecolor($new_width, $new_height); |
| 298 | + if (empty($options['crop'])) { |
| 299 | + $new_width = $img_width * $scale; |
| 300 | + $new_height = $img_height * $scale; |
| 301 | + $dst_x = 0; |
| 302 | + $dst_y = 0; |
| 303 | + $new_img = @imagecreatetruecolor($new_width, $new_height); |
| 304 | + } else { |
| 305 | + if (($img_width / $img_height) >= ($max_width / $max_height)) { |
| 306 | + $new_width = $img_width / ($img_height / $max_height); |
| 307 | + $new_height = $max_height; |
| 308 | + } else { |
| 309 | + $new_width = $max_width; |
| 310 | + $new_height = $img_height / ($img_width / $max_width); |
| 311 | + } |
| 312 | + $dst_x = 0 - ($new_width - $max_width) / 2; |
| 313 | + $dst_y = 0 - ($new_height - $max_height) / 2; |
| 314 | + $new_img = @imagecreatetruecolor($max_width, $max_height); |
| 315 | + } |
296 | 316 | switch (strtolower(substr(strrchr($file_name, '.'), 1))) { |
297 | 317 | case 'jpg': |
298 | 318 | case 'jpeg': |
@@ -322,7 +342,10 @@ protected function create_scaled_image($file_name, $version, $options) { |
322 | 342 | $success = $src_img && @imagecopyresampled( |
323 | 343 | $new_img, |
324 | 344 | $src_img, |
325 | | - 0, 0, 0, 0, |
| 345 | + $dst_x, |
| 346 | + $dst_y, |
| 347 | + 0, |
| 348 | + 0, |
326 | 349 | $new_width, |
327 | 350 | $new_height, |
328 | 351 | $img_width, |
|
0 commit comments