-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportSvg.py
49 lines (39 loc) · 1.5 KB
/
exportSvg.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
import subprocess
import sys
import re
import os
import shutil
def modifySvgColor(svgFilePath):
file = open(svgFilePath, 'r')
contents = file.read()
contents = re.sub(r'(<svg[^>]+style=")[^"]*?"', r'\1fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-opacity:1"',
contents, 0, re.DOTALL)
file.close()
outputPath = r'C:/Users/flori/Downloads/tmp/' + os.path.basename(svgFilePath)
file = open(outputPath, 'w')
file.write(contents)
file.close()
return outputPath
inkscapePath = r"C:\Program Files\Inkscape\bin\inkscape.exe"
def exportSvg(filePath, outputPath):
print('exporting ' + filePath + ' to ' + outputPath)
modifiedPath = modifySvgColor(filePath)
cmd = [inkscapePath, modifiedPath, '-w', '64', '-h', '64', '-o', outputPath]
result = subprocess.run(cmd,
capture_output=True, text=True)
print(result.stdout)
print(result.stderr)
def parseFolder(inputFolder, outputFolder):
shutil.rmtree(outputFolder, ignore_errors=True)
os.mkdir(outputFolder)
folderContents = os.listdir(inputFolder)
for file in folderContents:
filePath = os.path.join(inputFolder, file)
if not os.path.isfile(filePath):
continue
exportSvg(filePath, os.path.join(outputFolder, os.path.splitext(file)[0] + '.png'))
if __name__ == "__main__":
if len(sys.argv) < 3:
print('Usage: python exportSvg.py inputFolder outputFolder')
exit(1)
parseFolder(sys.argv[1], sys.argv[2])