init repo.

This commit is contained in:
Zhang Muyu
2023-09-10 23:20:05 +08:00
parent a37fa65690
commit 55d148f0f6
47 changed files with 1472 additions and 0 deletions

3
.gitignore vendored
View File

@@ -158,3 +158,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
*.png
*.svg

BIN
resources/A.ttf Normal file

Binary file not shown.

BIN
resources/B.ttf Normal file

Binary file not shown.

BIN
resources/C.ttf Normal file

Binary file not shown.

40
test/test_rect.py Normal file
View File

@@ -0,0 +1,40 @@
import svgwrite
import cairosvg
import os
from lxml import etree
from utils.font_size import FontSize
from utils.factory import TextFactory
from utils.factory import RectFactory
# config
width = 250
height = 250
# rect
dwg = svgwrite.Drawing('rect.svg', profile='tiny', width=width, height=height)
RectFactory.double_stroke_rect(container=dwg, width=250, height=250, main_color='#1f963b', stroke_color='#ffffff', stroke_width=4, r=16, x=0, y=0)
# 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')

51
test/test_text.py Normal file
View File

@@ -0,0 +1,51 @@
import svgwrite
import cairosvg
import os
from lxml import etree
from utils.font_size import FontSize
from utils.factory import TextFactory
'''
字号字高比=1:1; 下沉20%
'''
text = '测试0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
text_size = 50
text_width = FontSize.get_font_width(text, 'utils/A.ttf', text_size)
print(text_width)
# config
width = text_width
height = text_size
# rect
dwg = svgwrite.Drawing('./{}.svg'.format(text), profile='tiny', width=width, height=height)
dwg.add(dwg.rect(insert=(0, 0), size=(width, height), rx=0, ry=0, fill='red'))
# text
dwg.add(TextFactory.type_a_text(dwg, text, 'white', text_size, 0, 0))
# export
dwg.save()
# 解析SVG文件
svg_file = './{}.svg'.format(text)
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('./{}.svg'.format(text), 'wb') as f:
f.write(etree.tostring(svg_tree, pretty_print=True))
cairosvg.svg2png(url='./{}.svg'.format(text), write_to='./{}.png'.format(text))
os.remove('./{}.svg'.format(text))
print('{}标志生成完成'.format(text))

BIN
test/utils/A.ttf Normal file

Binary file not shown.

BIN
test/utils/B.ttf Normal file

Binary file not shown.

BIN
test/utils/C.ttf Normal file

Binary file not shown.

0
test/utils/__init__.py Normal file
View File

26
test/utils/factory.py Normal file
View File

@@ -0,0 +1,26 @@
import svgwrite
class TextFactory:
def type_a_text(container, text, color, size, x, y):
return TextFactory.text(container, text, 'A型交通标志专用字体', color, size, x, y)
def type_b_text(container, text, color, size, x, y):
return TextFactory.text(container, text, 'B型交通标志专用字体', color, size, x, y)
def text(container, text, font, color, size, x, y):
x_loc = x
y_loc = y + size * 0.8
return container.text(text, insert=(x_loc, y_loc), fill=color, font_family=font, font_size=size)
class RectFactory:
def single_stroke_rect(container, width, height, main_color, stroke_color, stroke_width, r, x, y):
container.add(container.rect(insert=(x, y), size=(width, height), rx=r, ry=r, fill=stroke_color))
container.add(container.rect(insert=(x + stroke_width, y + stroke_width), size=(width - 2 * stroke_width, height - 2 * stroke_width), rx=r - stroke_width, ry=r - stroke_width, fill=main_color))
def double_stroke_rect(container, width, height, main_color, stroke_color, stroke_width, r, x, y):
container.add(container.rect(insert=(x, y), size=(width, height), rx=r, ry=r, fill=main_color))
container.add(container.rect(insert=(x + stroke_width, y + stroke_width), size=(width - 2 * stroke_width, height - 2 * stroke_width), rx=r - stroke_width, ry=r - stroke_width, fill=stroke_color))
container.add(container.rect(insert=(x + 2 * stroke_width, y + 2 * stroke_width), size=(width - 4 * stroke_width, height - 4 * stroke_width), rx=r - 2 * stroke_width, ry=r - 2 * stroke_width, fill=main_color))

15
test/utils/font_size.py Normal file
View File

@@ -0,0 +1,15 @@
from PIL import ImageFont
class FontSize:
def get_font_width(text, font, size):
return sum([ImageFont.truetype(font, size, 0).getsize(char)[0] for char in text])
def font_size_width_dict(font, size):
dict = {}
for char in range(ord('0'), ord('9') + 1):
dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size
for char in range(ord('A'), ord('Z') + 1):
dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size
for char in range(ord('a'), ord('z') + 1):
dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size
return dict

64
test/utils/width.json Normal file
View File

@@ -0,0 +1,64 @@
{
"0": 0.52,
"1": 0.3,
"2": 0.5,
"3": 0.46,
"4": 0.48,
"5": 0.5,
"6": 0.5,
"7": 0.46,
"8": 0.5,
"9": 0.5,
"A": 0.5,
"B": 0.48,
"C": 0.5,
"D": 0.5,
"E": 0.42,
"F": 0.42,
"G": 0.5,
"H": 0.52,
"I": 0.22,
"J": 0.46,
"K": 0.48,
"L": 0.44,
"M": 0.58,
"N": 0.52,
"O": 0.54,
"P": 0.48,
"Q": 0.54,
"R": 0.48,
"S": 0.44,
"T": 0.38,
"U": 0.52,
"V": 0.46,
"W": 0.54,
"X": 0.48,
"Y": 0.5,
"Z": 0.44,
"a": 0.4,
"b": 0.42,
"c": 0.34,
"d": 0.42,
"e": 0.38,
"f": 0.22,
"g": 0.4,
"h": 0.4,
"i": 0.22,
"j": 0.2,
"k": 0.38,
"l": 0.2,
"m": 0.6,
"n": 0.4,
"o": 0.4,
"p": 0.42,
"q": 0.42,
"r": 0.28,
"s": 0.34,
"t": 0.26,
"u": 0.4,
"v": 0.38,
"w": 0.5,
"x": 0.38,
"y": 0.42,
"z": 0.36
}

View File

