-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Import SVG files #494
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
Comments
+1 |
Cairo doesn't read SVG files, so this would require adding another dependency like librsvg. Since librsvg works with cairo, it might be not that much work beyond adding the dependency. Feel free to submit a patch! |
fabric.js can help your goal. |
+1 to this feature |
Maybe with http://cairosvg.org/ it can read them? |
+1 |
@mltucker are you sure cairo can't read svg files, or is it just that
... is importing SVGs not just a matter of requiring |
Happy to pay a bounty if anyone would like to work on this? |
I too would love this functionality. @jakeg, does that bounty offer still stand? 😉 |
It sure does. I've emailed you to discuss :) |
I'd be willing to kick in.
|
To keep everyone updated, I am currently working on adding this functionality: https://github.com/scott113341/node-canvas/tree/svg I have a couple demos in the |
@scott113341 nice, bummer we have to add another dependency though |
Another option is to do something like this, where SVG geometry is parsed and then drawn onto the canvas. My guess is that this approach wouldn't work for all SVGs, but it's worth investigating. |
@scott113341 Yeah I was thinking about using @chearon is it really a problem to have another dependency? |
@jakeg most of the issues posted here are with dependencies. I'm working on distributed static builds though so if that gets merged it would be less of a problem. In the meantime it's worth considering having the SVG library be built only if it's found on the system, the same way Pango currently is on master |
Just noticed pull request #406 from 2 years ago which claims to add this functionality I think? |
@scott113341 what's outstanding from your branch? I am planning to reapply #406 over current master and create a new PR, but want to check in with you about your work first. |
If I remember correctly from a couple of months ago, Scott's fork was working for some SVGs but mangling other ones. Also, if outputting as PDF, the SVGs were unfortunately placed as low res rasters in the PDF output, rather than being placed as-is in their original vector form. |
Thanks for the insight @jakeg.
As a next step, I will assess both @scott113341 and @petarov approaches and report back with any serious issues. Do we have someone with merge privileges watching this discussion? I want to make sure the next PR doesn't lose our momentum. Thanks again all! |
@foysavas if the SVG is inserted in the PDF at a good resolution (maybe adding an option somehow to specify this?), then this may just be good enough. However, the current code puts them in at a ghastly low resolution with a lot of JPG artifacts (or similar), if I remember correctly. Ideally for my use though, the SVG would be inserted as-is. I'm printing around 50,000 books a year, using html5 canvas on the front end for users to design pages, and node-canvas on the server to produce PDFs which I then send to print. Clearly I'm going to need the SVGs to end up at a printable quality! |
Hi all, please try out #811 and tell me if there are any issues. |
This works fine with tree.svg, but not with the attached ok.svg (gah, github doesn't allow svg attach, so please rename from ok.png to ok.svg and then try it) Here's the ok.svg file (saved as ok.png to get it to upload): Here's the mangled output: Also can confirm that PDF output is same as per Scott's code (low-quality raster version of the svg rather than original vector file placed as-is in the pdf) |
@jakeg What OS and version of librsvg and node are you using? I managed to render ok.svg without issue. |
@foysavas Ubuntu 14.04 (in a VM on Windows 10), Node v4.4.5 and librsvg 2 (installed with |
Just for the record, it looks good on my Arch Linux w/h node 6.5.0. @jakeg Does the mangling occur only with this particular SVG or also with other ones you got? |
I can confirm the bad rendering of ok.svg on Ubuntu 14.04, using Node v4 or v6, and the packaged librsvg version 2.40.2. In contrast, I can confirm a correct rendering of ok.svg on Ubuntu 16.04, using Node v4 or v6, and the packaged librsvg version 2.40.13. I believe that librsvg around version 2.40.2 has a path parsing bug and that by 2.40.13 it was fixed. This abandoned bug post seems to support that: https://bugzilla.gnome.org/show_bug.cgi?id=767919 @jakeg Ubuntu 16.04 is also a LTS, hopefully you can transition to it. If you still run into issues, tell me. |
@foysavas fantastic! Yes, I am upgrading the main server to Ubuntu 16.04 today, and was going to run a new test after the upgrade, so wonderful to hear that :) Has anyone had a look at PDF output at all yet? See below re the quality of the SVG in the PDF (although it says it does, github doesn't allow me to add a PDF so again just change file extension from png to pdf) |
@jakeg Glad to hear it! Native SVGs embedded in PDFs would be nice. Maybe the best way to implement it would be to use |
Closing since the corresponding PR for this landed in 2.x! 🎉 |
Just linking the PR mentionned above, if anyone ends up on this issue and wants to know what the PR was: |
Would love to be able to include SVG files in node-canvas documents (input/drawImage() them, not output to SVG) similar to JPG/PNGs etc.
The text was updated successfully, but these errors were encountered: