-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtransparent.py
executable file
·51 lines (38 loc) · 1.44 KB
/
transparent.py
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
#!/usr/local/bin/python3
# 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 <[email protected]>
#mods by Josh Gourneau <[email protected]> to make one big horizontal sprite JPG with no spaces between images
import os
from PIL import Image
import glob
start_dir = "images/full_sprites/opaque/kanto/"
end_dir = "images/full_sprites/transparent/kanto/"
#get your images using glob
iconmap = os.listdir(start_dir)
#iconMap = sorted(iconMap)
print(len(iconmap))
for filename in iconmap:
image = Image.open(start_dir+filename)
image_width, image_height = image.size
print( "the image will by %d by %d" % (image_width, image_height))
print( "creating image...")
master = Image.new(
mode='RGBA',
size=(image_width, image_height),
color=(0,0,0,0)) # fully transparent
master.paste(image,(0,0))
data = master.getdata()
newdata = []
for item in data:
if item[0] == 255 and item[1] == 255 and item[2] == 255:
newdata.append((255,255,255,0))
else:
newdata.append(item)
master.putdata(newdata)
print( "saving master.jpg...")
master.save(end_dir+filename)
print( "saved!")