Ticket #22738: 22738.3.diff
File 22738.3.diff, 2.9 KB (added by , 11 years ago) |
---|
-
wp-includes/media.php
29 29 * @param int $width Width of the image 30 30 * @param int $height Height of the image 31 31 * @param string|array $size Size of what the result image should be. 32 * @param context Could be 'display' (like in a theme) or 'edit' (like inserting into a neditor) 32 33 * @return array Width and height of what the result image should resize to. 33 34 */ 34 function image_constrain_size_for_editor($width, $height, $size = 'medium' ) {35 function image_constrain_size_for_editor($width, $height, $size = 'medium', $context = null ) { 35 36 global $content_width, $_wp_additional_image_sizes; 36 37 38 if ( ! $context ) 39 $context = is_admin() ? 'edit' : 'display'; 40 37 41 if ( is_array($size) ) { 38 42 $max_width = $size[0]; 39 43 $max_height = $size[1]; … … 64 68 } elseif ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) { 65 69 $max_width = intval( $_wp_additional_image_sizes[$size]['width'] ); 66 70 $max_height = intval( $_wp_additional_image_sizes[$size]['height'] ); 67 if ( intval($content_width) > 0 && is_admin()) // Only in admin. Assume that theme authors know what they're doing.71 if ( intval($content_width) > 0 && 'edit' == $context ) // Only in admin. Assume that theme authors know what they're doing. 68 72 $max_width = min( intval($content_width), $max_width ); 69 73 } 70 74 // $size == 'full' has no constraint … … 73 77 $max_height = $height; 74 78 } 75 79 76 list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size );80 list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size, $context ); 77 81 78 82 return wp_constrain_dimensions( $width, $height, $max_width, $max_height ); 79 83 } … … 1375 1379 1376 1380 // Nothing from the filter, so consult image metadata if we have it. 1377 1381 $size_meta = $meta['sizes'][ $size ]; 1382 1383 // We have the actual image size, but might need to further constrain it if content_width is narrower. 1384 // This is not necessary for thumbnails and medium size. 1385 if ( 'thumbnail' == $size || 'medium' == $size ) { 1386 $width = $size_meta['width']; 1387 $height = $size_meta['height']; 1388 } else { 1389 list( $width, $height ) = image_constrain_size_for_editor( $size_meta['width'], $size_meta['height'], $size, 'edit' ); 1390 } 1391 1378 1392 $sizes[ $size ] = array( 1379 'height' => $ size_meta['height'],1380 'width' => $ size_meta['width'],1393 'height' => $height, 1394 'width' => $width, 1381 1395 'url' => $base_url . $size_meta['file'], 1382 'orientation' => $ size_meta['height'] > $size_meta['width']? 'portrait' : 'landscape',1396 'orientation' => $height > $width ? 'portrait' : 'landscape', 1383 1397 ); 1384 1398 } 1385 1399 }