2012-12-31 91 views
1

例如:如何從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。

我知道這是XML,但我無法弄清楚。這可能很容易,但這是今年的最後一天,我無法弄清楚。

一直在努力:

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

這也不起作用:

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

任何想法?

回答

4

所有你需要的是

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

輸出

23 x 22 

Simple Online Demo

相關問題