generated from huidetang/XiandaiFenshuTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvg.py
34 lines (25 loc) · 849 Bytes
/
svg.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
import glob
from os import getcwd
from os.path import basename, join
from io import BytesIO
from PIL import Image
from cairosvg import svg2png
def convert(dir):
path_list = []
path_file = join(dir, "*.svg")
filename = glob.glob(path_file)
path_list.extend(filename)
for file in path_list:
converted_file_name = join(dir, (basename(file).split('.', 1)[0] + ".png"))
print(file + "を" + converted_file_name + "に変換します。")
png = svg2png(url=file)
img = Image.open(BytesIO(png)).convert('RGBA')
img.save(converted_file_name)
print(converted_file_name + "を出力しました。")
return
def main():
image_path = getcwd() + '/images'
print(image_path + 'のファイルが対象です。')
convert(image_path)
if __name__ == "__main__":
main()