import Image
import os
import glob

sizes = [16, 22, 24, 32, 48]

icons = {}
for s in sizes:
    icons[s] = {}
    for f in glob.glob('%dx%d/*' % (s, s)):
        icons[s][f] = Image.open(f)

BORDER = 6
NIMAGES = 17
width = 48 * NIMAGES + BORDER * (NIMAGES + 1)
height = (len(sizes) + 1) * BORDER
for s in sizes:
    height += s
    
for bg in ['white', 'black']:
    montage = Image.new("RGBA", (width, height), bg)

    yoffset = 6
    for s in sizes:
        xoffset = 6
        keys = icons[s].keys()
        keys.sort()
        for n in keys:
            i = icons[s][n]
            montage.paste(i, (xoffset, yoffset,
                              xoffset + i.size[0],
                              yoffset + i.size[1]), i)
            xoffset += 48 + 6
        yoffset += i.size[1] + 6

    montage.save('gnome_games_icons_%s.png' % bg)
