Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1227
diff -u -p -r1.1227 common.inc
--- includes/common.inc	25 Sep 2010 02:00:06 -0000	1.1227
+++ includes/common.inc	26 Sep 2010 22:39:59 -0000
@@ -5843,7 +5843,7 @@ function drupal_common_theme() {
       // - http://dev.w3.org/html5/spec/Overview.html#alt
       // The title attribute is optional in all cases, so it is omitted by
       // default.
-      'variables' => array('path' => NULL, 'width' => NULL, 'height' => NULL, 'alt' => '', 'title' => NULL, 'attributes' => array()),
+      'variables' => array('path' => NULL, 'alt' => '', 'title' => NULL, 'attributes' => array(), 'getsize' => TRUE),
     ),
     'breadcrumb' => array(
       'variables' => array('breadcrumb' => NULL),
Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.614
diff -u -p -r1.614 theme.inc
--- includes/theme.inc	24 Sep 2010 21:20:08 -0000	1.614
+++ includes/theme.inc	26 Sep 2010 22:40:00 -0000
@@ -1480,8 +1480,6 @@ function theme_links($variables) {
  *   An associative array containing:
  *   - path: Either the path of the image file (relative to base_path()) or a
  *     full URL.
- *   - width: The width of the image (if known).
- *   - height: The height of the image (if known).
  *   - alt: The alternative text for text-based browsers. HTML 4 and XHTML 1.0
  *     always require an alt attribute. The HTML 5 draft allows the alt
  *     attribute to be omitted in some cases. Therefore, this variable defaults
@@ -1495,19 +1493,38 @@ function theme_links($variables) {
  *   - title: The title text is displayed when the image is hovered in some
  *     popular browsers.
  *   - attributes: Associative array of attributes to be placed in the img tag.
+ *   - getsize: If set to TRUE, the image's dimension are fetched and added as
+ *     width/height attributes.
  */
 function theme_image($variables) {
+  $path = $variables['path'];
+  $alt = $variables['alt'];
+  $title = $variables['title'];
   $attributes = $variables['attributes'];
-  $attributes['src'] = file_create_url($variables['path']);
-
-  foreach (array('width', 'height', 'alt', 'title') as $key) {
+  $getsize = $variables['getsize'];
 
-    if (isset($variables[$key])) {
-      $attributes[$key] = $variables[$key];
+  if (!$getsize || (is_file($path) && (list($width, $height) = @getimagesize($path)))) {
+    // The src attribute can be omitted, by passing NULL for $path and FALSE for
+    // $getsize.
+    if (isset($path)) {
+      $attributes['src'] = file_create_url($path);
+    }
+    // The alt attribute defaults to an empty string. By passing NULL as value,
+    // it can be omitted.
+    if (isset($alt)) {
+      $attributes['alt'] = $alt;
+    }
+    if (isset($title)) {
+      $attributes['title'] = $title;
     }
+    if (!isset($attributes['width']) && !empty($width)) {
+      $attributes['width'] = $width;
+    }
+    if (!isset($attributes['height']) && !empty($height)) {
+      $attributes['height'] = $height;
+    }
+    return '<img' . drupal_attributes($attributes) . ' />';
   }
-
-  return '<img' . drupal_attributes($attributes) . ' />';
 }
 
 /**
Index: modules/color/color.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/color/color.module,v
retrieving revision 1.91
diff -u -p -r1.91 color.module
--- modules/color/color.module	22 Sep 2010 03:24:09 -0000	1.91
+++ modules/color/color.module	26 Sep 2010 22:40:00 -0000
@@ -63,7 +63,7 @@ function _color_theme_select_form_alter(
   foreach (element_children($form) as $theme) {
     if ($screenshot = variable_get('color_' . $theme . '_screenshot')) {
       if (isset($form[$theme]['screenshot'])) {
-        $form[$theme]['screenshot']['#markup'] = theme('image', array('path' => $screenshot, 'title' => '', 'attributes' => array('class' => array('screenshot'))));
+        $form[$theme]['screenshot']['#markup'] = theme('image', array('path' => $screenshot, 'alt' => '', 'title' => '', 'attributes' => array('class' => array('screenshot')), 'getsize' => FALSE));
       }
     }
   }
Index: modules/image/image.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/image/image.admin.inc,v
retrieving revision 1.23
diff -u -p -r1.23 image.admin.inc
--- modules/image/image.admin.inc	24 Sep 2010 21:36:22 -0000	1.23
+++ modules/image/image.admin.inc	26 Sep 2010 22:40:00 -0000
@@ -796,7 +796,7 @@ function theme_image_style_preview($vari
   $output .= '<div class="preview-image-wrapper">';
   $output .= t('original') . ' (' . l(t('view actual size'), $original_path) . ')';
   $output .= '<div class="preview-image original-image" style="' . $original_attributes['style'] . '">';
-  $output .= '<a href="' . url($original_path) . '?' . time() . '">' . theme('image', array('path' => $original_path . '?' . time(), 'alt' => t('Sample original image'), 'title' => '', 'attributes' => $original_attributes)) . '</a>';
+  $output .= '<a href="' . url($original_path) . '?' . time() . '">' . theme('image', array('path' => $original_path . '?' . time(), 'alt' => t('Sample original image'), 'title' => '', 'attributes' => $original_attributes, 'getsize' => FALSE)) . '</a>';
   $output .= '<div class="height" style="height: ' . $original_height . 'px"><span>' . $original_image['height'] . 'px</span></div>';
   $output .= '<div class="width" style="width: ' . $original_width . 'px"><span>' . $original_image['width'] . 'px</span></div>';
   $output .= '</div>'; // End preview-image.
@@ -806,7 +806,7 @@ function theme_image_style_preview($vari
   $output .= '<div class="preview-image-wrapper">';
   $output .= check_plain($style['name']) . ' (' . l(t('view actual size'), file_create_url($preview_file) . '?' . time()) . ')';
   $output .= '<div class="preview-image modified-image" style="' . $preview_attributes['style'] . '">';
-  $output .= '<a href="' . file_create_url($preview_file) . '?' . time() . '">' . theme('image', array('path' => file_create_url($preview_file) . '?' . time(), 'alt' => t('Sample modified image'), 'title' => '', 'attributes' => $preview_attributes)) . '</a>';
+  $output .= '<a href="' . file_create_url($preview_file) . '?' . time() . '">' . theme('image', array('path' => file_create_url($preview_file) . '?' . time(), 'alt' => t('Sample modified image'), 'title' => '', 'attributes' => $preview_attributes, 'getsize' => FALSE)) . '</a>';
   $output .= '<div class="height" style="height: ' . $preview_height . 'px"><span>' . $preview_image['height'] . 'px</span></div>';
   $output .= '<div class="width" style="width: ' . $preview_width . 'px"><span>' . $preview_image['width'] . 'px</span></div>';
   $output .= '</div>'; // End preview-image.
Index: modules/image/image.field.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/image/image.field.inc,v
retrieving revision 1.29
diff -u -p -r1.29 image.field.inc
--- modules/image/image.field.inc	24 Sep 2010 21:36:22 -0000	1.29
+++ modules/image/image.field.inc	26 Sep 2010 22:40:00 -0000
@@ -339,7 +339,7 @@ function image_field_widget_process($ele
   if ($element['#file'] && $widget_settings['preview_image_style']) {
     $element['preview'] = array(
       '#type' => 'markup',
-      '#markup' => theme('image_style', array('style_name' => $widget_settings['preview_image_style'], 'path' => $element['#file']->uri)),
+      '#markup' => theme('image_style', array('style_name' => $widget_settings['preview_image_style'], 'path' => $element['#file']->uri, 'getsize' => FALSE)),
     );
   }
 
Index: modules/image/image.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/image/image.module,v
retrieving revision 1.52
diff -u -p -r1.52 image.module
--- modules/image/image.module	24 Sep 2010 00:37:43 -0000	1.52
+++ modules/image/image.module	26 Sep 2010 22:40:00 -0000
@@ -1099,6 +1099,7 @@ function theme_image_style($variables) {
     $style_path = image_style_url($style_name, $path);
   }
   $variables['path'] = $style_path;
+  $variables['getsize'] = FALSE;
   return theme('image', $variables);
 }
 
Index: modules/image/image.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/image/image.test,v
retrieving revision 1.31
diff -u -p -r1.31 image.test
--- modules/image/image.test	22 Sep 2010 03:24:09 -0000	1.31
+++ modules/image/image.test	26 Sep 2010 22:40:00 -0000
@@ -650,6 +650,7 @@ class ImageFieldDisplayTestCase extends 
     $image_uri = $node->{$field_name}[LANGUAGE_NONE][0]['uri'];
     $image_info = array(
       'path' => $image_uri,
+      'getsize' => TRUE,
     );
     $default_output = theme('image', $image_info);
     $this->assertRaw($default_output, t('Default formatter displaying correctly on full node view.'));
@@ -745,6 +746,7 @@ class ImageFieldDisplayTestCase extends 
     $node = node_load($nid, NULL, TRUE);
     $image_info = array(
       'path' => image_style_url('medium', $node->{$field_name}[LANGUAGE_NONE][0]['uri']),
+      'getsize' => FALSE,
     );
     $default_output = theme('image', $image_info);
     $this->assertRaw($default_output, t("Preview image is displayed using 'medium' style."));
@@ -754,6 +756,7 @@ class ImageFieldDisplayTestCase extends 
       'path' => $node->{$field_name}[LANGUAGE_NONE][0]['uri'],
       'alt' => $this->randomName(),
       'title' => $this->randomName(),
+      'getsize' => TRUE,
     );
     $edit = array(
       $field_name . '[' . LANGUAGE_NONE . '][0][alt]' => $image_info['alt'],
@@ -790,7 +793,7 @@ class ImageFieldDisplayTestCase extends 
     field_info_cache_clear();
     $field = field_info_field($field_name);
     $image = file_load($field['settings']['default_image']);
-    $default_output = theme('image', array('path' => $image->uri));
+    $default_output = theme('image', array('path' => $image->uri, 'getsize' => TRUE));
     $this->drupalGet('node/' . $node->nid);
     $this->assertRaw($default_output, t('Default image displayed when no user supplied image is present.'));
 
@@ -800,6 +803,7 @@ class ImageFieldDisplayTestCase extends 
     $node = node_load($nid, NULL, TRUE);
     $image_info = array(
       'path' => $node->{$field_name}[LANGUAGE_NONE][0]['uri'],
+      'getsize' => TRUE,
     );
     $image_output = theme('image', $image_info);
     $this->drupalGet('node/' . $nid);
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.1204
diff -u -p -r1.1204 user.module
--- modules/user/user.module	24 Sep 2010 00:37:45 -0000	1.1204
+++ modules/user/user.module	26 Sep 2010 22:40:01 -0000
@@ -1410,10 +1410,10 @@ function template_preprocess_user_pictur
     if (isset($filepath)) {
       $alt = t("@user's picture", array('@user' => format_username($account)));
       if (module_exists('image') && $style = variable_get('user_picture_style', '')) {
-        $variables['user_picture'] = theme('image_style', array('style_name' => $style, 'path' => $filepath, 'alt' => $alt, 'title' => $alt));
+        $variables['user_picture'] = theme('image_style', array('style_name' => $style, 'path' => $filepath, 'alt' => $alt, 'title' => $alt, 'attributes' => array(), 'getsize' => FALSE));
       }
       else {
-        $variables['user_picture'] = theme('image', array('path' => $filepath, 'alt' => $alt, 'title' => $alt));
+        $variables['user_picture'] = theme('image', array('path' => $filepath, 'alt' => $alt, 'title' => $alt, 'attributes' => array(), 'getsize' => FALSE));
       }
       if (!empty($account->uid) && user_access('access user profiles')) {
         $attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE);
