--- gthumb-old/libgthumb/image-loader.c	2006-08-17 10:16:45.000000000 -0600
+++ gthumb/libgthumb/image-loader.c	2006-10-04 10:33:48.000000000 -0600
@@ -37,6 +37,8 @@
 #include "gthumb-marshal.h"
 #include "file-utils.h"
 #include "glib-utils.h"
+#include "gth-exif-utils.h"
+#include "pixbuf-utils.h"
 
 
 #define REFRESH_RATE 5
@@ -406,15 +408,74 @@
 }
 
 
+/* If no change is needed, returns a copy of img. Otherwise, returns a new
+GdkPixbuf (and you may need to free img) */
+static GdkPixbuf*
+image_rotate_exif (GdkPixbuf *img, 
+                   const char *path)
+{
+#ifdef HAVE_LIBEXIF
+	GdkPixbuf	       *result = NULL, *temp = NULL;
+	GthExifOrientation	orientation;
+	
+	orientation = get_exif_tag_short(path, EXIF_TAG_ORIENTATION);
+	
+	if (img == NULL)
+		return NULL;
+	
+	switch (orientation) {
+	case GTH_EXIF_ORIENTATION_TOP_LEFT:
+		result = img;
+		break;
+	case GTH_EXIF_ORIENTATION_TOP_RIGHT:
+		result = _gdk_pixbuf_copy_mirror (img, TRUE, FALSE);
+		break;
+	case GTH_EXIF_ORIENTATION_BOTTOM_RIGHT:
+		result = _gdk_pixbuf_copy_mirror (img, TRUE, TRUE);
+		break;
+	case GTH_EXIF_ORIENTATION_BOTTOM_LEFT:
+		result = _gdk_pixbuf_copy_mirror (img, FALSE, TRUE);
+		break;
+	case GTH_EXIF_ORIENTATION_LEFT_TOP:
+		temp = _gdk_pixbuf_copy_rotate_90 (img, FALSE);
+		result = _gdk_pixbuf_copy_mirror (temp, TRUE, FALSE);
+		g_object_unref (temp);
+		temp = NULL;
+		break;
+	case GTH_EXIF_ORIENTATION_RIGHT_TOP:
+		result = _gdk_pixbuf_copy_rotate_90 (img, FALSE);
+		break;
+	case GTH_EXIF_ORIENTATION_RIGHT_BOTTOM:
+		temp = _gdk_pixbuf_copy_rotate_90 (img, FALSE);
+		result = _gdk_pixbuf_copy_mirror (temp, FALSE, TRUE);
+		g_object_unref (temp);
+		temp = NULL;
+		break;
+	case GTH_EXIF_ORIENTATION_LEFT_BOTTOM:
+		result = _gdk_pixbuf_copy_rotate_90 (img, TRUE);
+		break;
+	default:
+		result = img;
+		break;
+	}
+	
+	return result;
+#else
+	return img;
+#endif /* HAVE_LIBEXIF */
+}
+
 static void 
 image_loader_sync_pixbuf (ImageLoader *il)
 {
-	GdkPixbuf              *pixbuf;
+	GdkPixbuf              *pixbuf, *temp;
 	ImageLoaderPrivateData *priv;
+	const char	       *path;
   
 	g_return_if_fail (il != NULL);
      
 	priv = il->priv;
+	path = image_loader_get_path(il);
 
 	g_mutex_lock (priv->yes_or_no);
 
@@ -426,7 +487,11 @@
 		return;
 	}
 
-	pixbuf = gdk_pixbuf_animation_get_static_image (priv->animation);
+ 	temp = gdk_pixbuf_animation_get_static_image (priv->animation);
+	pixbuf = image_rotate_exif (temp, path);
+	/* (*temp) is internal to priv->animation; we don't need to free it */
+	temp = NULL;
+
 	g_object_ref (pixbuf);
 
 	if (priv->pixbuf == pixbuf) {
