Index: src/rotation-utils.c
===================================================================
--- src/rotation-utils.c	(revision 1508)
+++ src/rotation-utils.c	(working copy)
@@ -83,12 +83,15 @@
 	jpeg_data_unref (jdata);
 }
 
+typedef struct {
+	const char  *path;
+	GtkWindow   *parent;
+} jpeg_mcu_dialog_data;
 
 static boolean
-jpeg_mcu_dialog (const char  *path,
-		 JXFORM_CODE *transform,
+jpeg_mcu_dialog (JXFORM_CODE *transform,
 		 boolean     *trim,
-		 GtkWindow   *parent)
+		 jpeg_mcu_dialog_data *userdata)
 {
 	char      *display_name;
 	char      *msg;
@@ -107,10 +110,10 @@
 	 * Warn about possible image distortions along one or more edges.
 	 */
 
-	display_name = basename_for_display (path);
+	display_name = basename_for_display (userdata->path);
 	msg = g_strdup_printf (_("Problem transforming the image: %s"), display_name);
 	d = _gtk_message_dialog_with_checkbutton_new (
-		parent,
+		userdata->parent,
 		GTK_DIALOG_MODAL,
 		GTK_STOCK_DIALOG_WARNING,
 		msg,
@@ -198,7 +201,8 @@
 		break;
 	}
 
-	if (jpegtran ((char*)path, tmp, transf, (jpegtran_mcu_callback) jpeg_mcu_dialog, win, &err) != 0) {
+	jpeg_mcu_dialog_data userdata = {path, win};
+	if (jpegtran ((char*)path, tmp, transf, (jpegtran_mcu_callback) jpeg_mcu_dialog, &userdata, &err) != 0) {
 		if (err != NULL)
 			_gtk_error_dialog_from_gerror_run (win, &err);
 		remove_temp_file_and_dir (tmp);
Index: libgthumb/jpegutils/jpegtran.h
===================================================================
--- libgthumb/jpegutils/jpegtran.h	(revision 1508)
+++ libgthumb/jpegutils/jpegtran.h	(working copy)
@@ -28,8 +28,7 @@
 #include <glib.h>
 #include "transupp.h"
 
-typedef boolean (*jpegtran_mcu_callback) (const char  *path,
-					  JXFORM_CODE *transform,
+typedef boolean (*jpegtran_mcu_callback) (JXFORM_CODE *transform,
 					  boolean     *trim,
 					  void        *userdata);
 
Index: libgthumb/jpegutils/jpegtran.c
===================================================================
--- libgthumb/jpegutils/jpegtran.c	(revision 1508)
+++ libgthumb/jpegutils/jpegtran.c	(working copy)
@@ -327,10 +327,10 @@
 
 
 static int
-jpegtran_internal (const char                    *path,
-		   struct jpeg_decompress_struct *srcinfo,
+jpegtran_internal (struct jpeg_decompress_struct *srcinfo,
 		   struct jpeg_compress_struct   *dstinfo,
 		   JXFORM_CODE                    transformation,
+		   JCOPY_OPTION                   option,
 		   jpegtran_mcu_callback          callback,
 		   void                          *userdata)
 {
@@ -343,7 +343,7 @@
 	transformoption.force_grayscale = FALSE;
 
 	/* Enable saving of extra markers that we want to copy */
-	jcopy_markers_setup (srcinfo, JCOPYOPT_ALL);
+	jcopy_markers_setup (srcinfo, option);
 
 	/* Read file header */
 	(void) jpeg_read_header (srcinfo, TRUE);
@@ -361,7 +361,7 @@
 			transformoption.trim = TRUE;
 		}
 		else if ((callback == JPEGTRAN_MCU_CANCEL) ||
-			  ! callback (path, &transformoption.transform, &transformoption.trim, userdata)) {
+			  ! callback (&transformoption.transform, &transformoption.trim, userdata)) {
 			// Abort transform
 			return 1;
 		}
@@ -380,11 +380,20 @@
 
 	/* Initialize destination compression parameters from source values */
 	jpeg_copy_critical_parameters (srcinfo, dstinfo);
+	
+	
+	/* Do not output a JFIF marker for EXIF thumbnails. 
+	 * This is not the optimal way to detect the difference 
+	 * between a thumbnail and a normal image, but it works
+	 * well for gThumb. */
+	if (option == JCOPYOPT_NONE) {
+		dstinfo->write_JFIF_header = FALSE;
+	}
 
 	/* Adjust the markers to create a standard EXIF file if an EXIF marker
 	 * is present in the input. By default, libjpeg creates a JFIF file, 
 	 * which is incompatible with the EXIF standard. */
-	jcopy_markers_exif (srcinfo, dstinfo, JCOPYOPT_ALL);
+	jcopy_markers_exif (srcinfo, dstinfo, option);
 
 	/* Adjust destination parameters if required by transform options;
 	 * also find out which set of coefficient arrays will hold the output.
@@ -399,7 +408,7 @@
 
 	/* Copy to the output file any extra markers that we want to
 	 * preserve */
-	jcopy_markers_execute (srcinfo, dstinfo, JCOPYOPT_ALL);
+	jcopy_markers_execute (srcinfo, dstinfo, option);
 
 	/* Execute image transformation, if any */
 	jtransform_execute_transformation (srcinfo,
@@ -474,7 +483,7 @@
 	jpeg_memory_dest (&dstinfo, odata, osize);
 
 	/* Apply transformation */
-	if (jpegtran_internal ("", &srcinfo, &dstinfo, transformation, NULL, NULL) != 0) {
+	if (jpegtran_internal (&srcinfo, &dstinfo, transformation, JCOPYOPT_NONE, NULL, NULL) != 0) {
 		jpeg_destroy_compress (&dstinfo);
 		jpeg_destroy_decompress (&srcinfo);
 		return 1;
@@ -566,7 +575,7 @@
 	jpeg_stdio_dest (&dstinfo, output_file);
 
 	/* Apply transformation */
-	if (jpegtran_internal (input_filename, &srcinfo, &dstinfo, transformation, callback, userdata) != 0) {
+	if (jpegtran_internal (&srcinfo, &dstinfo, transformation, JCOPYOPT_ALL, callback, userdata) != 0) {
 		jpeg_destroy_compress (&dstinfo);
 		jpeg_destroy_decompress (&srcinfo);
 		fclose (input_file);
