-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathImagesSprite.py
More file actions
54 lines (42 loc) · 1.71 KB
/
Copy pathImagesSprite.py
File metadata and controls
54 lines (42 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python
# Edited by Hussein Bakri - 1) Edits transform it from Python 2 to Python 3
# 2) Make it work with PNG Image file format
# This work is licensed under the Creative Commons Attribution 3.0 United
# States License. To view a copy of this license, visit
# http://creativecommons.org/licenses/by/3.0/us/ or send a letter to Creative
# Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
# from http://oranlooney.com/make-css-sprites-python-image-library/
# Orignial Author Oran Looney <olooney@gmail.com>
#mods by Josh Gourneau <josh@gourneau.com> to make one big horizontal sprite JPG with no spaces between images
import os
from PIL import Image
#import Image
import glob
#get your images using glob
iconMap = glob.glob("*.png")
#just take the even ones
#iconMap = iconMap[::2]
print (len(iconMap))
images = [Image.open(filename) for filename in iconMap]
print ("%d images will be combined." % len(images))
image_width, image_height = images[0].size
print ("all images assumed to be %d by %d." % (image_width, image_height))
master_width = (image_width * len(images) )
#seperate each image with lots of whitespace
master_height = image_height
print ("the master image will by %d by %d" % (master_width, master_height))
print ("creating image...")
master = Image.new(
mode='RGBA',
size=(master_width, master_height),
color=(0,0,0,0)) # fully transparent
print ("created.")
for count, image in enumerate(images):
location = image_width*count
print ("adding %s at %d..." % (iconMap[count][1], location),
master.paste(image,(location,0)))
print ("added.")
print ("done adding icons.")
print ("saving img-sprite.png...",
master.save('img-sprite.png'))
print ("saved!")