-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsprite-tinter.py
37 lines (28 loc) · 1.08 KB
/
sprite-tinter.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
import os
from PIL import Image
def clamp(n, smallest, largest): return max(smallest, min(int(n), largest))
def tint(fname, postfix, additiveTint):
with Image.open(fname, 'r') as bs:
bs = bs.convert('RGBA')
for y in range(bs.height):
for x in range(bs.width):
pixel = bs.getpixel((x, y))
pixel = (
clamp(pixel[0] + additiveTint[0], 0x00, 0xFF),
clamp(pixel[1] + additiveTint[1], 0x00, 0xFF),
clamp(pixel[2] + additiveTint[2], 0x00, 0xFF),
pixel[3])
bs.putpixel((x, y), pixel)
newPath = os.path.splitext(fname)[0] + postfix + os.path.splitext(fname)[1]
bs.save(newPath)
# assign directory
directory = 'bs'
# iterate over files in
# that directory
for filename in os.listdir(directory):
f = os.path.join(directory, filename)
# checking if it is a file
if os.path.isfile(f):
tint(f, '_M', [0x33, -0x33, -0x33])
tint(f, '_X', [-0x33, 0x33, -0x33])
tint(f, '_I', [-0x33, -0x33, 0x33])