2 回答
TA贡献1818条经验 获得超7个赞
到目前为止,我有一些东西:
# scale SVG images from files
import os
import re
import svgutils as su
SCALE = .1
path = 'E:/Slicke/Sitne'
svg_files = [f for f in os.listdir(path) if f.endswith('.svg')]
for i in svg_files:
svg_file = os.path.join(path, i)
# Get SVGFigure from file
original = su.transform.fromfile(svg_file)
# Original size is represetnted as string (examle: '600px'); convert to float
original_width = float(re.sub('[^0-9]','', original.width))
original_height = float(re.sub('[^0-9]','', original.width))
scaled = su.transform.SVGFigure(original_width * SCALE, original_height * SCALE,)
# Get the root element
svg = original.getroot()
# Scale the root element
svg.scale_xy(SCALE, SCALE)
# Add scaled svg element to figure
scaled.append(svg)
# Create the path and new file name
svg_out = os.path.splitext(svg_file)[0] + '_scale.svg'
print(svg_out)
scaled.save(svg_out)
添加回答
举报