diff --git a/wp-admin/css/media.css b/wp-admin/css/media.css index e499d735ed..62860a7663 100644 --- a/wp-admin/css/media.css +++ b/wp-admin/css/media.css @@ -109,6 +109,11 @@ form.media-upload-form { background: url(../images/align-right.png) no-repeat center left; } +.media-upload-form fieldset#image-size label { + display: inline; + margin: 0 1em 0 0; +} + .pinkynail { max-width: 40px; max-height: 40px; diff --git a/wp-admin/includes/image.php b/wp-admin/includes/image.php index 5704f462e3..ee665a8731 100644 --- a/wp-admin/includes/image.php +++ b/wp-admin/includes/image.php @@ -224,16 +224,27 @@ function get_udims( $width, $height) { * */ function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) { - if ( $height <= $hmax && $width <= $wmax ){ - //Image is smaller than max - return array( $width, $height); - } elseif ( $width / $height > $wmax / $hmax ) { - //Image Width will be greatest - return array( $wmax, (int) ($height / $width * $wmax )); - } else { - //Image Height will be greatest - return array( (int) ($width / $height * $hmax ), $hmax ); - } + return wp_constrain_dimensions( $width, $height, $wmax, $hmax ); +} + +// same as wp_shrink_dimensions, except the max parameters are optional. +// if either width or height are empty, no constraint is applied on that dimension. +function wp_constrain_dimensions( $current_width, $current_height, $max_width=0, $max_height=0 ) { + if ( !$max_width and !$max_height ) + return array( $current_width, $current_height ); + + $width_ratio = $height_ratio = 1.0; + + if ( $max_width > 0 && $current_width > $max_width ) + $width_ratio = $max_width / $current_width; + + if ( $max_height > 0 && $current_height > $max_height ) + $height_ratio = $max_height / $current_height; + + // the smaller ratio is the one we need to fit it to the constraining box + $ratio = min( $width_ratio, $height_ratio ); + + return array( intval($current_width * $ratio), intval($current_height * $ratio) ); } // convert a fraction string to a decimal diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 1c8e75b921..e65474265c 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -131,6 +131,15 @@ jQuery(document).ready(function(){ /> +
@@ -174,7 +183,7 @@ function image_upload_handler() {
if ( is_wp_error($id) )
wp_iframe( 'image_upload_form', get_option('siteurl') . '/wp-admin/media-upload.php?type=image', $_POST, $id );
else {
- media_send_to_editor(get_image_send_to_editor($id, $_POST['image-alt'], $_POST['image-title'], $_POST['image-align'], $_POST['image-url']));
+ media_send_to_editor(get_image_send_to_editor($id, $_POST['image-alt'], $_POST['image-title'], $_POST['image-align'], $_POST['image-url'], true, $_POST['image-size']));
}
}
}
@@ -217,37 +226,16 @@ EOF;
add_filter('async_upload_image', 'async_image_callback');
-// scale down the default size of an image so it's a better fit for the editor and theme
-function image_constrain_size_for_editor($width, $height) {
- // pick a reasonable default width for the image
- // $content_width might be set in the theme's functions.php
- if ( !empty($GLOBALS['content_width']) )
- $max_width = $GLOBALS['content_width'];
- else
- $max_width = 500;
- $max_width = apply_filters( 'editor_max_image_width', $max_width );
- $max_height = apply_filters( 'editor_max_image_height', $max_width );
-
- return wp_shrink_dimensions( $width, $height, $max_width, $max_height );
-}
+function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') {
-function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false) {
-
- $img_src = wp_get_attachment_url($id);
- $meta = wp_get_attachment_metadata($id);
-
- $hwstring = '';
- if ( isset($meta['width'], $meta['height']) ) {
- list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'] );
- $hwstring = ' width="'.intval($width).'" height="'.intval($height).'"';
- }
-
- $html = '';
+ $html = get_image_tag($id, $alt, $title, $align, $rel, $size);
$rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
if ( $url )
$html = "$html";
+ elseif ( $size == 'thumb' || $size == 'medium' )
+ $html = ''.$html.'';
$html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url );
@@ -392,7 +380,7 @@ function media_buttons() { // just a placeholder for now
$multimedia_upload_iframe_src = apply_filters('multimedia_upload_iframe_src', $multimedia_upload_iframe_src);
$out = << %s,
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+%s
, %s
.'), wp_generate_password(), wp_generate_password(), wp_generate_password()) ?>