Re: svg 2 gif/png
| From: | Michael A. Peters | Date: | Wed, 03 Mar 2010 12:18:22 +0000 |
| Subject: | Re: svg 2 gif/png | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-302505@lists.php.net to get a copy of this message | ||
Michael A. Peters wrote:
Michael A. Peters wrote:doh - for xml sanity, add this before the replaceChild if ($newPolygon->hasAttribute('id')) {Michael A. Peters wrote: *snip*This does work (fixed version of function): function use2polygon($use,$polygon) { // get the xy coords $x = 0; $y = 0; if ($use->hasAttribute('x')) {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 -$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); }}
$newPolygon->removeAttribute('id');
}
Now it works, and makes identical svg image that works with convert.
http://www.shastaherps.org/map/map22.svg vs
http://www.shastaherps.org/map/map22.svg?convert=true