@@ -0,0 +1,56 @@
import svgwrite
import cairosvg
from lxml import etree
import os
from utils.font_size import FontSize
# config
width = 1920
height = 960
stroke_width = 40
out_r = stroke_width * 4
mid_r = stroke_width * 3
in_r = stroke_width * 2
for prefix in ['X', 'Y']:
for num in range(1, 1000):
text = '{}{}'.format(prefix, str(num).zfill(3))
text_h = 880
text_full_width = FontSize.get_font_width(text, './utils/B.ttf', text_h)
# rect
dwg = svgwrite.Drawing('./{}.svg'.format(text), profile='tiny', width=width, height=height)
dwg.add(dwg.rect(insert=(0, 0), size=(width, height), rx=out_r, ry=out_r, fill="white"))
dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width - stroke_width * 2, height - stroke_width * 2), rx=mid_r, ry=mid_r, fill="black"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 4, height - stroke_width * 4), rx=in_r, ry=in_r, fill="white"))
# text
y_offset = -180
text_x = (width - text_full_width) / 2
text_y = (height + text_h) / 2 + y_offset
dwg.add(dwg.text(text, insert=(text_x, text_y), fill="black", font_family="B型交通标志专用字体",font_size=text_h))
# export
dwg.save()
# 解析SVG文件
svg_file = './{}.svg'.format(text)
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 + stroke_width * 2))
if 'width' in element.attrib:
element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2))
# 保存修改后的SVG文件
with open('./{}.svg'.format(text), 'wb') as f:
f.write(etree.tostring(svg_tree, pretty_print=True))
cairosvg.svg2png(url='./{}.svg'.format(text), write_to='./{}.png'.format(text))
os.remove('./{}.svg'.format(text))
print('{}标志生成完成'.format(text))

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,14 @@
import svgwrite
class TextFactory:
def type_a_text(container, text, color, size, x, y):
return TextFactory.text(container, text, 'A型交通标志专用字体', color, size, x, y)
def type_b_text(container, text, color, size, x, y):
return TextFactory.text(container, text, 'B型交通标志专用字体', color, size, x, y)
def text(container, text, font, color, size, x, y):
x_loc = x
y_loc = y + size * 0.8
return container.text(text, insert=(x_loc, y_loc), fill=color, font_family=font, font_size=size)

View File

@@ -0,0 +1,15 @@
from PIL import ImageFont
class FontSize:
def get_font_width(text, font, size):
return sum([ImageFont.truetype(font, size, 0).getsize(char)[0] for char in text])
def font_size_width_dict(font, size):
dict = {}
for char in range(ord('0'), ord('9') + 1):
dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size
for char in range(ord('A'), ord('Z') + 1):
dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size
for char in range(ord('a'), ord('z') + 1):
dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size
return dict

View File

@@ -0,0 +1,64 @@
{
"0": 0.52,
"1": 0.3,
"2": 0.5,
"3": 0.46,
"4": 0.48,
"5": 0.5,
"6": 0.5,
"7": 0.46,
"8": 0.5,
"9": 0.5,
"A": 0.5,
"B": 0.48,
"C": 0.5,
"D": 0.5,
"E": 0.42,
"F": 0.42,
"G": 0.5,
"H": 0.52,
"I": 0.22,
"J": 0.46,
"K": 0.48,
"L": 0.44,
"M": 0.58,
"N": 0.52,
"O": 0.54,
"P": 0.48,
"Q": 0.54,
"R": 0.48,
"S": 0.44,
"T": 0.38,
"U": 0.52,
"V": 0.46,
"W": 0.54,
"X": 0.48,
"Y": 0.5,
"Z": 0.44,
"a": 0.4,
"b": 0.42,
"c": 0.34,
"d": 0.42,
"e": 0.38,
"f": 0.22,
"g": 0.4,
"h": 0.4,
"i": 0.22,
"j": 0.2,
"k": 0.38,
"l": 0.2,
"m": 0.6,
"n": 0.4,
"o": 0.4,
"p": 0.42,
"q": 0.42,
"r": 0.28,
"s": 0.34,
"t": 0.26,
"u": 0.4,
"v": 0.38,
"w": 0.5,
"x": 0.38,
"y": 0.42,
"z": 0.36
}

View File

@@ -0,0 +1,55 @@
import svgwrite
import cairosvg
import os
from lxml import etree
from utils.font_size import FontSize
# config
width = 1920
height = 960
stroke_width = 40
out_r = stroke_width * 4
mid_r = stroke_width * 3
in_r = stroke_width * 2
for num in range(101, 1000):
text = 'G{}'.format(num)
text_h = 880
text_full_width = FontSize.get_font_width(text, './utils/B.ttf', text_h)
# rect
dwg = svgwrite.Drawing('./{}.svg'.format(text), profile='tiny', width=width, height=height)
dwg.add(dwg.rect(insert=(0, 0), size=(width, height), rx=out_r, ry=out_r, fill="red"))
dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width - stroke_width * 2, height - stroke_width * 2), rx=mid_r, ry=mid_r, fill="white"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 4, height - stroke_width * 4), rx=in_r, ry=in_r, fill="#e71420"))
# text
y_offset = -180
text_x = (width - text_full_width) / 2
text_y = (height + text_h) / 2 + y_offset
dwg.add(dwg.text(text, insert=(text_x, text_y), fill="white", font_family="B型交通标志专用字体",font_size=text_h))
# export
dwg.save()
# 解析SVG文件
svg_file = './{}.svg'.format(text)
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 + stroke_width * 2))
if 'width' in element.attrib:
element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2))
# 保存修改后的SVG文件
with open('./{}.svg'.format(text), 'wb') as f:
f.write(etree.tostring(svg_tree, pretty_print=True))
cairosvg.svg2png(url='./{}.svg'.format(text), write_to='./{}.png'.format(text))
os.remove('./{}.svg'.format(text))
print('{}标志生成完成'.format(text))

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,14 @@
import svgwrite
class TextFactory:
def type_a_text(container, text, color, size, x, y):
return TextFactory.text(container, text, 'A型交通标志专用字体', color, size, x, y)
def type_b_text(container, text, color, size, x, y):
return TextFactory.text(container, text, 'B型交通标志专用字体', color, size, x, y)
def text(container, text, font, color, size, x, y):
x_loc = x
y_loc = y + size * 0.8
return container.text(text, insert=(x_loc, y_loc), fill=color, font_family=font, font_size=size)

View File

