Index: wp-includes/media.php
===================================================================
--- wp-includes/media.php	(revision 0)
+++ wp-includes/media.php	(revision 0)
@@ -0,0 +1,95 @@
+<?php
+
+// functions for media display
+
+// 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, $size = 'medium') {
+	
+	if ( $size == 'thumb' ) {
+		$max_width = intval(get_option('thumbnail_size_w'));
+		$max_height = intval(get_option('thumbnail_size_h'));
+		// last chance thumbnail size defaults
+		if ( !$max_width && !$max_height ) {
+			$max_width = 128;
+			$max_height = 96;
+		}
+	}
+	elseif ( $size == 'medium' ) {
+		$max_width = intval(get_option('medium_size_w'));
+		$max_height = intval(get_option('medium_size_h'));
+		// if no width is set, default to the theme content width if available
+		if ( !$max_width ) {
+			// $content_width might be set in the current theme's functions.php
+			if ( !empty($GLOBALS['content_width']) ) {
+				$max_width = $GLOBALS['content_width'];
+			}
+			else
+				$max_width = 500;
+		}
+	}
+	else { // $size == 'full'
+		$max_width = 0;
+		$max_height = 0;
+	}
+
+	list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size );
+	
+	return wp_constrain_dimensions( $width, $height, $max_width, $max_height );
+}
+
+// return a width/height string for use in an <img /> 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 <img src /> 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 = '<img src="'.attribute_escape($img_src).'" alt="'.attribute_escape($alt).'" title="'.attribute_escape($title).'"'.$hwstring.' class="align-'.attribute_escape($align).' size-'.attribute_escape($size).' attachment wp-att-'.attribute_escape($id).'" />';
+
+	$html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url );
+
+	return $html;
+}
+
+?>
\ No newline at end of file
Index: wp-settings.php
===================================================================
--- wp-settings.php	(revision 6947)
+++ wp-settings.php	(working copy)
@@ -263,6 +263,7 @@
 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
Index: wp-admin/includes/media.php
===================================================================
--- wp-admin/includes/media.php	(revision 6947)
+++ wp-admin/includes/media.php	(working copy)
@@ -131,6 +131,15 @@
 	<input type="radio" name="image-align" id="image-align-right" value="right"  <?php if ($image_align == 'right') echo ' checked="checked"'; ?>/>
 	<label for="image-align-right" id="image-align-right-label"><?php _e('Right'); ?></label>
 </fieldset>
+<fieldset id="image-size">
+	<legend><?php _e('Size'); ?></legend>
+	<input type="radio" name="image-size" id="image-size-thumb" value="thumb" <?php if ($image_size == 'thumb') echo ' checked="checked"'; ?>/>
+	<label for="image-size-thumb" id="image-size-thumb-label"><?php _e('Thumbnail'); ?></label>
+	<input type="radio" name="image-size" id="image-size-medium" value="medium" <?php if ($image_size == 'medium' || !$image_size) echo ' checked="checked"'; ?>/>
+	<label for="image-size-medium" id="image-size-medium-label"><?php _e('Medium'); ?></label>
+	<input type="radio" name="image-size" id="image-size-full" value="full" <?php if ($image_size == 'full') echo ' checked="checked"'; ?>/>
+	<label for="image-size-full" id="image-size-full-label"><?php _e('Full size'); ?></label>
+</fieldset>
 <p>
 	<button name="image-add" id="image-add" class="button-ok" value="1"><?php _e('Add Image'); ?></button>
 	<a href="#" onClick="return top.tb_remove();" id="image-cancel" class="button-cancel"><?php _e('Cancel'); ?></a>
