Re: svg 2 gif/png

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux