forked from kovacsv/VisualScriptEngineWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateIcons.py
More file actions
65 lines (51 loc) · 1.92 KB
/
GenerateIcons.py
File metadata and controls
65 lines (51 loc) · 1.92 KB
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
import os
import sys
import re
import subprocess
import codecs
def GetFileContent (fileName):
file = codecs.open (fileName, 'r', 'utf-8')
content = file.read ()
file.close ()
return content
def SetFileContent (fileName, content):
file = codecs.open (fileName, 'w', 'utf-8')
file.write (content)
file.close ()
def GenerateWhiteIcon (sourceIconPath, whiteSvgIconPath):
sourceContent = GetFileContent (sourceIconPath)
whiteSvgContent = sourceContent
whiteSvgContent = re.sub (r'#[0-9a-fA-F]{6}', '#FAFAFA', whiteSvgContent)
SetFileContent (whiteSvgIconPath, whiteSvgContent)
def GeneratePng (inkscapePath, sourceSvgPath, resultPngPath, size):
command = [
inkscapePath,
'--export-png=' + resultPngPath,
'--export-width=' + str (size),
'--export-height=' + str (size),
sourceSvgPath
]
subprocess.call (command)
def Main (argv):
currentDir = os.path.dirname (os.path.abspath (__file__))
os.chdir (currentDir)
if len (argv) != 2:
print ('usage: GenerateIcons.py <inkscapePath>')
return 1
inkscapePath = sys.argv[1] # "C:\Program Files\Inkscape\inkscape.com"
svgIconsPath = os.path.abspath (os.path.join ('..', 'Documentation', 'CommandIcons'))
pngIconsPath = os.path.abspath (os.path.join ('..', 'Sources', 'WebSite', 'images', 'command_icons'))
whitePostFix = '_White'
for svgName in os.listdir (svgIconsPath):
svgBaseName = os.path.splitext (svgName)[0]
if whitePostFix in svgBaseName:
continue
sourceIconPath = os.path.join (svgIconsPath, svgName)
whiteSvgIconPath = os.path.join (svgIconsPath, svgBaseName + whitePostFix + '.svg')
GenerateWhiteIcon (sourceIconPath, whiteSvgIconPath)
png18Path = os.path.join (pngIconsPath, svgBaseName + '.png')
GeneratePng (inkscapePath, sourceIconPath, png18Path, 18)
pngWhite18Path = os.path.join (pngIconsPath, svgBaseName + whitePostFix + '.png')
GeneratePng (inkscapePath, whiteSvgIconPath, pngWhite18Path, 18)
return 0
sys.exit (Main (sys.argv))