forked from CAS-ual-TY/PR-Assets-Indexes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_shadows.py
62 lines (44 loc) · 1.34 KB
/
remove_shadows.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
51
52
53
54
55
56
57
58
59
60
61
62
import os
import sys
from PIL import Image
import time
import shutil
path = "./vehicles"
print(path)
if len(sys.argv) >= 3:
color = sys.argv[2]
print(color)
colorInt = int(color, 16)
else:
colorInt = 0xA0000000
r0 = (colorInt >> 16) & 0xFF
g0 = (colorInt >> 8) & 0xFF
b0 = (colorInt >> 0) & 0xFF
a0 = (colorInt >> 24) & 0xFF
print("rgba = ({}, {}, {}, {})".format(r0, g0, b0, a0))
targetFolder = path + "\\new_icons"
print(targetFolder)
toDelete = os.path.join(targetFolder)
if os.path.isdir(toDelete):
for f in os.listdir(toDelete):
os.remove(os.path.join(targetFolder, f))
else:
os.mkdir(targetFolder)
for f in os.listdir(path):
if not os.path.isdir(f) and f[-len(".png"):] == ".png":
try:
original = os.path.join(path, f)
copy = os.path.join(targetFolder, f)
shutil.copyfile(original, copy)
img = Image.open(copy)
pixels = img.load()
for y0 in range(0, img.height):
for x0 in range(0, img.width):
r, g, b, a = img.getpixel((x0, y0))
if a != 255:
img.putpixel((x0, y0), (0, 0, 0, 0))
img.putpixel((x0, y0), (r, g, b, a))
img.save(copy)
except IOError:
print("Error for file {}".format(f))
print("done!")