@@ -0,0 +1,15 @@
from PIL import ImageFont
class FontSize:
def get_font_width(text, font, size):
return sum([ImageFont.truetype(font, size, 0).getsize(char)[0] for char in text])
def font_size_width_dict(font, size):
dict = {}
for char in range(ord('0'), ord('9') + 1):
dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size
for char in range(ord('A'), ord('Z') + 1):
dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size
for char in range(ord('a'), ord('z') + 1):
dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size
return dict

View File

@@ -0,0 +1,64 @@
{
"0": 0.52,
"1": 0.3,
"2": 0.5,
"3": 0.46,
"4": 0.48,
"5": 0.5,
"6": 0.5,
"7": 0.46,
"8": 0.5,
"9": 0.5,
"A": 0.5,
"B": 0.48,
"C": 0.5,
"D": 0.5,
"E": 0.42,
"F": 0.42,
"G": 0.5,
"H": 0.52,
"I": 0.22,
"J": 0.46,
"K": 0.48,
"L": 0.44,
"M": 0.58,
"N": 0.52,
"O": 0.54,
"P": 0.48,
"Q": 0.54,
"R": 0.48,
"S": 0.44,
"T": 0.38,
"U": 0.52,
"V": 0.46,
"W": 0.54,
"X": 0.48,
"Y": 0.5,
"Z": 0.44,
"a": 0.4,
"b": 0.42,
"c": 0.34,
"d": 0.42,
"e": 0.38,
"f": 0.22,
"g": 0.4,
"h": 0.4,
"i": 0.22,
"j": 0.2,
"k": 0.38,
"l": 0.2,
"m": 0.6,
"n": 0.4,
"o": 0.4,
"p": 0.42,
"q": 0.42,
"r": 0.28,
"s": 0.34,
"t": 0.26,
"u": 0.4,
"v": 0.38,
"w": 0.5,
"x": 0.38,
"y": 0.42,
"z": 0.36
}

View File

@@ -0,0 +1,55 @@
import svgwrite
import cairosvg
from lxml import etree
import os
from utils.font_size import FontSize
# config
width = 1920
height = 960
stroke_width = 40
out_r = stroke_width * 4
mid_r = stroke_width * 3
in_r = stroke_width * 2
for num in range(1, 1000):
text = 'S{}'.format(str(num).zfill(3))
text_h = 880
text_full_width = FontSize.get_font_width(text, './utils/B.ttf', text_h)
# rect
dwg = svgwrite.Drawing('./{}.svg'.format(text), profile='tiny', width=width, height=height)
dwg.add(dwg.rect(insert=(0, 0), size=(width, height), rx=out_r, ry=out_r, fill="yellow"))
dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width - stroke_width * 2, height - stroke_width * 2), rx=mid_r, ry=mid_r, fill="black"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 4, height - stroke_width * 4), rx=in_r, ry=in_r, fill="#f4ec17"))
# text
y_offset = -180
text_x = (width - text_full_width) / 2
text_y = (height + text_h) / 2 + y_offset
dwg.add(dwg.text(text, insert=(text_x, text_y), fill="black", font_family="B型交通标志专用字体",font_size=text_h))
# export
dwg.save()
# 解析SVG文件
svg_file = './{}.svg'.format(text)
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 + stroke_width * 2))
if 'width' in element.attrib:
element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2))
# 保存修改后的SVG文件
with open('./{}.svg'.format(text), 'wb') as f:
f.write(etree.tostring(svg_tree, pretty_print=True))
cairosvg.svg2png(url='./{}.svg'.format(text), write_to='./{}.png'.format(text))
os.remove('./{}.svg'.format(text))
print('{}标志生成完成'.format(text))

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,14 @@
import svgwrite
class TextFactory:
def type_a_text(container, text, color, size, x, y):
return TextFactory.text(container, text, 'A型交通标志专用字体', color, size, x, y)
def type_b_text(container, text, color, size, x, y):
return TextFactory.text(container, text, 'B型交通标志专用字体', color, size, x, y)
def text(container, text, font, color, size, x, y):
x_loc = x
y_loc = y + size * 0.8
return container.text(text, insert=(x_loc, y_loc), fill=color, font_family=font, font_size=size)

View File

@@ -0,0 +1,15 @@
from PIL import ImageFont
class FontSize:
def get_font_width(text, font, size):
return sum([ImageFont.truetype(font, size, 0).getsize(char)[0] for char in text])
def font_size_width_dict(font, size):
dict = {}
for char in range(ord('0'), ord('9') + 1):
dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size
for char in range(ord('A'), ord('Z') + 1):
dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size
for char in range(ord('a'), ord('z') + 1):
dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size
return dict

View File

@@ -0,0 +1,64 @@
{
"0": 0.52,
"1": 0.3,
"2": 0.5,
"3": 0.46,
"4": 0.48,
"5": 0.5,
"6": 0.5,
"7": 0.46,
"8": 0.5,
"9": 0.5,
"A": 0.5,
"B": 0.48,
"C": 0.5,
"D": 0.5,
"E": 0.42,
"F": 0.42,
"G": 0.5,
"H": 0.52,
"I": 0.22,
"J": 0.46,
"K": 0.48,
"L": 0.44,
"M": 0.58,
"N": 0.52,
"O": 0.54,
"P": 0.48,
"Q": 0.54,
"R": 0.48,
"S": 0.44,
"T": 0.38,
"U": 0.52,
"V": 0.46,
"W": 0.54,
"X": 0.48,
"Y": 0.5,
"Z": 0.44,
"a": 0.4,
"b": 0.42,
"c": 0.34,
"d": 0.42,
"e": 0.38,
"f": 0.22,
"g": 0.4,
"h": 0.4,
"i": 0.22,
"j": 0.2,
"k": 0.38,
"l": 0.2,
"m": 0.6,
"n": 0.4,
"o": 0.4,
"p": 0.42,
"q": 0.42,
"r": 0.28,
"s": 0.34,
"t": 0.26,
"u": 0.4,
"v": 0.38,
"w": 0.5,
"x": 0.38,
"y": 0.42,
"z": 0.36
}

View File

