I want to convert SVG into bitmap images (like JPEG, PNG, etc.) through JavaScript.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
If you don't mean programmatically, this question should probably belong to superuser.com.
Either way, the Batik SVG Toolkit may be of help, especially the SVG Rasterizer.
change
svg
to match your elementThis seems to work in most browsers:
jbeard4 solution worked beautifully.
I'm using Raphael SketchPad to create an SVG. Link to the files in step 1.
For a Save button (id of svg is "editor", id of canvas is "canvas"):
Here's a server side solution based on PhantomJS. You can use JSONP to make a cross domain call to the image service:
https://github.com/vidalab/banquo-server
For example:
http://[host]/api/https%3A%2F%2Fvida.io%2Fdocuments%2FWgBMc4zDWF7YpqXGR/viewport_width=980&viewport_height=900&delay=5000&selector=%23canvas
Then you can display image with img tag:
It works across browser.
Here is how you can do it through JavaScript: