## Description: Determine image format by extension instead of a fixed PNG format.
## Origin/Author: Shih-Yuan Lee (FourDollars) <sylee@ubuntu.com>
## Bug: https://bugzilla.gnome.org/show_bug.cgi?id=521751
Index: gnome-screenshot-3.4.1/src/screenshot-application.c
===================================================================
--- gnome-screenshot-3.4.1.orig/src/screenshot-application.c	2012-06-27 18:01:09.128193708 +0800
+++ gnome-screenshot-3.4.1/src/screenshot-application.c	2012-06-27 18:02:14.008515432 +0800
@@ -213,6 +213,28 @@
   ScreenshotApplication *self = user_data;
   GFileOutputStream *os;
   GError *error = NULL;
+  gchar *basename = g_file_get_basename (G_FILE (source));
+  gchar *extension = g_strrstr (basename, ".");
+
+  if (extension == NULL)
+    extension = "png";
+  else
+    extension++;
+
+  GSList *result = gdk_pixbuf_get_formats();
+  void foreach_print (gpointer data, gpointer user_data) {
+      gchar** extensions = gdk_pixbuf_format_get_extensions ((GdkPixbufFormat*) data);
+      while (*extensions != NULL) {
+        if (g_strcmp0 (*extensions, extension) == 0) {
+          extension = gdk_pixbuf_format_get_name ((GdkPixbufFormat*) data);
+          break;
+        }
+        extensions++;
+      }
+  }
+  g_slist_foreach (result, foreach_print, NULL);
+
+  g_free (basename);
 
   if (self->priv->should_overwrite)
     os = g_file_replace_finish (G_FILE (source), res, &error);
@@ -229,17 +251,15 @@
   if (self->priv->icc_profile_base64 != NULL)
     gdk_pixbuf_save_to_stream_async (self->priv->screenshot,
                                      G_OUTPUT_STREAM (os),
-                                     "png", NULL,
+                                     extension, NULL,
                                      save_pixbuf_ready_cb, self,
                                      "icc-profile", self->priv->icc_profile_base64,
-                                     "tEXt::Software", "gnome-screenshot",
                                      NULL);
   else
     gdk_pixbuf_save_to_stream_async (self->priv->screenshot,
                                      G_OUTPUT_STREAM (os),
-                                     "png", NULL,
+                                     extension, NULL,
                                      save_pixbuf_ready_cb, self,
-                                     "tEXt::Software", "gnome-screenshot",
                                      NULL);
 
   g_object_unref (os);