@@ -0,0 +1,108 @@
import svgwrite
import cairosvg
from lxml import etree
import os
# config
width = 1800
height = 1600
top_height = 250
stroke_width = 30
out_r = stroke_width * 3
in_r = stroke_width * 2
highway_map = {
11: '鹤大',
15: '沈海',
25: '长深',
35: '济广',
45: '大广',
55: '二广',
59: '呼北',
65: '包茂',
69: '银百',
75: '兰海',
85: '银昆',
10: '绥满',
12: '珲乌',
16: '丹锡',
18: '荣乌',
20: '青银',
22: '青兰',
30: '连霍',
36: '宁洛',
40: '沪陕',
42: '沪蓉',
50: '沪渝',
56: '杭瑞',
60: '沪昆',
70: '福银',
72: '泉南',
76: '厦蓉',
78: '汕昆',
80: '广昆',
}
for num, name in highway_map.items():
text = 'G{}'.format(num)
text_h = 1000
text_full_width = 0
for n in text:
if n == '1':
text_full_width += text_h * 0.3
else:
text_full_width += text_h * 0.5
# rect
dwg = svgwrite.Drawing('./{}.svg'.format(text), profile='tiny', width=width, height=height)
dwg.add(dwg.rect(insert=(0, 0), size=(width + 2 * stroke_width, height + 2 * stroke_width), rx=out_r, ry=out_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width, height), rx=out_r, ry=out_r, fill="white"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, top_height), rx=in_r, ry=in_r, fill="red"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2 + top_height / 2), size=(width - stroke_width * 2, top_height / 2), fill="red"))
# top text
top_text = '国  家  高  速'
top_text_size = 150
top_text_x = (width - top_text_size * len(top_text)) / 2 + 380
top_text_y = (top_height + top_text_size) / 2 + stroke_width - 25
dwg.add(dwg.text(top_text, insert=(stroke_width + top_text_x, stroke_width + top_text_y), fill="white", font_family="A型交通标志专用字体",font_size=top_text_size))
# num
y_offset = -240
text_x = (width - text_full_width) / 2
text_y = (height + text_h + top_height) / 2 + y_offset - 200
dwg.add(dwg.text(text, insert=(stroke_width + text_x, stroke_width + text_y), fill="white", font_family="B型交通标志专用字体",font_size=text_h))
# name
name_text = ' '.join(name + '高速')
name_text_size = 280
name_text_x = (width - name_text_size * len(name_text)) / 2 + 300
name_text_y = top_text_y + top_text_size + 1000
dwg.add(dwg.text(name_text, insert=(stroke_width + name_text_x, stroke_width + name_text_y), fill="white", font_family="A型交通标志专用字体",font_size=name_text_size))
# export
dwg.save()
# 解析SVG文件
svg_file = './{}.svg'.format(text)
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 + stroke_width * 2))
if 'width' in element.attrib:
element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2))
# 保存修改后的SVG文件
with open('./{}.svg'.format(text), 'wb') as f:
f.write(etree.tostring(svg_tree, pretty_print=True))
cairosvg.svg2png(url='./{}.svg'.format(text), write_to='./{}.png'.format(text))
os.remove('./{}.svg'.format(text))
print('{}标志生成完成'.format(text))

View File

@@ -0,0 +1,85 @@
import svgwrite
import cairosvg
from lxml import etree
import os
# config
width = 2000
height = 1600
top_height = 250
stroke_width = 30
out_r = stroke_width * 3
in_r = stroke_width * 2
highway_map = {
91: '辽中环线',
92: '杭州湾环线',
93: '成渝环线',
94: '珠三角环线',
95: '首都环线',
98: '海南环岛'
}
for num, name in highway_map.items():
text = 'G{}'.format(num)
text_h = 1000
text_full_width = 0
for n in text:
if n == '1':
text_full_width += text_h * 0.3
else:
text_full_width += text_h * 0.5
# rect
dwg = svgwrite.Drawing('./{}.svg'.format(text), profile='tiny', width=width, height=height)
dwg.add(dwg.rect(insert=(0, 0), size=(width + 2 * stroke_width, height + 2 * stroke_width), rx=out_r, ry=out_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width, height), rx=out_r, ry=out_r, fill="white"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, top_height), rx=in_r, ry=in_r, fill="red"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2 + top_height / 2), size=(width - stroke_width * 2, top_height / 2), fill="red"))
# top text
top_text = '国  家  高  速'
top_text_size = 150
top_text_x = (width - top_text_size * len(top_text)) / 2 + 380
top_text_y = (top_height + top_text_size) / 2 + stroke_width - 25
dwg.add(dwg.text(top_text, insert=(stroke_width + top_text_x, stroke_width + top_text_y), fill="white", font_family="A型交通标志专用字体",font_size=top_text_size))
# num
y_offset = -240
text_x = (width - text_full_width) / 2
text_y = (height + text_h + top_height) / 2 + y_offset - 200
dwg.add(dwg.text(text, insert=(stroke_width + text_x, stroke_width + text_y), fill="white", font_family="B型交通标志专用字体",font_size=text_h))
# name
name_text = name + '高速'
name_text_size = 260
name_text_x = (width - name_text_size * len(name_text)) / 2 + 10
name_text_y = top_text_y + top_text_size + 1000
dwg.add(dwg.text(name_text, insert=(stroke_width + name_text_x, stroke_width + name_text_y), fill="white", font_family="A型交通标志专用字体",font_size=name_text_size))
# export
dwg.save()
# 解析SVG文件
svg_file = './{}.svg'.format(text)
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 + stroke_width * 2))
if 'width' in element.attrib:
element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2))
# 保存修改后的SVG文件
with open('./{}.svg'.format(text), 'wb') as f:
f.write(etree.tostring(svg_tree, pretty_print=True))
cairosvg.svg2png(url='./{}.svg'.format(text), write_to='./{}.png'.format(text))
os.remove('./{}.svg'.format(text))
print('{}标志生成完成'.format(text))

View File

