1 import gtk
2
4 """
5 Returns a pixbuf scaled to the given size.
6
7 @param size: The size of the scaled pixbuf.
8 @param scale_up: If False, it is only scaled down if too large and not
9 scaled up.
10 @return: A pixbuf scaled to the given size.
11 """
12 size = int(size)
13 width = pixbuf.get_width()
14 height = pixbuf.get_height()
15 if width > height:
16 ratio = float(height)/float(width)
17 if width > size or (width < size and scale_up):
18 pixbuf = pixbuf.scale_simple(size, max(1, int(size*ratio)),
19 gtk.gdk.INTERP_TILES)
20 else:
21 ratio = float(width)/float(height)
22 if height > size or (height < size and scale_up):
23 pixbuf = pixbuf.scale_simple(max(1, int(size*ratio)), size,
24 gtk.gdk.INTERP_TILES)
25 return pixbuf
26