#!/usr/bin/env python import Image colors = [] def tohex(rgbtuple): return '#%02x%02x%02x' % rgbtuple for i in range(64): filename = 'PyBanner%03d.gif' % i im = Image.open(filename) rgb = im.convert('RGB') w, h = im.size # get the rgbs for all 4 corners, vote on the bg color c00 = rgb.getpixel((0, 0)) c01 = rgb.getpixel((0, h-1)) c10 = rgb.getpixel((w-1, 0)) c11 = rgb.getpixel((w-1, h-1)) dict = {} dict[c00] = dict.get(c00, 0) + 1 dict[c01] = dict.get(c01, 0) + 1 dict[c10] = dict.get(c10, 0) + 1 dict[c11] = dict.get(c11, 0) + 1 vote = 0 background = None for k, v in dict.items(): if v > vote: background = k vote = v ## print filename, 'background:', tohex(background) colors.append(tohex(background)) # see PDOGenerator.py for why this format is used print ' return[' print ' ', col = 0 for c in colors: print "'%s', " % c, col = col + 1 if not col % 5: print print ' ', print print ' ][self.__whichbanner]'