How can I get the height and width and length of an SVG path using Python? -
i have svg tons of paths basically:
<path fill="#fb6430" opacity="1.00" d=" m 0.70 0.00 l 14.60 0.00 c 16.36 3.76 19.56 6.54 21.77 9.99 c 21.37 11.15 20.65 12.15 20.02 13.20 c 18.65 11.77 17.81 9.99 17.51 8.04 c 16.28 8.93 15.13 9.92 14.08 11.01 c 13.93 9.08 13.77 7.16 13.62 5.23 c 13.03 5.22 11.84 5.20 11.25 5.19 c 11.35 6.73 11.45 8.26 11.58 9.79 c 10.84 9.90 9.37 10.13 8.63 10.24 c 7.87 9.37 7.10 8.51 6.36 7.63 c 6.08 7.25 5.53 6.51 5.25 6.13 c 3.75 4.08 2.19 2.06 0.70 0.00 z" />
i want height, width, area, length, , else can path. there python library? or there overlooking manually?
you can use svgpathtools find measurements these (assuming know mean).
# create svgpathtools path objects svg file svgpathtools import svg2paths paths, attributes = svg2paths('some_svg_file.svg') # let's take first path example mypath = paths[0] # let's find 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 area enclosed path (assuming path closed) try: print("area = ", mypath.area()) except assertionerror: print("this path not closed!") # if want notion of area open path, # use bounding box area. print("height*width = ", (ymax - ymin)*(xmax - xmin))
Comments
Post a Comment