Ticket #19393: wp-image-crop-position.patch
File wp-image-crop-position.patch, 2.7 KB (added by , 13 years ago) |
---|
-
wp-includes/media.php
179 179 * Registers a new image size 180 180 * 181 181 * @since 2.9.0 182 * 183 * In addition to true/false, the $crop parameter takes an array of the format 184 * array( x_crop_position, y_crop_position ) 185 * x_crop_position can be 'left', 'center', 'right' 186 * y_crop_position can be 'top', 'center', 'bottom' 187 * 188 * @param string $name Image size identifier. 189 * @param int $width Image width. 190 * @param int $height Image height. 191 * @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. 192 * @return bool|array False, if no image was created. Metadata array on success. 182 193 */ 183 194 function add_image_size( $name, $width = 0, $height = 0, $crop = false ) { 184 195 global $_wp_additional_image_sizes; 185 $_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => (bool)$crop );196 $_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => $crop ); 186 197 } 187 198 188 199 /** … … 362 373 $crop_w = round($new_w / $size_ratio); 363 374 $crop_h = round($new_h / $size_ratio); 364 375 365 $s_x = floor( ($orig_w - $crop_w) / 2 ); 366 $s_y = floor( ($orig_h - $crop_h) / 2 ); 376 if ( !is_array( $crop ) || count( $crop ) != 2 ) { 377 $crop = apply_filters( 'image_resize_crop_default', array( 'center', 'center' ) ); 378 } 379 380 switch ( $crop[0] ) { 381 case 'left': $s_x = 0; break; 382 case 'right': $s_x = $orig_w - $crop_w; break; 383 default: $s_x = floor( ( $orig_w - $crop_w ) / 2 ); 384 } 385 386 switch ( $crop[1] ) { 387 case 'top': $s_y = 0; break; 388 case 'bottom': $s_y = $orig_h - $crop_h; break; 389 default: $s_y = floor( ( $orig_h - $crop_h ) / 2 ); 390 } 367 391 } else { 368 392 // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box 369 393 $crop_w = $orig_w; -
wp-admin/includes/image.php
114 114 else 115 115 $sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options 116 116 if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) ) 117 $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes117 $sizes[$s]['crop'] = $_wp_additional_image_sizes[$s]['crop']; // For theme-added sizes 118 118 else 119 119 $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options 120 120 }