Index: wp-admin/custom-header.php
===================================================================
--- wp-admin/custom-header.php	(revision 19770)
+++ wp-admin/custom-header.php	(working copy)
@@ -173,6 +173,22 @@
 	}
 
 	/**
+	* Get the header height if using a flexible header (should this be in theme.php?)
+	* @since 3.4
+	*/
+	function flex_header_height() {
+		$header_support = get_theme_support( 'custom-header' );
+
+		if ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || ! $header_support[ 0 ][ 'flex-height' ] ) {
+			return HEADER_IMAGE_HEIGHT;
+		} else {
+			$header_image = get_header_image(); 
+			$header_image_post = get_page_by_title( substr( $header_image, strrpos( $header_image, '/') + 1 ), null, 'attachment' );
+			$header_image_info = wp_get_attachment_metadata( $header_image_post->ID );
+			return $header_image_info['height'];
+		}
+	}
+	/**
 	 * Execute custom header modification.
 	 *
 	 * @since 2.6.0
@@ -438,13 +454,20 @@
 		jQuery('img#upload').imgAreaSelect({
 			handles: true,
 			keys: true,
-			aspectRatio: xinit + ':' + yinit,
 			show: true,
 			x1: 0,
 			y1: 0,
 			x2: xinit,
 			y2: yinit,
+			<?php
+			$header_support = get_theme_support( 'custom-header' );
+			if ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || ! $header_support[ 0 ][ 'flex-height' ] ) {
+			?>
+			aspectRatio: xinit + ':' + yinit,
 			maxHeight: <?php echo HEADER_IMAGE_HEIGHT; ?>,
+			<?php
+			}
+			?>
 			maxWidth: <?php echo HEADER_IMAGE_WIDTH; ?>,
 			onInit: function () {
 				jQuery('#width').val(xinit);
@@ -490,9 +513,10 @@
 <td >
 	<?php if ( $this->admin_image_div_callback ) {
 	  call_user_func( $this->admin_image_div_callback );
-	} else {
+	} else { 
 	?>
-	<div id="headimg" style="max-width:<?php echo HEADER_IMAGE_WIDTH; ?>px;height:<?php echo HEADER_IMAGE_HEIGHT; ?>px;background-image:url(<?php esc_url ( header_image() ) ?>);">
+	<div id="headimg" style="max-width:<?php echo HEADER_IMAGE_WIDTH; ?>px;height:<?php 
+	echo $this->flex_header_height(); ?>px;background-image:url(<?php esc_url ( header_image() ) ?>);">
 		<?php
 		if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() )
 			$style = ' style="display:none;"';
@@ -510,7 +534,16 @@
 <th scope="row"><?php _e( 'Upload Image' ); ?></th>
 <td>
 	<p><?php _e( 'You can upload a custom header image to be shown at the top of your site instead of the default one. On the next screen you will be able to crop the image.' ); ?><br />
-	<?php printf( __( 'Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.' ), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ); ?></p>
+	<?php
+	$header_support = get_theme_support( 'custom-header' );
+	if ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || ! $header_support[ 0 ][ 'flex-height' ] ) {
+		printf( __( 'Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.' ), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT );
+	} else {
+		printf( __( 'Images should be at least <strong>%1$d pixels</strong> wide.' ), HEADER_IMAGE_WIDTH );
+		if ( ! empty( $header_support[ 0 ][ 'suggested-height' ] ) )
+			printf( __( ' Suggested height is <strong>%1$d pixels</strong>.' ), absint( $header_support[ 0 ][ 'suggested-height' ] ) );
+	}
+	?></p>
 	<form enctype="multipart/form-data" id="upload-form" method="post" action="<?php echo esc_attr( add_query_arg( 'step', 2 ) ) ?>">
 	<p>
 		<label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
@@ -662,7 +695,9 @@
 
 		list($width, $height, $type, $attr) = getimagesize( $file );
 
-		if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) {
+		$header_support = get_theme_support( 'custom-header' );
+		// If flexible height isn't supported and the image is the exact right size
+		if ( ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || !empty( $header_support[ 0 ][ 'flex-height' ] ) ) && $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) {
 			// Add the meta-data
 			wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
 			update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) );
@@ -733,7 +768,13 @@
 		$attachment_id = absint( $_POST['attachment_id'] );
 		$original = get_attached_file($attachment_id);
 
-		$cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT );
+		$header_support = get_theme_support( 'custom-header' );
+		if ( isset( $header_support[ 0 ] ) && ! empty( $header_support[ 0 ][ 'flex-height' ] ) )
+			$dst_height = (int) $_POST['height'] * ( HEADER_IMAGE_WIDTH / $_POST['width'] );
+		else
+			$dst_height = HEADER_IMAGE_HEIGHT;
+
+		$cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, $dst_height );
 		if ( is_wp_error( $cropped ) )
 			wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
 
