Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to output and save #63

Closed
audas opened this issue Nov 29, 2018 · 2 comments
Closed

How to output and save #63

audas opened this issue Nov 29, 2018 · 2 comments
Labels
question Further information is requested

Comments

@audas
Copy link

audas commented Nov 29, 2018

Sorry if already addressed but am not sure of the correct way to output svg to file ?

@meyfa meyfa added the question Further information is requested label Nov 29, 2018
@meyfa
Copy link
Owner

meyfa commented Nov 29, 2018

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:

<?php
require __DIR__ . '/vendor/autoload.php';

use SVG\SVG;
use SVG\Nodes\Shapes\SVGRect;

// image with 100x100 viewport
$image = new SVG(100, 100);
$doc = $image->getDocument();

// blue 40x40 square at (0, 0)
$square = new SVGRect(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!

@meyfa
Copy link
Owner

meyfa commented Dec 11, 2018

I'm closing this issue under the assumption that it has been solved. Please reopen it if I'm wrong.

@meyfa meyfa closed this as completed Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants