-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpng_to_svg_folder.py
More file actions
65 lines (46 loc) · 1.25 KB
/
png_to_svg_folder.py
File metadata and controls
65 lines (46 loc) · 1.25 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
from PIL import Image
from os import path
import shutil
import cairosvg
import os
files = []
errors = []
def FileExist(location):
ext = path.splitext(location)[1]
if ext == ".svg":
files.append(location)
def ConvertSVG(fileName, folderName):
try:
createFolder(folderName)
cairosvg.svg2png(url=convertPath + '\\' +
fileName, write_to=f'{fileName[:-4]}.png')
os.chdir(convertPath)
except Exception as e:
errors.append(fileName)
os.chdir(convertPath)
print("SVG Error", e)
def ConvertICO(fn):
try:
filename = r'' + fn
img = Image.open(convertPath + '\\Output\\' + filename)
img.save('logo.ico')
except Exception as e:
errors.append(fn)
print("Error", e)
def createFolder(fileName):
dir = path.join(path.abspath('')) + '\\' + fileName
if not os.path.exists(dir):
os.mkdir(dir)
os.chdir(dir)
def main():
convertPath = path.abspath('.')
tmpFiles = os.listdir(convertPath)
for myFile in tmpFiles:
FileExist(myFile)
return convertPath
convertPath = main()
print(files)
for nFile in files:
# print(convertPath + '\\' + nFile)
ConvertSVG(nFile, "Output")
ConvertICO(files[0])