如何从svg文件提取高度和宽度 [英] how to extract height and width from a svg file

查看:415
本文介绍了如何从svg文件提取高度和宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例:

<svg width="23" height="22" xmlns="http://www.w3.org/2000/svg">
<!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
<g>
<title>Layer 1</title>
<path fill-opacity="0" id="svg_1" d="m23,2-20,9.5l22,9" stroke-width="4" stroke="#000000" fill="#ffffff" />
</g>
</svg>

我想提取svg文件的宽度和高度,以便可以对canvg进行一些定位.

I want to extract the width and height of the svg file so that I can do some positioning with canvg.

我知道它是xml,但我无法弄清楚.可能确实很容易,但这是一年的最后一天,我无法弄清楚.

I know it's xml, but I can't figure it out. It's probably something really easy but it's the last day of the year and I can't figure it out.

尝试过:

PHP SimpleXML

PHP SimpleXML

$xml = simplexml_load_file($imageright) or die("Error: Cannot create object");
print_r($xml->getDocNamespaces());echo '</br>';

给我 数组([] => http://www.w3.org/2000/svg )

giving me Array ( [] => http://www.w3.org/2000/svg )

这也不起作用:

foreach($xml->svg[0]->attributes() as $a => $b)
  {
  echo $a,'="',$b,"\"</br>";
  }

有什么想法吗?

推荐答案

您需要的只是

$xml = simplexml_load_file($imageright);
$attr = $xml->attributes();
printf("%s x %s", $attr->width, $attr->height);

输出

23 x 22

简单的在线演示

这篇关于如何从svg文件提取高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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