-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseSVG.php
36 lines (36 loc) · 1.1 KB
/
parseSVG.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
function parseSVG($svg_path)
{
$doc = new DOMDocument();
$doc->load($svg_path);
$xpath = new domXPath($doc);
$query = "//*";
$xpathQuery = $xpath->query($query);
$size = $xpathQuery->length;
for ($i=0; $i<$size; $i++)
{
$shapes = array('rect','circle','line','ellipse','polygon','polyline','path');
$node = $xpathQuery->item($i);
foreach ($shapes as $shape)
{
if ($node->nodeName == $shape)
{
$clonenode = $node->cloneNode(true);
foreach ($clonenode->attributes as $att)
{
$attributes[] = $att->nodeName . "='" . $att->nodeValue . "' ";
}
$final = "<svg viewBox='0 0 600 780'><" . $clonenode->nodeName . " " . implode($attributes) . "/></svg>";
echo "<div class='shapes'>";
echo "<div class='svg_overlay'>";
echo "<div onclick='alert(this.innerHTML)'>";
echo $final;
echo "</div>";//ends svg onclick alert
echo "</div>";//end svg_overlay
echo "</div>";//ends shapes
$attributes = array();
}
}
}
}
?>