Re: svg 2 gif/png
| From: | Michael A. Peters | Date: | Wed, 03 Mar 2010 11:25:51 +0000 |
| Subject: | Re: svg 2 gif/png | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-302501@lists.php.net to get a copy of this message | ||
Michael A. Peters wrote:
*snip*
Is there an easy way around this? IE a php class/function that understands SVG w/ xlink and can replace the use tags with the polygons they refer to? If not, I'll have to try to write one, but I'd rather not ...I just did, haven't tested yet, but this may work - function use2polygon($use,$polygon) { // get the xy coords $x = 0; $y = 0; if ($use->hasAttribute('x') {
$x = 0 + $use->getAttribute('x');
}
if ($use->hasAttribute('y') {
$y = 0 + $use->getAttribute('y');
}
// clone the polygon
if ($polygon->hasAttribute('points') {
$points = preg_replace('/\s+/',' ',$polygon->getAttribute('points'));
$pointArray = explode(' ',$points);
$sizeof = sizeof($pointArray);
for ($i=0;$i<$sizeof;$i++) {
$foo = explode(',',$pointArray[$i]);
$foo[0] = $x + $foo[0];
$foo[1] = $y + $foo[1];
$pointArray[$i] = $foo[0] . ',' . $foo[1];
}
$points = implode(' ',$points);
$newPolygon = $polygon->cloneNode(true);
$newPolygon->setAttribute('points',$points);
$use->parentNode->replaceChild($newPolygon,$use);
}
}
of course that requires domdocument and probably requires looping through the dom node list backwards, but hopefully that will do it.