55
66import svgwrite
77
8+ from svglib .svglib import svg2rlg
9+ from reportlab .graphics import renderPDF , renderPM
10+
811if __name__ == "__main__" :
912
1013 parser = argparse .ArgumentParser (description = 'Generate the svg file for the markers.' )
1821 help = 'the radius of the outer circle (default: %(default)s)' )
1922 parser .add_argument ('--addId' , action = 'store_true' ,
2023 help = 'add the marker id on the top left corner' )
24+ parser .add_argument ('--addCross' , action = 'store_true' ,
25+ help = 'add a small cross in the center of the marker' )
26+ parser .add_argument ('--generatePng' , action = 'store_true' ,
27+ help = 'also generate a png file' )
28+ parser .add_argument ('--generatePdf' , action = 'store_true' ,
29+ help = 'also generate a pdf file' )
2130 parser .add_argument ('--whiteBackground' , action = 'store_true' ,
2231 help = 'set the background (outside the marker) to white instead of transparent' )
2332
2837 scale = args .radius / 100
2938
3039 # size of the image, diameter + margin
31- width = size + args .margin
32- height = size + args .margin
40+ width = size + args .margin
41+ height = size + args .margin
3342
3443 # id of the first marker
3544 markerId = 1
3645
3746 # font size for the id
38- font_size = int (0.037 * height )
47+ font_size = int (0.037 * height )
3948
4049 # center of the marker
41- center = (width / 2 , height / 2 )
50+ center = (width / 2 , height / 2 )
4251
4352 radius = args .radius
4453
5665 for line in f :
5766
5867 # name of the output file
59- out_filename = os .path .join (args .outdir , str (markerId ).zfill (4 )+ '.svg' )
68+ base_filename = os .path .join (args .outdir , str (markerId ).zfill (4 ))
69+ out_filename = base_filename + '.svg'
6070
6171 # create the svg
6272 dwg = svgwrite .Drawing (out_filename , profile = 'tiny' , size = (width , height ))
6777 dwg .add (dwg .text (text = str (markerId ), insert = (5 , 50 ), font_size = font_size ))
6878
6979 # print the outer circle as black
70- dwg .add (dwg .circle (center = center , r = size / 2 , fill = 'black' ))
80+ dwg .add (dwg .circle (center = center , r = size / 2 , fill = 'black' ))
7181
7282 fill_color = 'white'
7383 count = 0
7686 for r in line .split ():
7787 radius = int (r )
7888 # print(r)
79- dwg .add (dwg .circle (center = center , r = scale * radius , fill = fill_color ))
89+ dwg .add (dwg .circle (center = center , r = scale * radius , fill = fill_color ))
8090 if fill_color == 'white' :
8191 fill_color = 'black'
8292 else :
8999 else :
90100 assert count == 7
91101
102+ if args .addCross :
103+ # print a small cross in the center
104+ dwg .add (dwg .line (start = (center [0 ] - 10 , center [1 ]), end = (center [0 ] + 10 , center [1 ]), stroke = "gray" ))
105+ dwg .add (dwg .line (start = (center [0 ], center [1 ] - 10 ), end = (center [0 ], center [1 ] + 10 ), stroke = "gray" ))
106+
92107 dwg .save (pretty = True )
93108
94- markerId = markerId + 1
109+ if args .generatePng or args .generatePdf :
110+ drawing = svg2rlg (out_filename )
111+ if args .generatePdf :
112+ renderPDF .drawToFile (drawing , base_filename + ".pdf" )
113+ if args .generatePng :
114+ renderPM .drawToFile (drawing , base_filename + ".png" , fmt = "PNG" )
115+
116+ markerId = markerId + 1
0 commit comments