Re: [PHP] svg 2 gif/png
[email protected] ("Michael A. Peters")
| Newsgroups | php.general |
|---|---|
| Message-ID | <[email protected]> |
Michael A. Peters wrote:
> 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 -
This does work (fixed version of function):
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(' ',$pointArray);
$newPolygon = $polygon->cloneNode(true);
$newPolygon->setAttribute('points',$points);
$use->parentNode->replaceChild($newPolygon,$use);
}
}