Index: gdk-pixbuf-util.c
===================================================================
--- gdk-pixbuf-util.c	(revision 17867)
+++ gdk-pixbuf-util.c	(working copy)
@@ -245,6 +245,108 @@
         }
 }
 
+
+/**
+ * gdk_pixbuf_transform_orientation:
+ * @pixbuf: A #GdkPixbuf.
+ *
+ * Takes an existing pixbuf and checks for the presence of an
+ * associated "orientation" option, which may be provided by the 
+ * jpeg loader (which reads the exif orientation tag) or the 
+ * tiff loader (which reads the tiff orientation tag, and
+ * compensates it for the partial transforms performed by 
+ * libtiff). If an orientation option/tag is present, the
+ * appropriate transform will be performed so that the pixbuf
+ * is oriented correctly. The "orientation" option is then
+ * set to "0" (a string, not an integer).
+ *
+ * Return value: A newly-created pixbuf, or a reference to the
+ * input pixbuf (with an increased reference count). 	        
+ **/
+GdkPixbuf *
+gdk_pixbuf_transform_orientation (GdkPixbuf *src)
+{
+        GdkPixbuf   *dest;
+	GdkPixbuf   *temp;
+        GQuark       quark; 
+        gchar      **options; 
+        gint         n = 0; 
+  	const gchar *orientation_string;
+	gint64       transform = 0;
+
+	/* Need a source pixbuf, of course */
+        g_return_val_if_fail (GDK_IS_PIXBUF (src), NULL); 
+
+	/* Read the orientation option associated with the pixbuf */
+	orientation_string = gdk_pixbuf_get_option (src, "orientation");	
+
+	/* Convert the orientation string into an integer, for easier handling */
+	transform = g_ascii_strtoll (orientation_string, NULL, 10);
+
+	/* If no orientation option is present, return a reference 
+	   to the input pixbuf */
+	if (!orientation_string) {
+		dest = src;
+                g_object_ref (dest);
+		return dest;
+	}
+ 
+	/* Reset the orientation option to "0", to prevent the user from
+	   mangling the image by calling this function more than once. */
+        quark = g_quark_from_static_string ("gdk_pixbuf_options"); 
+        options = g_object_get_qdata (G_OBJECT (src), quark); 
+
+	for (n = 0; options[2*n]; n++) { 
+		if (strcmp (options[2*n], "orientation") == 0) {
+			/* remove the existing value */
+			g_free (options[2*n+1]);
+			/* reset it to "0" */
+			options[2*n+1] = g_strdup ("0");
+			break;
+		}
+	}
+
+	/* Apply the actual transforms, which involve rotations and flips. */
+        switch (transform) {
+        case 1:
+                dest = src;
+                g_object_ref (dest);
+                break;
+        case 2:
+                dest = gdk_pixbuf_flip (src, TRUE);
+                break;
+        case 3:
+                dest = gdk_pixbuf_rotate_simple (src, GDK_PIXBUF_ROTATE_UPSIDEDOWN);
+                break;
+        case 4:
+                dest = gdk_pixbuf_flip (src, FALSE);
+                break;
+        case 5:
+                temp = gdk_pixbuf_rotate_simple (src, GDK_PIXBUF_ROTATE_CLOCKWISE);
+                dest = gdk_pixbuf_flip (temp, TRUE);
+                g_object_unref (temp);
+                break;
+        case 6:
+                dest = gdk_pixbuf_rotate_simple (src, GDK_PIXBUF_ROTATE_CLOCKWISE);
+                break;
+        case 7:
+                temp = gdk_pixbuf_rotate_simple (src, GDK_PIXBUF_ROTATE_CLOCKWISE);
+                dest = gdk_pixbuf_flip (temp, FALSE);
+                g_object_unref (temp);
+                break;
+        case 8:
+                dest = gdk_pixbuf_rotate_simple (src, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
+                break;
+        default:
+                dest = src;
+                g_object_ref (dest);
+                break;
+        }
+	
+        return dest;
+}
+
+
 #define __GDK_PIXBUF_UTIL_C__
 #include "gdk-pixbuf-aliasdef.c"
 
Index: gdk-pixbuf-core.h
===================================================================
--- gdk-pixbuf-core.h	(revision 17867)
+++ gdk-pixbuf-core.h	(working copy)
@@ -231,6 +231,8 @@
                                        gfloat           saturation,
                                        gboolean         pixelate);
 
+/* Transform an image to agree with its embedded orientation tag */
+GdkPixbuf *gdk_pixbuf_transform_orientation (GdkPixbuf *src);
 
 G_CONST_RETURN gchar * gdk_pixbuf_get_option (GdkPixbuf   *pixbuf,
                                               const gchar *key);
