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



commit 40d3f1715cc289a368cb09dbbe566e32f1726097
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         | 14 +++++++----
 .../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, 49 insertions(+), 8 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..ded94d0 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,10 @@ prepopulate_account_page (GisAccountPageLocal *page)
   }
 
   if (pixbuf) {
-    gtk_image_set_from_pixbuf (GTK_IMAGE (priv->avatar_image), pixbuf);
+    GdkPixbuf *rounded = round_image (pixbuf);
+
+    gtk_image_set_from_pixbuf (GTK_IMAGE (priv->avatar_image), rounded);
+    g_object_unref (rounded);
     priv->avatar_pixbuf = pixbuf;
   }
 
@@ -350,7 +353,7 @@ avatar_callback (GdkPixbuf   *pixbuf,
 {
   GisAccountPageLocal *page = user_data;
   GisAccountPageLocalPrivate *priv = gis_account_page_local_get_instance_private (page);
-  GdkPixbuf *tmp;
+  GdkPixbuf *tmp, *rounded;
 
   g_clear_object (&priv->avatar_pixbuf);
   g_free (priv->avatar_filename);
@@ -358,15 +361,18 @@ avatar_callback (GdkPixbuf   *pixbuf,
 
   if (pixbuf) {
     priv->avatar_pixbuf = g_object_ref (pixbuf);
-    tmp = gdk_pixbuf_scale_simple (pixbuf, 96, 96, GDK_INTERP_BILINEAR);
+    tmp = round_image (pixbuf);
     gtk_image_set_from_pixbuf (GTK_IMAGE (priv->avatar_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);
+    rounded = round_image (tmp);
     g_object_unref (tmp);
+
+    gtk_image_set_from_pixbuf (GTK_IMAGE (priv->avatar_image), rounded);
+    g_object_unref (rounded);
   }
   else {
     gtk_image_set_pixel_size (GTK_IMAGE (priv->avatar_image), 96);
diff --git a/gnome-initial-setup/pages/account/um-photo-dialog.c 
b/gnome-initial-setup/pages/account/um-photo-dialog.c
index f7bd5ee..e1d1ad3 100644
--- a/gnome-initial-setup/pages/account/um-photo-dialog.c
+++ b/gnome-initial-setup/pages/account/um-photo-dialog.c
@@ -166,13 +166,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 9a1ff54..5fd215e 100644
--- a/gnome-initial-setup/pages/account/um-utils.c
+++ b/gnome-initial-setup/pages/account/um-utils.c
@@ -602,3 +602,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]