You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm assuming you've already got an SVG object (an image) loaded from somewhere or constructed one manually.
You can use its toXMLString() method to obtain the SVG in text form, and then write that out whichever way you prefer. The simplest way would be using PHP's file_put_contents.
Complete example:
<?phprequire __DIR__ . '/vendor/autoload.php';
useSVG\SVG;
useSVG\Nodes\Shapes\SVGRect;
// image with 100x100 viewport$image = newSVG(100, 100);
$doc = $image->getDocument();
// blue 40x40 square at (0, 0)$square = newSVGRect(0, 0, 40, 40);
$square->setStyle('fill', '#0000FF');
$doc->addChild($square);
// obtain the SVG text$svgString = $image->toXMLString();
// write it to a file
file_put_contents('path/to/the-file.svg', $svgString);
I hope this solved your problem. Please, always ask if something is unclear!
Sorry if already addressed but am not sure of the correct way to output svg to file ?
The text was updated successfully, but these errors were encountered: