Ticket #19393: 19393.diff
File 19393.diff, 2.8 KB (added by , 11 years ago) |
---|
-
src/wp-admin/includes/image.php
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 sizes100 $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 } -
src/wp-includes/media.php
184 184 * Registers a new image size 185 185 * 186 186 * @since 2.9.0 187 * 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. 187 198 */ 188 199 function add_image_size( $name, $width = 0, $height = 0, $crop = false ) { 189 200 global $_wp_additional_image_sizes; 190 $_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => (bool)$crop );201 $_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => $crop ); 191 202 } 192 203 193 204 /** … … 349 360 $crop_w = round($new_w / $size_ratio); 350 361 $crop_h = round($new_h / $size_ratio); 351 362 352 $s_x = floor( ($orig_w - $crop_w) / 2 ); 353 $s_y = floor( ($orig_h - $crop_h) / 2 ); 363 if ( ! is_array( $crop ) || count( $crop ) !== 2 ) { 364 $crop = apply_filters( 'image_resize_crop_default', array( 'center', 'center' ) ); 365 } 366 367 @list( $x, $y ) = $crop; 368 369 switch ( $x ) { 370 case 'left': 371 $s_x = 0; 372 break; 373 case 'right': 374 $s_x = $orig_w - $crop_w; 375 break; 376 default: 377 $s_x = floor( ( $orig_w - $crop_w ) / 2 ); 378 break; 379 } 380 381 switch ( $y ) { 382 case 'top': 383 $s_y = 0; 384 break; 385 case 'bottom': 386 $s_y = $orig_h - $crop_h; 387 break; 388 default: 389 $s_y = floor( ( $orig_h - $crop_h ) / 2 ); 390 break; 391 } 354 392 } else { 355 393 // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box 356 394 $crop_w = $orig_w;