-
Notifications
You must be signed in to change notification settings - Fork 9
/
svg2exp.py
executable file
·78 lines (64 loc) · 1.54 KB
/
svg2exp.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
#######################################
#
# renders an EXP embroidery file as a PNG image
#
# author:(c) Michael Aschauer <m AT ash.to>
# www: http:/m.ash.to
# licenced under: GPL v3
# see: http://www.gnu.org/licenses/gpl.html
#
#######################################
from PIL import Image
import stitchcode
import getopt
import sys
def usage():
print """
usage: svg2exp.py [options] -i SVG-FILE -o EXP-FILE
renders an EXP embroidery file as a PNG image
options:
-h, --help print usage
-i, --input=FILE input SVG file
-o, --output=FILE output EXP file
-z, --zoom=FACTOR zoom in/out
"""
infile = "";
outfile = "";
zoom = 1
show_stitches = False
def process_args():
global infile, outfile, zoom, show_stitches
try:
opts, args = getopt.getopt(sys.argv[1:], "hi:o:z",
["help", "input=","output=","zoom="])
except getopt.GetoptError, err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
for o, a in opts:
if o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-o", "--output"):
outfile = a
elif o in ("-i", "--input"):
infile = a
elif o in ("-z", "--zoom"):
zoom = float(a)
else:
usage()
sys.exit()
if len(infile) == 0:
print "options required."
usage()
sys.exit(2)
if __name__ == '__main__':
process_args()
if not outfile:
outfile = "%s.exp" % infile[:-4]
emb = stitchcode.Embroidery()
emb.import_svg(infile)
emb.scale(zoom)
emb.save_as_exp(outfile)