-
Notifications
You must be signed in to change notification settings - Fork 9
/
exp2svg.py
executable file
·81 lines (66 loc) · 1.64 KB
/
exp2svg.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
79
80
81
#!/usr/bin/env python
#######################################
#
# renders an EXP embroidery file as SVG 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
#
#######################################
import stitchcode
import getopt
import sys
def usage():
print """
usage: exp2svg.py [options] -i EXP-FILE -o SVG-FILE
renders an EXP embroidery file as SVG-image
options:
-h, --help print usage
-i, --input=FILE input EXP file
-o, --output=FILE output SVG file
-z, --zoom=FACTOR zoom in/out
-s, --show-stitches show stitches
"""
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:s",
["help", "input=","output=","zoom=","show-stiches"])
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)
elif o in ("-s", "--show-stitch"):
show_stitches = True
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.svg" % infile[:-4]
emb = stitchcode.Embroidery()
emb.import_melco(infile)
emb.scale(zoom)
emb.save_as_svg(outfile)