@@ -174,7 +183,7 @@
 		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 @@
 
 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) {
+	$html = get_image_tag($id, $alt, $title, $align, $rel, $size);
 
-	$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 = '<img src="'.attribute_escape($img_src).'" alt="'.attribute_escape($alt).'" title="'.attribute_escape($title).'"'.$hwstring.' class="align-'.attribute_escape($align).'" />';
-
 	$rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
 	if ( $url )
 		$html = "<a href='".attribute_escape($url)."'$rel>$html</a>";
+	elseif ( $size == 'thumb' || $size == 'medium' )
+		$html = '<a href="'.get_attachment_link($id).'"'.$rel.'>'.$html.'</a>';
 		
 	$html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url );
 
@@ -392,7 +380,7 @@
 	$multimedia_upload_iframe_src = apply_filters('multimedia_upload_iframe_src', $multimedia_upload_iframe_src);
 	$out = <<<EOF
 
-<a href="{$image_upload_iframe_src}&TB_iframe=true&height=500&width=480" class="thickbox"><img src='images/media-button-image.gif' alt='' /></a>
+<a href="{$image_upload_iframe_src}&TB_iframe=true&height=550&width=480" class="thickbox"><img src='images/media-button-image.gif' alt='' /></a>
 <a href="{$multimedia_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox"><img src='images/media-button-gallery.gif' alt='' /></a>
 <a href="{$image_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox"><img src='images/media-button-video.gif' alt='' /></a>
 <a href="{$image_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox"><img src='images/media-button-music.gif' alt='' /></a>
Index: wp-admin/includes/image.php
===================================================================
--- wp-admin/includes/image.php	(revision 6947)
+++ wp-admin/includes/image.php	(working copy)
@@ -224,18 +224,29 @@
  *
  */
 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
 function wp_exif_frac2dec($str) {
 	@list( $n, $d ) = explode( '/', $str );
Index: wp-admin/css/media.css
===================================================================
--- wp-admin/css/media.css	(revision 6947)
+++ wp-admin/css/media.css	(working copy)
@@ -109,6 +109,11 @@
 	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;
Index: wp-admin/options-writing.php
===================================================================
--- wp-admin/options-writing.php	(revision 6947)
+++ wp-admin/options-writing.php	(working copy)
@@ -57,6 +57,30 @@
 </tr>
 </table>
 
+<h3><?php _e('Image sizes') ?></h3>
+<p><?php _e('The sizes listed below determine the maximum dimensions to use when inserting an image into the body of a post.'); ?></p>
+
+<table class="niceblue">
+<tr valign="top">
+<th scope="row"><?php _e('Thumbnail size:') ?></th>
+<td>
+<label for="thumbnail_size_w"><?php _e('Width:'); ?></label>
+<input name="thumbnail_size_w" type="text" id="thumbnail_size_w" value="<?php form_option('thumbnail_size_w'); ?>" size="6" />
+<label for="thumbnail_size_h"><?php _e('Height:'); ?></label>
+<input name="thumbnail_size_h" type="text" id="thumbnail_size_h" value="<?php form_option('thumbnail_size_h'); ?>" size="6" />
+</td>
+</tr>
+<tr valign="top">
+<th scope="row"><?php _e('Medium size:') ?></th>
+<td>
+<label for="medium_size_w"><?php _e('Width:'); ?></label>
+<input name="medium_size_w" type="text" id="medium_size_w" value="<?php form_option('medium_size_w'); ?>" size="6" />
+<label for="medium_size_h"><?php _e('Height:'); ?></label>
+<input name="medium_size_h" type="text" id="thumbnail_size_h" value="<?php form_option('medium_size_h'); ?>" size="6" />
+</td>
+</tr>
+</table>
+
 <h3><?php _e('Post via e-mail') ?></h3>
 <p><?php printf(__('To post to WordPress by e-mail you must set up a secret e-mail account with POP3 access. Any mail received at this address will be posted, so it&#8217;s a good idea to keep this address very secret. Here are three random strings you could use: <code>%s</code>, <code>%s</code>, <code>%s</code>.'), wp_generate_password(), wp_generate_password(), wp_generate_password()) ?></p>
 
