Skip to content
Snippets Groups Projects
Commit 54987247 authored by Yann Leboulanger's avatar Yann Leboulanger
Browse files

cleaner code

parent e8f33c7c
No related branches found
No related tags found
No related merge requests found
......@@ -410,18 +410,22 @@ def get_scaled_pixbuf(pixbuf, kind):
# resize to a width / height for the avatar not to have distortion
# (keep aspect ratio)
width = gajim.config.get(kind + '_avatar_width')
height = gajim.config.get(kind + '_avatar_height')
# Pixbuf size
pix_width = pixbuf.get_width()
pix_height = pixbuf.get_height()
# don't make avatars bigger than they are
if pixbuf.get_width() < gajim.config.get(kind + '_avatar_width') and \
pixbuf.get_height() < gajim.config.get(kind + '_avatar_height'):
if pix_width < width and pix_height < height:
return pixbuf # we don't want to make avatar bigger
ratio = float(pixbuf.get_width()) / float(pixbuf.get_height())
ratio = float(pix_width) / float(pix_height)
if ratio > 1:
w = gajim.config.get(kind + '_avatar_width')
w = width
h = int(w / ratio)
else:
h = gajim.config.get(kind + '_avatar_height')
h = height
w = int(h * ratio)
scaled_buf = pixbuf.scale_simple(w, h, gtk.gdk.INTERP_HYPER)
return scaled_buf
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment