-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess_icon.py
29 lines (22 loc) · 896 Bytes
/
preprocess_icon.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
import os
import cv2
from io import BytesIO
import cairosvg
from PIL import Image
if __name__ == '__main__':
for f in os.listdir('raw_icons/'):
file_path = os.path.join('raw_icons', f)
output_file_path = os.path.join('icons', os.path.splitext(f)[0] + ".png")
if file_path.endswith('.svg'):
out = BytesIO()
cairosvg.svg2png(url=file_path, write_to=output_file_path)
img = cv2.imread(output_file_path)
h, w, _ = img.shape
resized_img = cv2.resize(img, (128, 128 * h//w))
cv2.imwrite(output_file_path, resized_img)
else:
img = cv2.imread(file_path)
h, w, _ = img.shape
resized_img = cv2.resize(img, (128, 128 * h//w))
cv2.imwrite(output_file_path, resized_img)
print("Done!")