|
| 58 |
global $content_width; |
| 59 |
|
| 60 |
$_wp_additional_image_sizes = wp_get_additional_image_sizes(); |
| 61 |
|
| 62 |
if ( ! $context ) |
| 63 |
$context = is_admin() ? 'edit' : 'display'; |
| 64 |
|
| 65 |
if ( is_array($size) ) { |
| 66 |
$max_width = $size[0]; |
| 67 |
$max_height = $size[1]; |
| 68 |
} |
| 69 |
elseif ( $size == 'thumb' || $size == 'thumbnail' ) { |
| 70 |
$max_width = intval(get_option('thumbnail_size_w')); |
| 71 |
$max_height = intval(get_option('thumbnail_size_h')); |
| 72 |
// last chance thumbnail size defaults |
| 73 |
if ( !$max_width && !$max_height ) { |
| 74 |
$max_width = 128; |
| 75 |
$max_height = 96; |
| 76 |
} |
| 77 |
} |
| 78 |
elseif ( $size == 'medium' ) { |
| 79 |
$max_width = intval(get_option('medium_size_w')); |
| 80 |
$max_height = intval(get_option('medium_size_h')); |
| 81 |
|
| 82 |
} |
| 83 |
elseif ( $size == 'medium_large' ) { |
| 84 |
$max_width = intval( get_option( 'medium_large_size_w' ) ); |
| 85 |
$max_height = intval( get_option( 'medium_large_size_h' ) ); |
| 86 |
|
| 87 |
if ( intval( $content_width ) > 0 ) { |
| 88 |
$max_width = min( intval( $content_width ), $max_width ); |
| 89 |
} |
| 90 |
} |
| 91 |
elseif ( $size == 'large' ) { |
| 92 |
/* |
| 93 |
* We're inserting a large size image into the editor. If it's a really |
| 94 |
* big image we'll scale it down to fit reasonably within the editor |
| 95 |
* itself, and within the theme's content width if it's known. The user |
| 96 |
* can resize it in the editor if they wish. |
| 97 |
*/ |
| 98 |
$max_width = intval(get_option('large_size_w')); |
| 99 |
$max_height = intval(get_option('large_size_h')); |
| 100 |
if ( intval($content_width) > 0 ) { |
| 101 |
$max_width = min( intval($content_width), $max_width ); |
| 102 |
} |
| 103 |
} elseif ( ! empty( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) { |
| 104 |
$max_width = intval( $_wp_additional_image_sizes[$size]['width'] ); |
| 105 |
$max_height = intval( $_wp_additional_image_sizes[$size]['height'] ); |
| 106 |
// Only in admin. Assume that theme authors know what they're doing. |
| 107 |
if ( intval( $content_width ) > 0 && 'edit' === $context ) { |
| 108 |
$max_width = min( intval( $content_width ), $max_width ); |
| 109 |
} |
| 110 |
} |
| 111 |
// $size == 'full' has no constraint |
| 112 |
else { |
| 113 |
$max_width = $width; |
| 114 |
$max_height = $height; |
| 115 |
} |