python如何画svg路径_如何使用Python获取SVG路径的高度,宽度和长度?

I have an svg with tons of paths like this basically:

i want to get the height, width, area, length, and anything else I can basically from this path. Is there any python library? Or is there something I am overlooking where I could just do it manually?

解决方案

You can use svgpathtools to find measurements like these (assuming I know what you mean).

# create svgpathtools Path objects from an SVG file

from svgpathtools import svg2paths

paths, attributes = svg2paths('some_svg_file.svg')

# let's take the first path as an example

mypath = paths[0]

# Let's find its length

print("length = ", mypath.length())

# Find height, width

xmin, xmax, ymin, ymax = mypath.bbox()

print("width = ", xmax - xmin)

print("height = ", ymax - ymin)

# Let's find the area enclosed by the path (assuming the path is closed)

try:

print("area = ", mypath.area())

except AssertionError:

print("This path is not closed!")

# if you want a notion of area for an open path,

# you could use the bounding box area.

print("height*width = ", (ymax - ymin)*(xmax - xmin))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值