diff -Nupr -X diff.ignore orig.gthumb/libgthumb/gth-exif-utils.c modi.gthumb/libgthumb/gth-exif-utils.c
--- orig.gthumb/libgthumb/gth-exif-utils.c	2006-10-08 09:45:26.000000000 +0100
+++ modi.gthumb/libgthumb/gth-exif-utils.c	2006-11-08 16:35:08.000000000 +0000
@@ -337,3 +337,25 @@ copy_exif_data (const char *src,
 	exif_data_unref (edata);
 }
 
+void
+set_orientation_in_exif_data (GthTransform  transform,
+			      ExifData     *edata)
+{
+	unsigned int  i;
+
+	for (i = 0; i < EXIF_IFD_COUNT; i++) {
+		ExifContent *content = edata->ifd[i];
+		ExifEntry   *entry;
+
+		if ((content == NULL) || (content->count == 0)) 
+			continue;
+
+		entry = exif_content_get_entry (content, EXIF_TAG_ORIENTATION);
+		if (entry != NULL) {
+			ExifByteOrder byte_order;
+			byte_order = exif_data_get_byte_order (edata);
+			exif_set_short (entry->data, byte_order, transform);
+		}
+	}
+}
+
diff -Nupr -X diff.ignore orig.gthumb/libgthumb/gth-exif-utils.h modi.gthumb/libgthumb/gth-exif-utils.h
--- orig.gthumb/libgthumb/gth-exif-utils.h	2006-10-12 20:15:11.000000000 +0100
+++ modi.gthumb/libgthumb/gth-exif-utils.h	2006-11-08 16:35:03.000000000 +0000
@@ -31,6 +31,7 @@
 #include <libexif/exif-entry.h>
 #include <libexif/exif-utils.h>
 #include "jpegutils/jpeg-data.h"
+#include "typedefs.h"
 
 
 char *      get_exif_tag            (const char *filename,
@@ -46,5 +47,7 @@ void        save_exif_data          (con
 				     ExifData   *edata);
 void        copy_exif_data          (const char *src,
 				     const char *dest);
+void   set_orientation_in_exif_data (GthTransform  transform,
+				     ExifData     *edata);
 
 #endif /* EXIF_UTILS_H */
diff -Nupr -X diff.ignore orig.gthumb/src/catalog-web-exporter.c modi.gthumb/src/catalog-web-exporter.c
--- orig.gthumb/src/catalog-web-exporter.c	2006-11-07 12:46:59.000000000 +0000
+++ modi.gthumb/src/catalog-web-exporter.c	2006-11-08 16:34:56.000000000 +0000
@@ -1782,6 +1782,9 @@ copy_exif_from_orig (const char *src_fil
 	if (jdata_dest == NULL)
 		return;
 
+	/* The exif orientation tag, if present, must be reset to "top-left" */
+	set_orientation_in_exif_data (GTH_TRANSFORM_NONE, edata_src);
+
 	jpeg_data_set_exif_data (jdata_dest, edata_src);
 
 	jpeg_data_save_file (jdata_dest, dest_filename);
@@ -1789,9 +1792,6 @@ copy_exif_from_orig (const char *src_fil
 	exif_data_unref (edata_src);
 	jpeg_data_unref (jdata_src);
 	jpeg_data_unref (jdata_dest);
-
-	/* The exif orientation tag, if present, must be reset to "top-left" */
-	write_orientation_field (dest_filename, GTH_TRANSFORM_NONE);
 }
 
 
diff -Nupr -X diff.ignore orig.gthumb/src/gth-browser.c modi.gthumb/src/gth-browser.c
--- orig.gthumb/src/gth-browser.c	2006-11-07 01:24:23.000000000 +0000
+++ modi.gthumb/src/gth-browser.c	2006-11-08 16:43:01.000000000 +0000
@@ -1822,15 +1822,14 @@ save_jpeg_data (GthBrowser *browser,
 	}
 #endif /* HAVE_LIBIPTCDATA */
 
-	if (priv->exif_data != NULL) 
+	if (priv->exif_data != NULL) {
+		/* The exif orientation tag, if present, must be reset to "top-left" */
+		set_orientation_in_exif_data (GTH_TRANSFORM_NONE, priv->exif_data);
 		jpeg_data_set_exif_data (jdata, priv->exif_data);
+	}
 
 	jpeg_data_save_file (jdata, filename);
 	jpeg_data_unref (jdata);
-
-	/* The exif orientation tag, if present, must be reset to "top-left" */
-	write_orientation_field (filename, GTH_TRANSFORM_NONE);
-
 }
 
 
diff -Nupr -X diff.ignore orig.gthumb/src/gth-viewer.c modi.gthumb/src/gth-viewer.c
--- orig.gthumb/src/gth-viewer.c	2006-11-05 13:22:42.000000000 +0000
+++ modi.gthumb/src/gth-viewer.c	2006-11-08 16:42:55.000000000 +0000
@@ -844,6 +844,9 @@ save_jpeg_data (GthViewer  *viewer,
 	if (filename == NULL)
 		return;
 
+	if (!image_is_jpeg (filename))
+		return;
+
 	if (priv->exif_data != NULL) 
 		data_to_save = TRUE;
 	
@@ -877,14 +880,14 @@ save_jpeg_data (GthViewer  *viewer,
 	}
 #endif /* HAVE_LIBIPTCDATA */
 
-	if (priv->exif_data != NULL) 
+	if (priv->exif_data != NULL) {
+		/* The exif orientation tag, if present, must be reset to "top-left" */
+		set_orientation_in_exif_data (GTH_TRANSFORM_NONE, priv->exif_data);
 		jpeg_data_set_exif_data (jdata, priv->exif_data);
+	}
 
 	jpeg_data_save_file (jdata, filename);
 	jpeg_data_unref (jdata);
-
-	/* The exif orientation tag, if present, must be reset to "top-left" */
-	write_orientation_field (filename, GTH_TRANSFORM_NONE);
 }
 
 
diff -Nupr -X diff.ignore orig.gthumb/src/rotation-utils.c modi.gthumb/src/rotation-utils.c
--- orig.gthumb/src/rotation-utils.c	2006-11-05 20:24:28.000000000 +0000
+++ modi.gthumb/src/rotation-utils.c	2006-11-08 16:34:59.000000000 +0000
@@ -57,7 +57,6 @@ write_orientation_field (const char   *p
 {
 	JPEGData     *jdata;
 	ExifData     *edata;
-	unsigned int  i;
 
 	path = get_file_path_from_uri (path);
 	if (path == NULL)
@@ -73,20 +72,7 @@ write_orientation_field (const char   *p
 		return;
 	}
 
-	for (i = 0; i < EXIF_IFD_COUNT; i++) {
-		ExifContent *content = edata->ifd[i];
-		ExifEntry   *entry;
-
-		if ((content == NULL) || (content->count == 0)) 
-			continue;
-
-		entry = exif_content_get_entry (content, EXIF_TAG_ORIENTATION);
-		if (entry != NULL) {
-			ExifByteOrder byte_order;
-			byte_order = exif_data_get_byte_order (edata);
-			exif_set_short (entry->data, byte_order, transform);
-		}
-	}
+	set_orientation_in_exif_data (transform, edata);
 
 	jpeg_data_save_file (jdata, path);
 
@@ -124,6 +110,8 @@ jtransform_perfect_transform(gint image_
 		if (image_height % MCU_height)
 			result = FALSE;
 		break;
+	default:
+		break;
 	}
 
 	return result;
