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

Can I load a svg from my server to make it a png? #65

Closed
ashickur-rahman opened this issue Jan 15, 2019 · 5 comments
Closed

Can I load a svg from my server to make it a png? #65

ashickur-rahman opened this issue Jan 15, 2019 · 5 comments
Labels
question Further information is requested

Comments

@ashickur-rahman
Copy link

I have already created a SVG, but now I want to make it a png. Is it possible to do so?

@stelgenhof
Copy link

Yes, you can use the toRasterImage method to achieve that. See the README.md (Rasterizing section) for an example.

@ashickur-rahman
Copy link
Author

Yes, you can use the toRasterImage method to achieve that. See the README.md (Rasterizing section) for an example.

My bad, I forget add I already have the SVG. So how I can call the file? In example you initialize a SVG using this
$image = new SVG(100, 100);

But I want to load the SVG I already have. Is it possible?

@stelgenhof
Copy link

If I understand what you are trying to do, have a look at the README.md file the last section. It explains how you can load an existing SVG from either a string or file.

The example outputs the resulting SVG to the browser, but you can easily save the resulting SVG to a file with for example the PHP 'file_put_contents' function.

Is that what you are looking for?

@ashickur-rahman
Copy link
Author

Now I got it. But png is not rendering well.
This is the SVG

svg.zip

The code

require "vendor/autoload.php";

use SVG\SVG;

$image = SVG::fromFile("circle.svg");

$rasterImage = $image->toRasterImage(500, 500);

header('Content-Type: image/png');
imagepng($rasterImage);

image

I am not sure, what I am doing wrong?

@stelgenhof
Copy link

This might not be the best way to generate a PNG from an existing SVG file. The internal rasterization component of this library might not be able to properly render the elements in your SVG. I belief there are some limitations with rasterization in this library.

If you only are looking for a simple conversion from SVG to PNG, then I would recommend use a library such as Imagick.

@meyfa meyfa added the question Further information is requested label Jul 30, 2019
@meyfa meyfa closed this as completed Jul 30, 2019
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

3 participants