-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_wonderdraft_symbols.py
74 lines (53 loc) · 1.72 KB
/
generate_wonderdraft_symbols.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
63
64
65
66
67
68
69
70
71
72
73
74
import json
import os
import platform
import re
import glob
from pathlib import Path
from raster_engines import getEngine
from file_system import *
from user_interface import *
from tqdm import tqdm
from config import *
def generateWonderDraftSymbols(args, gui=False):
createFolders()
ensurePopulated(SVG_DIR)
filenames = getAllFilesInDir(".svg", SVG_DIR)
prefix = ""
if gui:
tqdm_out = open(PROGRESS_TRACKER_PNG_TMP_FILE, "w")
else:
tqdm_out = None
if hasattr(args, 'folder'):
SYMBOL_DIR = TREE_DIR = args.folder
if args.is_tree_mode:
files = getAllFilesInDir(".svg", SVG_DIR)
for f in tqdm(files, file=tqdm_out):
basefile, category, s = splitPath(f)
file_name = f'{prefix}{TREE_DIR}/{category}/{s}/{basefile}.svg'
png_path = os.path.join(file_name.replace('svg', 'png'))
svg_path = os.path.join(f)
saveWrite(None, png_path)
args.engine.convert(
svg_path,
png_path
)
else:
# Ensure the output directory exists
files = getAllFilesInDir(".svg", SVG_DIR)
for f in tqdm(files, file=tqdm_out):
basefile, category, s = splitPath(f)
file_name = removeBaseFolder(f)
svg_path = os.path.join(f)
png_path = os.path.join(
SYMBOL_DIR, file_name.replace('svg', 'png'))
saveWrite(None, png_path)
args.engine.convert(
svg_path,
png_path
)
if __name__ == "__main__":
args = genWonderDraftUI()
initEngineSupport(args)
args.engine = selectEnginePrompt(args)
generateWonderDraftSymbols(args)