-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Added: Image can now load SVG files and data #406
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
Conversation
Only compile with librsvg support if the library is present on the system (using /util/has_lib.sh for lookup) and if the OS is not Windows.
There are 3 new methods added in Image.cc: * isSVG - Attempts to identify if buffer data contains an SVG image. It checks if the initial bytes start either with 'svg' or 'xml'. Lower case letters only! * loadSVGFromBuffer - Load SVG image from buffer and renders to Cairo surface. * loadSVG - Load a complete SVG file and then calls loadSVGFromBuffer. This is pretty much the same as loadGIF.
This test loads an SVG buffered file data into an Image and then draws the buffered data onto a Canvas context. After that it converts the Canvas data to PNG data.
@TooTallNate does this patch make sense? Just wanted to get some feedback because I'd like to use node-canvas for another project I'm working on. |
I'm also looking to use librsvg with node-canvas. @petarov why was this closed? |
@foysavas Hi, I think there was just no interest in this patch at that time and after 6 or 7 months it was no longer compatible with the code base. I did use this functionality in a project though, but since I abandoned that project, I decided it was best to close the PR as well. If someone's interest in working at this, I can help with a review. |
@petarov Wanting to do the same, I was seriously delighted to find your pull request. I'll fork off the current master and try to reapply your code. When it's ready, I'll comment back here with a link for review. Thanks so much for your help and code! |
Hi,
This PR extends
Image
with the ability to loadsvg
files. The functionality depends on librsvg. What I originally wanted to do was to convert dynamically generatedsvg
images topng
files at server side. This patch should now provide the ability to do so:Here's a short example:
Build & Support
Test cases are provided for both
make test
andmake test-server
targets.Windows is currently not supported mainly because I have no access to a Windows installation to test. But it should run fine, if someone is willing to work further on that.