Index: libgnomeui/gnome-vfs-util.c
===================================================================
--- libgnomeui/gnome-vfs-util.c	(revision 5299)
+++ libgnomeui/gnome-vfs-util.c	(working copy)
@@ -60,6 +60,8 @@ struct GnomeGdkPixbufAsyncHandle {
 typedef struct {
     gint width;
     gint height;
+    gint input_width;
+    gint input_height;
     gboolean preserve_aspect_ratio;
 } SizePrepareContext;
 
@@ -104,6 +106,9 @@ size_prepared_cb (GdkPixbufLoader *loade
 
 	g_return_if_fail (width > 0 && height > 0);
 
+	info->input_width = width;
+	info->input_height = height;
+	
 	if (width < info->width && height < info->height) return;
 	
 	if (info->preserve_aspect_ratio && 
@@ -184,6 +189,7 @@ gnome_gdk_pixbuf_new_from_uri_at_scale (
     if (1 <= width || 1 <= height) {
         info.width = width;
         info.height = height;
+	info.input_width = info.input_height = 0;
         info.preserve_aspect_ratio = preserve_aspect_ratio;        
         g_signal_connect (loader, "size-prepared", G_CALLBACK (size_prepared_cb), &info);
     }
@@ -235,6 +241,11 @@ gnome_gdk_pixbuf_new_from_uri_at_scale (
     }
     g_object_unref (G_OBJECT (loader));
 
+    g_object_set_data (G_OBJECT (pixbuf), "gnome-original-width",
+		       GINT_TO_POINTER (info.input_width));
+    g_object_set_data (G_OBJECT (pixbuf), "gnome-original-height",
+		       GINT_TO_POINTER (info.input_height));
+    
     return pixbuf;
 }
 
Index: libgnomeui/gnome-thumbnail-pixbuf-utils.c
===================================================================
--- libgnomeui/gnome-thumbnail-pixbuf-utils.c	(revision 5299)
+++ libgnomeui/gnome-thumbnail-pixbuf-utils.c	(working copy)
@@ -350,6 +350,7 @@ _gnome_thumbnail_load_scaled_jpeg (const
 				   int         target_width,
 				   int         target_height)
 {
+	GdkPixbuf *pixbuf;
 	struct jpeg_decompress_struct cinfo;
 	Source src;
 	ErrorHandlerData jerr;
@@ -454,13 +455,20 @@ _gnome_thumbnail_load_scaled_jpeg (const
 	
 	gnome_vfs_close (handle);
 	
-	return gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB,
-					 cinfo.out_color_components == 4 ? TRUE : FALSE,
-					 8,
-					 cinfo.output_width,
-					 cinfo.output_height,
-					 cinfo.output_width * out_n_components,
-					 free_buffer, NULL);
+	pixbuf = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB,
+					   cinfo.out_color_components == 4 ? TRUE : FALSE,
+					   8,
+					   cinfo.output_width,
+					   cinfo.output_height,
+					   cinfo.output_width * out_n_components,
+					   free_buffer, NULL);
+
+	g_object_set_data (G_OBJECT (pixbuf), "gnome-original-width",
+			   GINT_TO_POINTER (cinfo.image_width));
+	g_object_set_data (G_OBJECT (pixbuf), "gnome-original-height",
+			   GINT_TO_POINTER (cinfo.image_height));
+
+	return pixbuf;
 }
 
 #endif /* HAVE_LIBJPEG */
Index: libgnomeui/gnome-thumbnail.c
===================================================================
--- libgnomeui/gnome-thumbnail.c	(revision 5299)
+++ libgnomeui/gnome-thumbnail.c	(working copy)
@@ -942,6 +942,8 @@ gnome_thumbnail_factory_generate_thumbna
   GdkPixbuf *pixbuf, *scaled;
   char *script, *expanded_script;
   int width, height, size;
+  int original_width, original_height;
+  char dimension[12];
   double scale;
   int exit_status;
   char *tmpname;
@@ -999,12 +1001,13 @@ gnome_thumbnail_factory_generate_thumbna
     return NULL;
 
   width = gdk_pixbuf_get_width (pixbuf);
-  g_object_set_data_full (G_OBJECT (pixbuf), "gnome-thumbnail-width",
-			  g_strdup_printf ("%d", width), g_free);
   height = gdk_pixbuf_get_height (pixbuf);
-  g_object_set_data_full (G_OBJECT (pixbuf), "gnome-thumbnail-height",
-			  g_strdup_printf ("%d", height), g_free);
 
+  original_width = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (pixbuf),
+						       "gnome-original-width"));
+  original_height = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (pixbuf),
+							"gnome-original-height"));
+  
   if (width > size || height > size)
     {
       scale = (double)size / MAX (width, height);
@@ -1017,6 +1020,15 @@ gnome_thumbnail_factory_generate_thumbna
       pixbuf = scaled;
     }
   
+  if (original_width > 0) {
+	  g_snprintf (dimension, sizeof (dimension), "%i", original_width);
+	  gdk_pixbuf_set_option (pixbuf, "tEXt::Thumb::Image::Width", dimension);
+  }
+  if (original_height > 0) {
+	  g_snprintf (dimension, sizeof (dimension), "%i", original_height);
+	  gdk_pixbuf_set_option (pixbuf, "tEXt::Thumb::Image::Height", dimension);
+  }
+
   return pixbuf;
 }
 
@@ -1175,12 +1187,8 @@ gnome_thumbnail_factory_save_thumbnail (
   close (tmp_fd);
   
   g_snprintf (mtime_str, 21, "%ld",  original_mtime);
-  width = g_object_get_data (G_OBJECT (thumbnail), "gnome-thumbnail-width");
-  if (width == NULL)
-    width = gdk_pixbuf_get_option (thumbnail, "tEXt::Thumb::Image::Width");
-  height = g_object_get_data (G_OBJECT (thumbnail), "gnome-thumbnail-height");
-  if (height == NULL)
-    height = gdk_pixbuf_get_option (thumbnail, "tEXt::Thumb::Image::Height");
+  width = gdk_pixbuf_get_option (thumbnail, "tEXt::Thumb::Image::Width");
+  height = gdk_pixbuf_get_option (thumbnail, "tEXt::Thumb::Image::Height");
 
   if (width != NULL && height != NULL) 
     saved_ok  = gdk_pixbuf_save (thumbnail,
