Skip to content

Instantly share code, notes, and snippets.

@mishudark
Created February 20, 2011 18:40
Show Gist options
  • Select an option

  • Save mishudark/836191 to your computer and use it in GitHub Desktop.

Select an option

Save mishudark/836191 to your computer and use it in GitHub Desktop.
crea sprite en base a muchas imgs, sacado de debumode on
from PIL import Image
path = '/Users/gimenete/Desktop/famfamfam_silk_icons_v013/icons/'
names = ['add.png', 'accept.png', 'anchor.png', 'bomb.png', 'cd_add.png', 'clock.png']
output = 'sprites.png'
vpadding = 16
padding = 2
w = 0
h = 0
images = {}
for name in names:
im = Image.open(path+name)
images[name.split('.')[0]] = im
width, height = im.size
if width > w:
w = width
h += height
h += vpadding
canvas = Image.new('RGBA', (w, h))
h = 0
i = 0
for name in images:
im = images[name]
width, height = im.size
canvas.paste(im, (0, h))
print '.s_%s { background:url(%s) 0px -%dpx no-repeat; padding-left: %dpx;}' % (name, output, h, (width+padding))
h += height
h += vpadding
canvas.save(output, 'PNG')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment