25
def __init__(self, margin=150):
28
26
self.sprites = None
29
27
self.combined_image = None
30
28
self.positions = None
31
29
self.css_object = None
33
32
def loadCSSTemplate(self, css_file, group_name,
34
33
url_prefix_substitutions=None):
86
85
max_width = max(width, max_width)
87
86
total_height += height
89
master_width = max_width
90
88
# Separate each image with lots of whitespace.
91
master_height = total_height + (MARGIN * len(self.sprites))
89
combined_image_height = (
90
total_height + (self.margin * len(self.sprites)))
92
91
transparent = (0,0,0,0)
92
combined_image = Image.new(
95
size=(master_width, master_height),
94
size=(max_width, combined_image_height),
100
99
for index, sprite in enumerate(self.sprites):
101
master.paste(sprite['image'], (0, y))
101
combined_image.paste(sprite['image'], (0, y))
103
print >> sys.stderr, (
104
"Error with image file %s" % sprite['filename'])
102
106
# This is the position of the combined image on an HTML
103
107
# element. Therefore, it subtracts the position of the
104
108
# sprite in the file to move it to the top of the element.
105
109
positions[sprite['filename']] = (0, -y)
106
y += sprite['image'].size[1] + MARGIN
110
y += sprite['image'].size[1] + self.margin
108
112
self.positions = positions
109
self.combined_image = master
113
self.combined_image = combined_image
111
115
def savePNG(self, filename):
112
self.combined_image.save(filename, format='png')
116
self.combined_image.save(filename, format='png', optimize=True)
114
118
def savePositioning(self, filename):
115
119
simplejson.dump(self.positions, fp=open(filename, 'w'), indent=4)