Changeset 23096
- Timestamp:
- 12/06/2012 06:25:39 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/media.php
r23095 r23096 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; 37 38 if ( ! $context ) 39 $context = is_admin() ? 'edit' : 'display'; 36 40 37 41 if ( is_array($size) ) { … … 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 } … … 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 ); … … 1379 1383 // Nothing from the filter, so consult image metadata if we have it. 1380 1384 $size_meta = $meta['sizes'][ $size ]; 1385 1386 // We have the actual image size, but might need to further constrain it if content_width is narrower. 1387 // This is not necessary for thumbnails and medium size. 1388 if ( 'thumbnail' == $size || 'medium' == $size ) { 1389 $width = $size_meta['width']; 1390 $height = $size_meta['height']; 1391 } else { 1392 list( $width, $height ) = image_constrain_size_for_editor( $size_meta['width'], $size_meta['height'], $size, 'edit' ); 1393 } 1394 1381 1395 $sizes[ $size ] = array( 1382 'height' => $ size_meta['height'],1383 'width' => $ size_meta['width'],1396 'height' => $height, 1397 'width' => $width, 1384 1398 'url' => $base_url . $size_meta['file'], 1385 'orientation' => $ size_meta['height'] > $size_meta['width']? 'portrait' : 'landscape',1399 'orientation' => $height > $width ? 'portrait' : 'landscape', 1386 1400 ); 1387 1401 }
Note: See TracChangeset
for help on using the changeset viewer.