diff --git a/wp-admin/css/media.css b/wp-admin/css/media.css index e499d735e..62860a766 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 5704f462e..ee665a873 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 1c8e75b92..e65474265 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 = ''.attribute_escape($alt).''; + $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 = << + diff --git a/wp-admin/options-writing.php b/wp-admin/options-writing.php index ee5c5a8b4..dc7bdedd3 100644 --- a/wp-admin/options-writing.php +++ b/wp-admin/options-writing.php @@ -57,6 +57,30 @@ endforeach; +

+

+ + + + + + + + + + +
+ + + + +
+ + + + +
+

%s, %s, %s.'), wp_generate_password(), wp_generate_password(), wp_generate_password()) ?>

diff --git a/wp-includes/media.php b/wp-includes/media.php new file mode 100644 index 000000000..7db43be89 --- /dev/null +++ b/wp-includes/media.php @@ -0,0 +1,95 @@ + tag. Empty values will be omitted. +function image_hwstring($width, $height) { + $out = ''; + if ($width) + $out .= 'width="'.intval($width).'" '; + if ($height) + $out .= 'height="'.intval($height).'" '; + return $out; +} + +// Scale an image to fit a particular size (such as 'thumb' or 'medium'), and return an image URL, height and width. +// The URL might be the original image, or it might be a resized version. +// returns an array($url, $width, $height) +function image_downsize($id, $size = 'medium') { + + $img_url = wp_get_attachment_url($id); + $meta = wp_get_attachment_metadata($id); + $width = $height = 0; + + // plugins can use this to provide resize services + if ( $out = apply_filters('image_downsize', false, $id, $size) ) + return $out; + + if ( $size == 'thumb' ) { + // thumbnail: use the thumb as the displayed image, and constrain based on its dimensions + $thumb_path = wp_get_attachment_thumb_file($id); + // the actual thumbnail size isn't stored so we'll have to calculate it + if ( $thumb_path && ($info = getimagesize($thumb_path)) ) { + list( $width, $height ) = image_constrain_size_for_editor( $info[0], $info[1], $size ); + $img_url = wp_get_attachment_thumb_url($id); + } + // this could be improved to provide a default thumbnail if one doesn't exist + } + elseif ( isset($meta['width'], $meta['height']) ) { + // any other type: use the real image and constrain it + list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'], $size ); + } + + return array( $img_url, $width, $height ); + +} + +// return an tag for the given image attachment, scaling it down if requested +function get_image_tag($id, $alt, $title, $align, $rel = false, $size='medium') { + + list( $img_src, $width, $height ) = image_downsize($id, $size); + $hwstring = image_hwstring($width, $height); + + $html = ''.attribute_escape($alt).''; + + $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url ); + + return $html; +} + +?> \ No newline at end of file diff --git a/wp-settings.php b/wp-settings.php index afd5bb040..cb8363e67 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -263,6 +263,7 @@ require (ABSPATH . WPINC . '/taxonomy.php'); require (ABSPATH . WPINC . '/update.php'); require (ABSPATH . WPINC . '/canonical.php'); require (ABSPATH . WPINC . '/shortcodes.php'); +require (ABSPATH . WPINC . '/media.php'); if (strpos($_SERVER['PHP_SELF'], 'install.php') === false) { // Used to guarantee unique hash cookies