获取SVG路径的外部坐标(getBBox)? [英] Get outer coordinates of a SVG path (getBBox)?

查看:432
本文介绍了获取SVG路径的外部坐标(getBBox)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取PHP中SVG路径的坐标(左上角的x,y和宽度/高度).

I need to get the coordinates (x,y of top-left corner and width/height) of a SVG path in PHP.

我的意思是SVG文件的路径节点中的d属性,类似这样:

I mean the d-attribute in a path node of an SVG-file, somehting like this:

<path d="M 100 100 L 300 100 L 200 300 z" />

我自己执行此操作的路径非常复杂(某些路径具有绝对和/或相对坐标,可能的曲线等)

My paths are quite complex to do this myself (some have absolute and/or relative coordinates, possible curves, etc.)

在PHP中是否有用于此类工作的库?

Are there any libraries for this kind of work in PHP?

推荐答案

如果您的形状不使用圆弧或贝塞尔曲线(许多形状实际上使用直线来近似曲线),则可以使用此PHP函数来计算边界框: http://pastebin.com/8eLQccbg

If your shape doesn't use arcs or beziers (many shapes actually use straight lines to approximate curves) then you can use this PHP function to calculate the bounding box: http://pastebin.com/8eLQccbg

这篇关于获取SVG路径的外部坐标(getBBox)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