From ac39977be7f77c5435d5e4bad73b6895c4bfd2ef Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Tue, 22 Dec 2020 07:59:03 -0800 Subject: [PATCH] adjust avatar scaling --- src/widgets.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/widgets.py b/src/widgets.py index 9a987af..c3c2511 100644 --- a/src/widgets.py +++ b/src/widgets.py @@ -339,7 +339,7 @@ class PostItem(Gtk.ListBoxRow): # header container self.h_box = Gtk.Box(orientation='horizontal') self.avatar = Handy.Avatar(size=48, text=post.user.username, show_initials=True) - self.avatar.set_image_load_func(self.get_avatar, post.user.content.avatar_image.link) + self.avatar.set_image_load_func(self.get_avatar, post.user.content.avatar_image) #self.avatar = Gtk.Image.new_from_pixbuf(self.get_avatar(48, post.user.content.avatar_image.link)) self.source = Gtk.Label(label=post.source.name, xalign=1, yalign=0) self.h_box.pack_start(self.avatar, False, False, 10) @@ -397,15 +397,19 @@ class PostItem(Gtk.ListBoxRow): self.box.pack_start(self.c_box, True, True, 10) self.box.pack_start(self.f_box, True, True, 10) - def get_avatar(self, size, url): + def get_avatar(self, size, avatar): # TODO: needs a cache # TODO: can I make it not round? - r = requests.get(url) + r = requests.get(avatar.link) loader = GdkPixbuf.PixbufLoader() loader.write(r.content) loader.close() pixbuf = loader.get_pixbuf() - return pixbuf.scale_simple(size,size,GdkPixbuf.InterpType.BILINEAR) + old_width = avatar.width + old_height = avatar.height + ratio = old_width / old_height + new_height = size / ratio + return pixbuf.scale_simple(size,new_height,GdkPixbuf.InterpType.BILINEAR) def get_oembed_thumb(self, oembed): url = oembed.thumbnail_url