-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsvg_to_png.py
More file actions
executable file
·38 lines (29 loc) · 956 Bytes
/
svg_to_png.py
File metadata and controls
executable file
·38 lines (29 loc) · 956 Bytes
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
#!/usr/bin/env python3
#encoding=utf-8
from svglib.svglib import svg2rlg
from reportlab.graphics import renderPDF, renderPM
import glob
def scan_folders(target_path):
#path="."
print("Checking path:", target_path)
idx=0
convert_count=0
filename_pattern = target_path + "/*.svg"
for name in glob.glob(filename_pattern):
idx+=1
#print("convert filename:", name)
is_convert = False
drawing = svg2rlg(name)
new_name = name.replace('.svg','.png')
renderPM.drawToFile(drawing, new_name, fmt="PNG")
convert_count+=1
print("Finish!\nconvert file count:%d\n" % (convert_count))
if __name__ == '__main__':
import sys
argument_count = 2
if len(sys.argv)==argument_count:
target_path = sys.argv[1]
scan_folders(target_path)
else:
print("Argument must be: %d" % (argument_count -1))
print("Ex:%s project.sfdir" % (sys.argv[0]))