[gnome-boxes/round-avatar: 3/3] unattended-setup-box: Round user avatar



commit 2d69dfd8f738ad17acdc21a97f9ae110a37731b0
Author: Felipe Borges <felipeborges gnome org>
Date:   Wed Sep 25 13:17:12 2019 +0200

    unattended-setup-box: Round user avatar
    
    This is to be consistent with the GNOME avatars
    See https://gitlab.gnome.org/GNOME/Initiatives/issues/6
    
    Fixes #420 🌿

 src/unattended-setup-box.vala |  2 +-
 src/util-app.vala             | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/src/unattended-setup-box.vala b/src/unattended-setup-box.vala
index a2aa1152..3867654b 100644
--- a/src/unattended-setup-box.vala
+++ b/src/unattended-setup-box.vala
@@ -64,7 +64,7 @@
         set {
             try {
                 var pixbuf = new Gdk.Pixbuf.from_file_at_scale (value, 64, 64, true);
-                user_avatar.pixbuf = pixbuf;
+                user_avatar.pixbuf = round_image (pixbuf);
             } catch (GLib.Error error) {
                 debug ("Failed to load user avatar file '%s': %s", value, error.message);
             }
diff --git a/src/util-app.vala b/src/util-app.vala
index 88a9a1d3..3dc35cf7 100644
--- a/src/util-app.vala
+++ b/src/util-app.vala
@@ -648,4 +648,19 @@ private async void move_config_from_cache (string config_name) {
 
         return Gdk.pixbuf_get_from_surface (surface, 0, 0, width, height);
     }
+
+    public Gdk.Pixbuf? round_image (Gdk.Pixbuf source) {
+        int size = source.width;
+        Cairo.Surface surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, size, size);
+        Cairo.Context cr = new Cairo.Context (surface);
+
+        cr.arc (size / 2, size / 2, size / 2, 0, 2 * GLib.Math.PI);
+        cr.clip ();
+        cr.new_path ();
+
+        Gdk.cairo_set_source_pixbuf (cr, source, 0, 0);
+        cr.paint ();
+
+        return Gdk.pixbuf_get_from_surface (surface, 0, 0, size, size);
+    }
 }


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