@@ -0,0 +1,106 @@
import svgwrite
import cairosvg
from lxml import etree
import os
import csv
# config
width = 2000
height = 1400
top_height = 250
stroke_width = 30
out_r = stroke_width * 3
in_r = stroke_width * 2
highway_map = {}
with open('data.csv', 'r') as file:
reader = csv.DictReader(file)
for row in reader:
highway_map[row['num']] = row['name']
for num, name in highway_map.items():
file_name = num + name;
# G+前两位
big_text = num[:3]
# 后两位
small_text = num[3:]
big_text_h = 900
small_text_h = 600
big_full_width = 0
small_full_width = 0
for n in big_text:
if n == '1':
big_full_width += big_text_h * 0.3
else:
big_full_width += big_text_h * 0.5
for n in small_text:
if n == '1':
small_full_width += small_text_h * 0.3
else:
small_full_width += small_text_h * 0.5
text_full_width = big_full_width + small_full_width
# rect
dwg = svgwrite.Drawing('./{}.svg'.format(file_name), profile='tiny', width=width, height=height)
dwg.add(dwg.rect(insert=(0, 0), size=(width + 2 * stroke_width, height + 2 * stroke_width), rx=out_r, ry=out_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width, height), rx=out_r, ry=out_r, fill="white"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, top_height), rx=in_r, ry=in_r, fill="red"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2 + top_height / 2), size=(width - stroke_width * 2, top_height / 2), fill="red"))
# top text
top_text = '国  家  高  速'
top_text_size = 150
top_text_x = (width - top_text_size * len(top_text)) / 2 + 380
top_text_y = (top_height + top_text_size) / 2 + stroke_width - 25
dwg.add(dwg.text(top_text, insert=(stroke_width + top_text_x, stroke_width + top_text_y), fill="white", font_family="A型交通标志专用字体",font_size=top_text_size))
# num
y_offset = -360
big_text_x = (width - text_full_width) / 2
big_text_y = (height + big_text_h + top_height) / 2 + y_offset
dwg.add(dwg.text(big_text, insert=(stroke_width + big_text_x, stroke_width + big_text_y), fill="white", font_family="B型交通标志专用字体",font_size=big_text_h))
small_text_x = (width - text_full_width) / 2 + big_full_width
dwg.add(dwg.text(small_text, insert=(stroke_width + small_text_x, stroke_width + big_text_y), fill="white", font_family="B型交通标志专用字体",font_size=small_text_h))
# name
name_text = name
if len(name_text) < 8:
name_text_size = 260
else:
name_text_size = 230
name_text_x = (width - name_text_size * len(name)) / 2
name_text_y = top_text_y + top_text_size + 880
dwg.add(dwg.text(name_text, insert=(stroke_width + name_text_x, stroke_width + name_text_y), fill="white", font_family="A型交通标志专用字体",font_size=name_text_size))
# export
dwg.save()
# 解析SVG文件
svg_file = './{}.svg'.format(file_name)
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 + stroke_width * 2))
if 'width' in element.attrib:
element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2))
# 保存修改后的SVG文件
with open('./{}.svg'.format(file_name), 'wb') as f:
f.write(etree.tostring(svg_tree, pretty_print=True))
cairosvg.svg2png(url='./{}.svg'.format(file_name), write_to='./{}.png'.format(file_name))
os.remove('./{}.svg'.format(file_name))
print('{}标志生成完成'.format(file_name))

View File

@@ -0,0 +1,31 @@
num,name
G0401,长沙绕城高速
G0601,西宁绕城高速
G1501,沈阳绕城高速
G1503,上海绕城高速
G1504,宁波绕城高速
G1505,福州绕城高速
G1508,广州绕城高速
G2501,长春绕城高速
G2502,天津绕城高速
G2503,南京绕城高速
G2504,杭州绕城高速
G4501,北京绕城高速
G5901,呼和浩特绕城高速
G1001,哈尔滨绕城高速
G2001,济南绕城高速
G2002,石家庄绕城高速
G2003,太原绕城高速
G2004,银川绕城高速
G2201,兰州绕城高速
G3001,郑州绕城高速
G3002,西安绕城高速
G3003,乌鲁木齐绕城高速
G4001,合肥绕城高速
G4201,武汉绕城高速
G4202,成都绕城高速
G5001,重庆绕城高速
G5601,昆明绕城高速
G6001,南昌绕城高速
G6002,贵阳绕城高速
G7201,南宁绕城高速
1 num name
2 G0401 长沙绕城高速
3 G0601 西宁绕城高速
4 G1501 沈阳绕城高速
5 G1503 上海绕城高速
6 G1504 宁波绕城高速
7 G1505 福州绕城高速
8 G1508 广州绕城高速
9 G2501 长春绕城高速
10 G2502 天津绕城高速
11 G2503 南京绕城高速
12 G2504 杭州绕城高速
13 G4501 北京绕城高速
14 G5901 呼和浩特绕城高速
15 G1001 哈尔滨绕城高速
16 G2001 济南绕城高速
17 G2002 石家庄绕城高速
18 G2003 太原绕城高速
19 G2004 银川绕城高速
20 G2201 兰州绕城高速
21 G3001 郑州绕城高速
22 G3002 西安绕城高速
23 G3003 乌鲁木齐绕城高速
24 G4001 合肥绕城高速
25 G4201 武汉绕城高速
26 G4202 成都绕城高速
27 G5001 重庆绕城高速
28 G5601 昆明绕城高速
29 G6001 南昌绕城高速
30 G6002 贵阳绕城高速
31 G7201 南宁绕城高速

View File

@@ -0,0 +1,103 @@
import svgwrite
import cairosvg
from lxml import etree
import os
import csv
# config
width = 2000
height = 1400
top_height = 250
stroke_width = 30
out_r = stroke_width * 3
in_r = stroke_width * 2
highway_map = {}
with open('data.csv', 'r') as file:
reader = csv.DictReader(file)
for row in reader:
highway_map[row['num']] = row['name']
for num, name in highway_map.items():
file_name = num + name;
# G+前两位
big_text = num[:3]
# 后两位
small_text = num[3:]
big_text_h = 900
small_text_h = 600
big_full_width = 0
small_full_width = 0
for n in big_text:
if n == '1':
big_full_width += big_text_h * 0.3
else:
big_full_width += big_text_h * 0.5
for n in small_text:
if n == '1':
small_full_width += small_text_h * 0.3
else:
small_full_width += small_text_h * 0.5
text_full_width = big_full_width + small_full_width
# rect
dwg = svgwrite.Drawing('./{}.svg'.format(file_name), profile='tiny', width=width, height=height)
dwg.add(dwg.rect(insert=(0, 0), size=(width + 2 * stroke_width, height + 2 * stroke_width), rx=out_r, ry=out_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width, height), rx=out_r, ry=out_r, fill="white"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, top_height), rx=in_r, ry=in_r, fill="red"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2 + top_height / 2), size=(width - stroke_width * 2, top_height / 2), fill="red"))
# top text
top_text = '国  家  高  速'
top_text_size = 150
top_text_x = (width - top_text_size * len(top_text)) / 2 + 380
top_text_y = (top_height + top_text_size) / 2 + stroke_width - 25
dwg.add(dwg.text(top_text, insert=(stroke_width + top_text_x, stroke_width + top_text_y), fill="white", font_family="A型交通标志专用字体",font_size=top_text_size))
# num
y_offset = -360
big_text_x = (width - text_full_width) / 2
big_text_y = (height + big_text_h + top_height) / 2 + y_offset
dwg.add(dwg.text(big_text, insert=(stroke_width + big_text_x, stroke_width + big_text_y), fill="white", font_family="B型交通标志专用字体",font_size=big_text_h))
small_text_x = (width - text_full_width) / 2 + big_full_width
dwg.add(dwg.text(small_text, insert=(stroke_width + small_text_x, stroke_width + big_text_y), fill="white", font_family="B型交通标志专用字体",font_size=small_text_h))
# name
name_text = ' '.join(name)
name_text_size = 280
name_text_x = (width - name_text_size * len(name) * 1.2) / 2
name_text_y = top_text_y + top_text_size + 880
dwg.add(dwg.text(name_text, insert=(stroke_width + name_text_x, stroke_width + name_text_y), fill="white", font_family="A型交通标志专用字体",font_size=name_text_size))
# export
dwg.save()
# 解析SVG文件
svg_file = './{}.svg'.format(file_name)
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 + stroke_width * 2))
if 'width' in element.attrib:
element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2))
# 保存修改后的SVG文件
with open('./{}.svg'.format(file_name), 'wb') as f:
f.write(etree.tostring(svg_tree, pretty_print=True))
cairosvg.svg2png(url='./{}.svg'.format(file_name), write_to='./{}.png'.format(file_name))
os.remove('./{}.svg'.format(file_name))
print('{}标志生成完成'.format(file_name))

View File

