Index: wp-includes/media.php
===================================================================
--- wp-includes/media.php	(revision 18522)
+++ wp-includes/media.php	(working copy)
@@ -442,6 +442,16 @@
 	if ( !is_null($dest_path) and $_dest_path = realpath($dest_path) )
 		$dir = $_dest_path;
 	$destfilename = "{$dir}/{$name}-{$suffix}.{$ext}";
+	
+	// If the file already exists, add a numeric suffix and increment it until
+	// the new file name is available
+	if ( file_exists($destfilename) ) {
+		$i = 1;
+		do {
+			$destfilename = "{$dir}/{$name}{$i}-{$suffix}.{$ext}";
+			$i++;
+		} while ( file_exists($destfilename) );
+	}
 
 	if ( IMAGETYPE_GIF == $orig_type ) {
 		if ( !imagegif( $newimage, $destfilename ) )
@@ -451,7 +461,7 @@
 			return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
 	} else {
 		// all other formats are converted to jpg
-		$destfilename = "{$dir}/{$name}-{$suffix}.jpg";
+		$destfilename = substr($destfilename, 0, 0 - strlen($ext)) . 'jpg';
 		if ( !imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) )
 			return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
 	}
