diff --git src/wp-admin/includes/image.php src/wp-admin/includes/image.php
index 23cce46..07c4f8e 100644
|
|
function wp_generate_attachment_metadata( $attachment_id, $file ) { |
97 | 97 | else |
98 | 98 | $sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options |
99 | 99 | if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) ) |
100 | | $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes |
| 100 | $sizes[$s]['crop'] = $_wp_additional_image_sizes[$s]['crop']; // For theme-added sizes |
101 | 101 | else |
102 | 102 | $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options |
103 | 103 | } |
diff --git src/wp-includes/media.php src/wp-includes/media.php
index e62753a..9982955 100644
|
|
function image_downsize($id, $size = 'medium') { |
185 | 185 | * |
186 | 186 | * @since 2.9.0 |
187 | 187 | * |
188 | | * @param string $name The image size name. |
189 | | * @param int $width The image's width. |
190 | | * @param int $height The image's width. |
191 | | * @param bool $width Whether to crop the image to fit the dimensions. Default false. |
| 188 | * In addition to true/false, the $crop parameter takes an array of the format |
| 189 | * array( x_crop_position, y_crop_position ) |
| 190 | * x_crop_position can be 'left', 'center', 'right' |
| 191 | * y_crop_position can be 'top', 'center', 'bottom' |
| 192 | * |
| 193 | * @param string $name Image size identifier. |
| 194 | * @param int $width Image width. |
| 195 | * @param int $height Image height. |
| 196 | * @param bool|array $crop Optional, default is false. Whether to crop image to specified height and width or resize. An array can specify positioning of the crop area. |
| 197 | * @return bool|array False, if no image was created. Metadata array on success. |
192 | 198 | */ |
193 | 199 | function add_image_size( $name, $width = 0, $height = 0, $crop = false ) { |
194 | 200 | global $_wp_additional_image_sizes; |
| 201 | |
195 | 202 | $_wp_additional_image_sizes[ $name ] = array( |
196 | 203 | 'width' => absint( $width ), |
197 | 204 | 'height' => absint( $height ), |
198 | | 'crop' => (bool) $crop, |
| 205 | 'crop' => $crop, |
199 | 206 | ); |
200 | 207 | } |
201 | 208 | |
… |
… |
function wp_constrain_dimensions( $current_width, $current_height, $max_width=0, |
345 | 352 | * Retrieve calculated resized dimensions for use in WP_Image_Editor. |
346 | 353 | * |
347 | 354 | * Calculate dimensions and coordinates for a resized image that fits within a |
348 | | * specified width and height. If $crop is true, the largest matching central |
349 | | * portion of the image will be cropped out and resized to the required size. |
| 355 | * specified width and height. |
| 356 | * |
| 357 | * If $crop is true, the largest matching central portion of the image will |
| 358 | * be cropped out and resized to the required size. |
| 359 | * |
| 360 | * In addition to true/false, the $crop parameter takes an array of the format |
| 361 | * array( x_crop_position, y_crop_position ) |
| 362 | * x_crop_position can be 'left', 'center', 'right' |
| 363 | * y_crop_position can be 'top', 'center', 'bottom' |
350 | 364 | * |
351 | 365 | * @since 2.5.0 |
352 | 366 | * @uses apply_filters() Calls 'image_resize_dimensions' on $orig_w, $orig_h, $dest_w, $dest_h and |
… |
… |
function wp_constrain_dimensions( $current_width, $current_height, $max_width=0, |
356 | 370 | * @param int $orig_h Original height. |
357 | 371 | * @param int $dest_w New width. |
358 | 372 | * @param int $dest_h New height. |
359 | | * @param bool $crop Optional, default is false. Whether to crop image or resize. |
| 373 | * @param bool|array $crop Optional, default is false. Whether to crop image to specified height and width or resize. An array can specify positioning of the crop area. |
360 | 374 | * @return bool|array False on failure. Returned array matches parameters for imagecopyresampled() PHP function. |
361 | 375 | */ |
362 | 376 | function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false) { |
… |
… |
function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = fal |
391 | 405 | $crop_w = round($new_w / $size_ratio); |
392 | 406 | $crop_h = round($new_h / $size_ratio); |
393 | 407 | |
394 | | $s_x = floor( ($orig_w - $crop_w) / 2 ); |
395 | | $s_y = floor( ($orig_h - $crop_h) / 2 ); |
| 408 | if ( ! is_array( $crop ) || count( $crop ) !== 2 ) { |
| 409 | $crop = apply_filters( 'image_resize_crop_default', array( 'center', 'center' ) ); |
| 410 | } |
| 411 | |
| 412 | @list( $x, $y ) = $crop; |
| 413 | |
| 414 | switch ( $x ) { |
| 415 | case 'left': |
| 416 | $s_x = 0; |
| 417 | break; |
| 418 | case 'right': |
| 419 | $s_x = $orig_w - $crop_w; |
| 420 | break; |
| 421 | default: |
| 422 | $s_x = floor( ( $orig_w - $crop_w ) / 2 ); |
| 423 | break; |
| 424 | } |
| 425 | |
| 426 | switch ( $y ) { |
| 427 | case 'top': |
| 428 | $s_y = 0; |
| 429 | break; |
| 430 | case 'bottom': |
| 431 | $s_y = $orig_h - $crop_h; |
| 432 | break; |
| 433 | default: |
| 434 | $s_y = floor( ( $orig_h - $crop_h ) / 2 ); |
| 435 | break; |
| 436 | } |
396 | 437 | } else { |
397 | 438 | // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box |
398 | 439 | $crop_w = $orig_w; |