@@ -0,0 +1,195 @@
num,name
G0111,秦滨高速
G0112,长辽高速
G0121,京秦高速
G0122,秦沈高速
G0211,津石高速
G0212,武滨高速
G0311,济聊高速
G0321,德上高速
G0322,京德高速
G0323,济合高速
G0411,安长高速
G0412,深南高速
G0413,新忻高速
G0421,许广高速
G0422,武深高速
G0423,乐广高速
G0424,京武高速
G0425,广澳高速
G0511,德都高速
G0512,成乐高速
G0513,平洛高速
G0611,张汶高速
G0612,西和高速
G0613,西丽高速
G0615,德康高速
G0616,乌甘高速
G0711,乌若高速
G0712,额策高速
G1111,鹤哈高速
G1112,集双高速
G1113,丹阜高速
G1115,鸡建高速
G1116,伊北高速
G1117,绥北高速
G1118,抚长高速
G1119,白临高速
G1131,牡延高速
G1511,日兰高速
G1512,甬金高速
G1513,温丽高速
G1514,宁上高速
G1515,盐靖高速
G1516,盐洛高速
G1517,莆炎高速
G1518,盐蚌高速
G1519,南如高速
G1521,常嘉高速
G1522,常台高速
G1523,甬莞高速
G1531,沪慈高速
G1532,泉梅高速
G1533,泉金高速
G1534,厦金高速
G1535,潮南高速
G1536,莞广高速
G2511,新鲁高速
G2512,阜锦高速
G2513,淮徐高速
G2515,鲁霍高速
G2516,东吕高速
G2517,沙厦高速
G2518,深岑高速
G2519,康沈高速
G2531,杭上高速
G3511,菏宝高速
G3512,寻赣高速
G4511,龙河高速
G4512,双嫩高速
G4513,奈营高速
G4515,赤绥高速
G5511,集阿高速
G5512,晋新高速
G5513,长张高速
G5515,张南高速
G5516,苏张高速
G5517,常长高速
G5518,晋潼高速
G5911,朔太高速
G5912,房五高速
G6511,安清高速
G6512,秀从高速
G6517,梧柳高速
G6521,榆蓝高速
G6522,延西高速
G6911,安来高速
G7511,钦东高速
G7512,筑蓉高速
G7521,渝筑高速
G7522,筑北高速
G8511,昆磨高速
G8512,景打高速
G8513,平绵高速
G8515,广泸高速
G8516,巴蓉高速
G8517,屏兴高速
G1011,哈同高速
G1012,建黑高速
G1013,海张高速
G1015,铁科高速
G1016,双宝高速
G1017,海加高速
G1211,吉黑高速
G1212,沈吉高速
G1213,北漠高速
G1215,松长高速
G1216,乌阿高速
G1221,延长高速
G1611,克承高速
G1612,锡二高速
G1811,黄石高速
G1812,沧榆高速
G1813,威青高速
G1815,潍日高速
G1816,乌玛高速
G1817,乌银高速
G1818,滨德高速
G2011,青新高速
G2012,定武高速
G2211,长延高速
G3011,柳格高速
G3012,吐和高速
G3013,阿伊高速
G3014,奎阿高速
G3015,奎塔高速
G3016,清伊高速
G3017,武金高速
G3018,精阿高速
G3019,博阿高速
G3021,临兴高速
G3031,商固高速
G3032,永海高速
G3033,奎库高速
G3035,伊新高速
G3036,阿阿高速
G3611,宁信高速
G3612,平宜高速
G3613,洛内高速
G3615,洛卢高速
G4011,扬溧高速
G4012,溧宁高速
G4013,扬乐高速
G4015,丹宁高速
G4211,宁芜高速
G4212,合安高速
G4213,麻安高速
G4215,蓉遵高速
G4216,蓉丽高速
G4217,蓉昌高速
G4218,雅叶高速
G4219,曲乃高速
G4221,沪武高速
G4222,和襄高速
G4223,武渝高速
G4231,宁九高速
G5011,芜合高速
G5012,恩广高速
G5013,渝蓉高速
G5015,武岳高速
G5016,宜华高速
G5021,石渝高速
G5611,大丽高速
G5612,大临高速
G5613,保泸高速
G5615,天猴高速
G5616,安吉高速
G5617,临勐高速
G5618,临清高速
G5621,昆大高速
G6011,南韶高速
G6012,曲弥高速
G6021,杭长高速
G6022,醴娄高速
G6023,南凤高速
G6025,洞三高速
G7011,十天高速
G7012,抚吉高速
G7013,沙南高速
G7021,宁武高速
G7211,南友高速
G7212,柳北高速
G7221,衡南高速
G7611,都香高速
G7612,纳兴高速
G8011,开河高速
G8012,弥楚高速
G8013,砚文高速
G9111,本集高速
G9211,甬舟高速
G9221,杭甬高速
G9411,莞佛高速
G9511,涞涞高速
G9811,海乐高速
G9812,海琼高速
G9813,万洋高速
1 num name
2 G0111 秦滨高速
3 G0112 长辽高速
4 G0121 京秦高速
5 G0122 秦沈高速
6 G0211 津石高速
7 G0212 武滨高速
8 G0311 济聊高速
9 G0321 德上高速
10 G0322 京德高速
11 G0323 济合高速
12 G0411 安长高速
13 G0412 深南高速
14 G0413 新忻高速
15 G0421 许广高速
16 G0422 武深高速
17 G0423 乐广高速
18 G0424 京武高速
19 G0425 广澳高速
20 G0511 德都高速
21 G0512 成乐高速
22 G0513 平洛高速
23 G0611 张汶高速
24 G0612 西和高速
25 G0613 西丽高速
26 G0615 德康高速
27 G0616 乌甘高速
28 G0711 乌若高速
29 G0712 额策高速
30 G1111 鹤哈高速
31 G1112 集双高速
32 G1113 丹阜高速
33 G1115 鸡建高速
34 G1116 伊北高速
35 G1117 绥北高速
36 G1118 抚长高速
37 G1119 白临高速
38 G1131 牡延高速
39 G1511 日兰高速
40 G1512 甬金高速
41 G1513 温丽高速
42 G1514 宁上高速
43 G1515 盐靖高速
44 G1516 盐洛高速
45 G1517 莆炎高速
46 G1518 盐蚌高速
47 G1519 南如高速
48 G1521 常嘉高速
49 G1522 常台高速
50 G1523 甬莞高速
51 G1531 沪慈高速
52 G1532 泉梅高速
53 G1533 泉金高速
54 G1534 厦金高速
55 G1535 潮南高速
56 G1536 莞广高速
57 G2511 新鲁高速
58 G2512 阜锦高速
59 G2513 淮徐高速
60 G2515 鲁霍高速
61 G2516 东吕高速
62 G2517 沙厦高速
63 G2518 深岑高速
64 G2519 康沈高速
65 G2531 杭上高速
66 G3511 菏宝高速
67 G3512 寻赣高速
68 G4511 龙河高速
69 G4512 双嫩高速
70 G4513 奈营高速
71 G4515 赤绥高速
72 G5511 集阿高速
73 G5512 晋新高速
74 G5513 长张高速
75 G5515 张南高速
76 G5516 苏张高速
77 G5517 常长高速
78 G5518 晋潼高速
79 G5911 朔太高速
80 G5912 房五高速
81 G6511 安清高速
82 G6512 秀从高速
83 G6517 梧柳高速
84 G6521 榆蓝高速
85 G6522 延西高速
86 G6911 安来高速
87 G7511 钦东高速
88 G7512 筑蓉高速
89 G7521 渝筑高速
90 G7522 筑北高速
91 G8511 昆磨高速
92 G8512 景打高速
93 G8513 平绵高速
94 G8515 广泸高速
95 G8516 巴蓉高速
96 G8517 屏兴高速
97 G1011 哈同高速
98 G1012 建黑高速
99 G1013 海张高速
100 G1015 铁科高速
101 G1016 双宝高速
102 G1017 海加高速
103 G1211 吉黑高速
104 G1212 沈吉高速
105 G1213 北漠高速
106 G1215 松长高速
107 G1216 乌阿高速
108 G1221 延长高速
109 G1611 克承高速
110 G1612 锡二高速
111 G1811 黄石高速
112 G1812 沧榆高速
113 G1813 威青高速
114 G1815 潍日高速
115 G1816 乌玛高速
116 G1817 乌银高速
117 G1818 滨德高速
118 G2011 青新高速
119 G2012 定武高速
120 G2211 长延高速
121 G3011 柳格高速
122 G3012 吐和高速
123 G3013 阿伊高速
124 G3014 奎阿高速
125 G3015 奎塔高速
126 G3016 清伊高速
127 G3017 武金高速
128 G3018 精阿高速
129 G3019 博阿高速
130 G3021 临兴高速
131 G3031 商固高速
132 G3032 永海高速
133 G3033 奎库高速
134 G3035 伊新高速
135 G3036 阿阿高速
136 G3611 宁信高速
137 G3612 平宜高速
138 G3613 洛内高速
139 G3615 洛卢高速
140 G4011 扬溧高速
141 G4012 溧宁高速
142 G4013 扬乐高速
143 G4015 丹宁高速
144 G4211 宁芜高速
145 G4212 合安高速
146 G4213 麻安高速
147 G4215 蓉遵高速
148 G4216 蓉丽高速
149 G4217 蓉昌高速
150 G4218 雅叶高速
151 G4219 曲乃高速
152 G4221 沪武高速
153 G4222 和襄高速
154 G4223 武渝高速
155 G4231 宁九高速
156 G5011 芜合高速
157 G5012 恩广高速
158 G5013 渝蓉高速
159 G5015 武岳高速
160 G5016 宜华高速
161 G5021 石渝高速
162 G5611 大丽高速
163 G5612 大临高速
164 G5613 保泸高速
165 G5615 天猴高速
166 G5616 安吉高速
167 G5617 临勐高速
168 G5618 临清高速
169 G5621 昆大高速
170 G6011 南韶高速
171 G6012 曲弥高速
172 G6021 杭长高速
173 G6022 醴娄高速
174 G6023 南凤高速
175 G6025 洞三高速
176 G7011 十天高速
177 G7012 抚吉高速
178 G7013 沙南高速
179 G7021 宁武高速
180 G7211 南友高速
181 G7212 柳北高速
182 G7221 衡南高速
183 G7611 都香高速
184 G7612 纳兴高速
185 G8011 开河高速
186 G8012 弥楚高速
187 G8013 砚文高速
188 G9111 本集高速
189 G9211 甬舟高速
190 G9221 杭甬高速
191 G9411 莞佛高速
192 G9511 涞涞高速
193 G9811 海乐高速
194 G9812 海琼高速
195 G9813 万洋高速

View File

