rename.
This commit is contained in:
@@ -21,15 +21,15 @@
|
||||
## 使用
|
||||
- 出口预告/直行标志
|
||||
```sh
|
||||
python ./test/main.py -d filepath
|
||||
python ./main/main.py -d filepath
|
||||
```
|
||||
- 服务区预告标志
|
||||
```sh
|
||||
python ./test/sa_pa.py -d filepath
|
||||
python ./main/sa_pa.py -d filepath
|
||||
```
|
||||
- 地点距离预告标志
|
||||
```sh
|
||||
python ./test/distance.py -d filepath
|
||||
python ./main/distance.py -d filepath
|
||||
```
|
||||
|
||||
## 组件介绍
|
||||
|
||||
113
test/test.py
113
test/test.py
@@ -1,113 +0,0 @@
|
||||
import svgwrite
|
||||
import cairosvg
|
||||
import os
|
||||
import base64
|
||||
|
||||
from lxml import etree
|
||||
|
||||
import sys
|
||||
sys.path.append(os.getcwd())
|
||||
|
||||
from utils.font_size import *
|
||||
|
||||
from components.text import *
|
||||
from components.rect import *
|
||||
from components.common_road import *
|
||||
from components.special_area import *
|
||||
from components.express_way import *
|
||||
from components.exit import *
|
||||
|
||||
# config
|
||||
width = 550
|
||||
height = 550
|
||||
|
||||
# rect
|
||||
dwg = svgwrite.Drawing('rect.svg', profile='tiny', width=width, height=height)
|
||||
|
||||
exit_r = ExitComponent('428', 'B')
|
||||
exit_r.draw(dwg, width - exit_r.width(), 0)
|
||||
|
||||
rect = DoubleStrokeRectComponent(width=width, height=height - 50, main_color='#1f963b', stroke_color='#ffffff', stroke_width=4, r=16)
|
||||
rect.draw(dwg, 0, 50)
|
||||
|
||||
g_road = CommonRoadNationalComponent('G202')
|
||||
g_road.draw(dwg, 50, 70)
|
||||
|
||||
p_road = CommonRoadProvincialComponent('S210')
|
||||
p_road.draw(dwg, 50, 130)
|
||||
|
||||
c_road = CommonRoadTownshipComponent('X021')
|
||||
c_road.draw(dwg, 50, 190)
|
||||
|
||||
t_road = CommonRoadTownshipComponent('Y101')
|
||||
t_road.draw(dwg, 50, 250)
|
||||
|
||||
street = StreetComponent('北四环西路')
|
||||
street.draw(dwg, 200, 70)
|
||||
|
||||
tourist = TouristComponent('湖滨旅游区')
|
||||
tourist.draw(dwg, 200, 130)
|
||||
|
||||
g2501 = NationalExpressWayComponent('G25', '01')
|
||||
g2501.draw(dwg, 200, 190)
|
||||
|
||||
g1 = NationalExpressWayComponent('G1', '')
|
||||
g1.draw(dwg, 300, 190)
|
||||
|
||||
g10 = NationalExpressWayComponent('G10', '')
|
||||
g10.draw(dwg, 375, 190)
|
||||
|
||||
g55 = NationalExpressWayComponent('G55', '')
|
||||
g55.draw(dwg, 200, 250)
|
||||
|
||||
g11 = NationalExpressWayComponent('G11', '')
|
||||
g11.draw(dwg, 300, 250)
|
||||
|
||||
g9902 = NationalExpressWayComponent('G99', '02')
|
||||
g9902.draw(dwg, 375, 250)
|
||||
|
||||
s50 = ProvincialExpressWayComponent('京', 'S50', '')
|
||||
s50.draw(dwg, 50, 310)
|
||||
|
||||
s3801 = ProvincialExpressWayComponent('京津冀', 'S3801', '')
|
||||
s3801.draw(dwg, 150, 310)
|
||||
|
||||
s9955 = ProvincialExpressWayComponent('粤', 'S99', '55')
|
||||
s9955.draw(dwg, 300, 310)
|
||||
|
||||
text_a = TextAComponent('北京', '#ffffff', 50)
|
||||
text_a.draw(dwg, 50, 370)
|
||||
|
||||
text_b = TextBComponent('Beijing', '#ffffff', 30)
|
||||
text_b.draw(dwg, 65, 420)
|
||||
|
||||
png_file = open('./resources/exit.png','rb')
|
||||
png_obj = png_file.read()
|
||||
s = base64.b64encode(png_obj)
|
||||
png_file.close()
|
||||
png_base64 = s.decode('ascii')
|
||||
image_size = 70
|
||||
# dwg.add(dwg.image(insert=((width - image_size) / 2, height - image_size * 1.2), size=(image_size, image_size), href='data:image/png;base64,{0}'.format(png_base64)))
|
||||
|
||||
# export
|
||||
dwg.save()
|
||||
|
||||
# 解析SVG文件
|
||||
svg_file = 'rect.svg'
|
||||
with open(svg_file, 'rb') as f:
|
||||
svg_data = f.read()
|
||||
parser = etree.XMLParser(remove_blank_text=True)
|
||||
svg_tree = etree.fromstring(svg_data, parser)
|
||||
|
||||
for element in svg_tree.iter():
|
||||
if 'height' in element.attrib:
|
||||
element.attrib['height'] = element.attrib['height'].replace('100%', '{}'.format(height))
|
||||
if 'width' in element.attrib:
|
||||
element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width))
|
||||
|
||||
# 保存修改后的SVG文件
|
||||
with open('rect.svg', 'wb') as f:
|
||||
f.write(etree.tostring(svg_tree, pretty_print=True))
|
||||
|
||||
cairosvg.svg2png(url='rect.svg', write_to='rect.png')
|
||||
# os.remove('rect.svg')
|
||||
Reference in New Issue
Block a user