[gnome-initial-setup/wip/feborges/generate-user-pics] account: Round all the other images



commit 63479e3f7b01a7610b447aef76235af99b6a3b30
Author: Felipe Borges <felipeborges gnome org>
Date:   Tue Jan 29 12:33:20 2019 +0000

    account: Round all the other images

 .../pages/account/gis-account-page-local.c         |  6 ++---
 .../pages/account/um-photo-dialog.c                | 14 +++++++----
 gnome-initial-setup/pages/account/um-utils.c       | 27 ++++++++++++++++++++++
 gnome-initial-setup/pages/account/um-utils.h       |  2 ++
 4 files changed, 42 insertions(+), 7 deletions(-)
---
diff --git a/gnome-initial-setup/pages/account/gis-account-page-local.c 
b/gnome-initial-setup/pages/account/gis-account-page-local.c
index 70a8242..dfb3b39 100644
--- a/gnome-initial-setup/pages/account/gis-account-page-local.c
+++ b/gnome-initial-setup/pages/account/gis-account-page-local.c
@@ -224,7 +224,7 @@ prepopulate_account_page (GisAccountPageLocal *page)
   }
 
   if (pixbuf) {
-    gtk_image_set_from_pixbuf (GTK_IMAGE (priv->avatar_image), pixbuf);
+    gtk_image_set_from_pixbuf (GTK_IMAGE (priv->avatar_image), round_image (pixbuf));
     priv->avatar_pixbuf = pixbuf;
   }
 
@@ -359,13 +359,13 @@ avatar_callback (GdkPixbuf   *pixbuf,
   if (pixbuf) {
     priv->avatar_pixbuf = g_object_ref (pixbuf);
     tmp = gdk_pixbuf_scale_simple (pixbuf, 96, 96, GDK_INTERP_BILINEAR);
-    gtk_image_set_from_pixbuf (GTK_IMAGE (priv->avatar_image), tmp);
+    gtk_image_set_from_pixbuf (GTK_IMAGE (priv->avatar_image), round_image (tmp));
     g_object_unref (tmp);
   }
   else if (filename) {
     priv->avatar_filename = g_strdup (filename);
     tmp = gdk_pixbuf_new_from_file_at_size (filename, 96, 96, NULL);
-    gtk_image_set_from_pixbuf (GTK_IMAGE (priv->avatar_image), tmp);
+    gtk_image_set_from_pixbuf (GTK_IMAGE (priv->avatar_image), round_image (tmp));
     g_object_unref (tmp);
   }
   else {
diff --git a/gnome-initial-setup/pages/account/um-photo-dialog.c 
b/gnome-initial-setup/pages/account/um-photo-dialog.c
index 85f6b01..1292fe0 100644
--- a/gnome-initial-setup/pages/account/um-photo-dialog.c
+++ b/gnome-initial-setup/pages/account/um-photo-dialog.c
@@ -157,13 +157,19 @@ static GtkWidget *
 create_face_widget (gpointer item,
                     gpointer user_data)
 {
+        GdkPixbuf *pixbuf = NULL;
         GtkWidget *image;
-        GIcon *icon;
 
-        icon = g_file_icon_new (G_FILE (item));
-        image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
+        pixbuf = gdk_pixbuf_new_from_file_at_size (g_file_get_path (G_FILE (item)),
+                                                   AVATAR_PIXEL_SIZE,
+                                                   AVATAR_PIXEL_SIZE,
+                                                   NULL);
+        if (pixbuf == NULL)
+                return NULL;
+
+        image = gtk_image_new_from_pixbuf (round_image (pixbuf));
+        g_object_unref (pixbuf);
         gtk_image_set_pixel_size (GTK_IMAGE (image), AVATAR_PIXEL_SIZE);
-        g_object_unref (icon);
 
         gtk_widget_show (image);
 
diff --git a/gnome-initial-setup/pages/account/um-utils.c b/gnome-initial-setup/pages/account/um-utils.c
index 2d4fa4b..ab2608b 100644
--- a/gnome-initial-setup/pages/account/um-utils.c
+++ b/gnome-initial-setup/pages/account/um-utils.c
@@ -586,3 +586,30 @@ generate_user_picture (const gchar *name) {
 
         return surface;
 }
+
+GdkPixbuf *
+round_image (GdkPixbuf *image)
+{
+        GdkPixbuf *dest = NULL;
+        cairo_surface_t *surface;
+        cairo_t *cr;
+        gint size;
+
+        size = gdk_pixbuf_get_width (image);
+        surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, size, size);
+        cr = cairo_create (surface);
+
+        /* Clip a circle */
+        cairo_arc (cr, size/2, size/2, size/2, 0, 2 * G_PI);
+        cairo_clip (cr);
+        cairo_new_path (cr);
+
+        gdk_cairo_set_source_pixbuf (cr, image, 0, 0);
+        cairo_paint (cr);
+
+        dest = gdk_pixbuf_get_from_surface (surface, 0, 0, size, size);
+        cairo_surface_destroy (surface);
+        cairo_destroy (cr);
+
+        return dest;
+}
diff --git a/gnome-initial-setup/pages/account/um-utils.h b/gnome-initial-setup/pages/account/um-utils.h
index 7a3c010..78edbac 100644
--- a/gnome-initial-setup/pages/account/um-utils.h
+++ b/gnome-initial-setup/pages/account/um-utils.h
@@ -54,6 +54,8 @@ void     generate_username_choices        (const gchar     *name,
 
 cairo_surface_t *generate_user_picture    (const gchar     *name);
 
+GdkPixbuf       *round_image              (GdkPixbuf       *image);
+
 
 G_END_DECLS
 


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