@@ -0,0 +1,110 @@
import svgwrite
import cairosvg
from lxml import etree
import os
# config
width = 2000
height = 1400
top_height = 250
stroke_width = 30
out_r = stroke_width * 3
in_r = stroke_width * 2
highway_map = {
'G9901': '哈尔滨都市圈环线',
'G9902': '长春都市圈环线',
'G9903': '杭州都市圈环线',
'G9904': '南京都市圈环线',
'G9905': '郑州都市圈环线',
'G9906': '武汉都市圈环线',
'G9907': '长株潭都市圈环线',
'G9908': '西安都市圈环线',
'G9909': '重庆都市圈环线',
'G9910': '成都都市圈环线',
'G9911': '济南都市圈环线',
'G9912': '合肥都市圈环线'
}
for num, name in highway_map.items():
file_name = num + name;
# G+前两位
big_text = num[:3]
# 后两位
small_text = num[3:]
big_text_h = 850
small_text_h = 570
big_full_width = 0
small_full_width = 0
for n in big_text:
if n == '1':
big_full_width += big_text_h * 0.3
else:
big_full_width += big_text_h * 0.5
for n in small_text:
if n == '1':
small_full_width += small_text_h * 0.3
else:
small_full_width += small_text_h * 0.5
text_full_width = big_full_width + small_full_width
# rect
dwg = svgwrite.Drawing('./{}.svg'.format(file_name), profile='tiny', width=width, height=height)
dwg.add(dwg.rect(insert=(0, 0), size=(width + 2 * stroke_width, height + 2 * stroke_width), rx=out_r, ry=out_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width, height), rx=out_r, ry=out_r, fill="white"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, top_height), rx=in_r, ry=in_r, fill="red"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2 + top_height / 2), size=(width - stroke_width * 2, top_height / 2), fill="red"))
# top text
top_text = '国  家  高  速'
top_text_size = 150
top_text_x = (width - top_text_size * len(top_text)) / 2 + 380
top_text_y = (top_height + top_text_size) / 2 + stroke_width - 25
dwg.add(dwg.text(top_text, insert=(stroke_width + top_text_x, stroke_width + top_text_y), fill="white", font_family="A型交通标志专用字体",font_size=top_text_size))
# num
y_offset = -360
big_text_x = (width - text_full_width) / 2
big_text_y = (height + big_text_h + top_height) / 2 + y_offset
dwg.add(dwg.text(big_text, insert=(stroke_width + big_text_x, stroke_width + big_text_y), fill="white", font_family="B型交通标志专用字体",font_size=big_text_h))
small_text_x = (width - text_full_width) / 2 + big_full_width
dwg.add(dwg.text(small_text, insert=(stroke_width + small_text_x, stroke_width + big_text_y), fill="white", font_family="B型交通标志专用字体",font_size=small_text_h))
# name
name_text_size = 220
name_text_x = (width - name_text_size * len(name)) / 2
name_text_y = top_text_y + top_text_size + 880
dwg.add(dwg.text(name, insert=(stroke_width + name_text_x, stroke_width + name_text_y), fill="white", font_family="A型交通标志专用字体",font_size=name_text_size))
# export
dwg.save()
# 解析SVG文件
svg_file = './{}.svg'.format(file_name)
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 + stroke_width * 2))
if 'width' in element.attrib:
element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2))
# 保存修改后的SVG文件
with open('./{}.svg'.format(file_name), 'wb') as f:
f.write(etree.tostring(svg_tree, pretty_print=True))
cairosvg.svg2png(url='./{}.svg'.format(file_name), write_to='./{}.png'.format(file_name))
os.remove('./{}.svg'.format(file_name))
print('{}标志生成完成'.format(file_name))

View File

@@ -0,0 +1,90 @@
import svgwrite
import cairosvg
from lxml import etree
import os
# config
width = 1600
height = 1600
top_height = 250
stroke_width = 30
out_r = stroke_width * 3
in_r = stroke_width * 2
highway_map = {
1: '',
2: '',
3: '',
4: '港澳',
5: '',
6: '',
7: ''
}
for num, name in highway_map.items():
text = 'G{}'.format(num)
text_h = 1000
text_full_width = 0
for n in text:
if n == '1':
text_full_width += text_h * 0.3
else:
text_full_width += text_h * 0.5
# rect
dwg = svgwrite.Drawing('./{}.svg'.format(text), profile='tiny', width=width, height=height)
dwg.add(dwg.rect(insert=(0, 0), size=(width + 2 * stroke_width, height + 2 * stroke_width), rx=out_r, ry=out_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width, height), rx=out_r, ry=out_r, fill="white"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, top_height), rx=in_r, ry=in_r, fill="red"))
dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2 + top_height / 2), size=(width - stroke_width * 2, top_height / 2), fill="red"))
# top text
top_text = '国  家  高  速'
top_text_size = 150
top_text_x = (width - top_text_size * len(top_text)) / 2 + 380
top_text_y = (top_height + top_text_size) / 2 + stroke_width - 25
dwg.add(dwg.text(top_text, insert=(stroke_width + top_text_x, stroke_width + top_text_y), fill="white", font_family="A型交通标志专用字体",font_size=top_text_size))
# num
y_offset = -240
text_x = (width - text_full_width) / 2
text_y = (height + text_h + top_height) / 2 + y_offset - 200
dwg.add(dwg.text(text, insert=(stroke_width + text_x, stroke_width + text_y), fill="white", font_family="B型交通标志专用字体",font_size=text_h))
# name
name_text_size = 260
if len(name) == 1:
name_text = ' '.join('{}高速'.format(name))
name_text_x = (width - name_text_size * len(name_text) * 0.69) / 2
else:
name_text = '{}高速'.format(name)
name_text_x = (width - name_text_size * len(name_text)) / 2
name_text_y = top_text_y + top_text_size + 1000
dwg.add(dwg.text(name_text, insert=(stroke_width + name_text_x, stroke_width + name_text_y), fill="white", font_family="A型交通标志专用字体",font_size=name_text_size))
# export
dwg.save()
# 解析SVG文件
svg_file = './{}.svg'.format(text)
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 + stroke_width * 2))
if 'width' in element.attrib:
element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2))
# 保存修改后的SVG文件
with open('./{}.svg'.format(text), 'wb') as f:
f.write(etree.tostring(svg_tree, pretty_print=True))
cairosvg.svg2png(url='./{}.svg'.format(text), write_to='./{}.png'.format(text))
os.remove('./{}.svg'.format(text))
print('{}标志生成完成'.format(text))