[recipes] Apply image rotation on disk



commit 894542f4541d1f0ca0cb2f6c142a56ead31253ac
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Feb 18 17:07:27 2017 -0500

    Apply image rotation on disk
    
    This is not as elegant, but makes for a simpler data model,
    and will help with other things.

 src/gr-image-viewer.c |    2 +-
 src/gr-utils.c        |   29 +++++++++++++++++++++++++++++
 src/gr-utils.h        |    2 ++
 3 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/src/gr-image-viewer.c b/src/gr-image-viewer.c
index 10fda33..2b7e337 100644
--- a/src/gr-image-viewer.c
+++ b/src/gr-image-viewer.c
@@ -642,8 +642,8 @@ gr_image_viewer_rotate_image (GrImageViewer *viewer,
         g_assert (angle == 0 || angle == 90 || angle == 180 || angle == 270);
 
         ri = &g_array_index (viewer->images, GrRotatedImage, viewer->index);
-        ri->angle = (ri->angle + angle) % 360;
 
+        rotate_image (ri->path, angle);
         populate_preview (viewer);
         set_current_image (viewer);
 
diff --git a/src/gr-utils.c b/src/gr-utils.c
index cbb02a0..0bc54cd 100644
--- a/src/gr-utils.c
+++ b/src/gr-utils.c
@@ -706,3 +706,32 @@ import_image (const char *path)
         return imported;
 }
 
+void
+rotate_image (const char *path,
+              int         angle)
+{
+        g_autoptr(GdkPixbuf) pixbuf = NULL;
+        g_autoptr(GdkPixbuf) oriented = NULL;
+        g_autoptr(GError) error = NULL;
+        GdkPixbufFormat *format;
+        g_autofree char *format_name = NULL;
+
+        pixbuf = gdk_pixbuf_new_from_file (path, &error);
+        if (pixbuf== NULL) {
+                g_message ("Failed to load image '%s': %s", path, error->message);
+                return;
+        }
+
+        format = gdk_pixbuf_get_file_info (path, NULL, NULL);
+        if (gdk_pixbuf_format_is_writable (format))
+                format_name = gdk_pixbuf_format_get_name (format);
+        else
+                format_name = g_strdup ("png");
+
+        oriented = gdk_pixbuf_rotate_simple (pixbuf, angle);
+
+        if (!gdk_pixbuf_save (oriented, path, format_name, &error, NULL)) {
+                g_message ("Failed to save rotated image: %s", error->message);
+                return;
+        }
+}
diff --git a/src/gr-utils.h b/src/gr-utils.h
index 6fd3277..dee0f8d 100644
--- a/src/gr-utils.h
+++ b/src/gr-utils.h
@@ -81,3 +81,5 @@ void
 window_unexport_handle (GtkWindow *window);
 
 char *import_image (const char *path);
+void  rotate_image (const char *path,
+                    int         angle);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]